FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
Linking FhSim with CMake

This page shows how a downstream C++ project consumes FhSim through CMake. The package is distributed with Conan and exposes a standard CMake config package.

For the v2→v3 target changes, see Migrating to FhSim 3.0.

Finding the package

FhSim installs a CMake config package named FhSim:

find_package(FhSim CONFIG REQUIRED)

It provides these imported targets (Conan components in parentheses):

Target Component Use it to
FhSim::simobject simobject Build a SimObject plugin library.
FhSim::fhsim fhsim Embed the full simulation engine in your own program.
FhSim::fhsim_test fhsim_testtools Write SimObject/integration tests.
FhSim::fhsim_vis fhsim_vis Add the visualization layer (only when built with visualization).
Note
Link the lightest target that covers your needs. SimObject plugins should link FhSim::simobject, not FhSim::fhsim.

SimObject plugin

A SimObject library is built as a MODULE (a runtime-loadable plugin) and links only FhSim::simobject:

cmake_minimum_required(VERSION 3.24)
project(fhsim_myplugin)
find_package(FhSim CONFIG REQUIRED)
add_library(fhsim_myplugin MODULE
src/MyObject.cpp
src/Creator.cpp
)
target_link_libraries(fhsim_myplugin PRIVATE FhSim::simobject)

See Create a new SimObject library for the plugin/creator structure.

Embedding the engine

To drive simulations from your own executable, link the full engine:

cmake_minimum_required(VERSION 3.24)
project(my_simulator)
find_package(FhSim CONFIG REQUIRED)
add_executable(my_simulator src/main.cpp)
target_link_libraries(my_simulator PRIVATE FhSim::fhsim)

See Running FhSim from your own software for the embedding API.

Tests

Test executables link both the engine and the test-tools target (and GoogleTest):

find_package(FhSim CONFIG REQUIRED)
find_package(GTest REQUIRED)
add_executable(my_tests test/MyObject_Test.cpp)
target_link_libraries(my_tests PRIVATE
FhSim::fhsim
FhSim::fhsim_test
GTest::gtest
GTest::gtest_main
)

See Testing for the test API.

Consuming via Conan

Add FhSim to your consumer conanfile.py:

def requirements(self):
self.requires("fhsim/[^3.1.0]@sintef/stable")

Generate CMake files with CMakeDeps + CMakeToolchain as usual; find_package(FhSim) then resolves against the Conan-provided package. The with_visualization option controls whether FhSim::fhsim_vis is available.

See also