From 33685c8947734ab9e7b9caeb6e01cb6802c7f569 Mon Sep 17 00:00:00 2001 From: TimmRuppert Date: Fri, 20 Dec 2024 16:23:21 +0100 Subject: [PATCH] implement usage of external osi (#12) * implement usage of external osi Signed-off-by: Timm Ruppert * typos and cosmetics Signed-off-by: Timm Ruppert --------- Signed-off-by: Timm Ruppert --- CMakeLists.txt | 15 ++++++++++----- src/CMakeLists.txt | 3 ++- tests/CMakeLists.txt | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6296300..203ea86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16) -project(osi-utilities) +project(asam-osi-utilities) -# Som features (e.g. mcap) require at least C++17 +# Some features (e.g. mcap) require at least C++17 set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Generate compile_commands.json for clang based tools @@ -14,21 +14,26 @@ include_directories(${PROJECT_SOURCE_DIR}/include) option(USE_EXTERNAL_OSI "Use an external version of open_simulation_interface" OFF) option(LINK_WITH_SHARED_OSI "Link utils with shared OSI library instead of statically linking" OFF) -# Locate open_simulation_interface using find_package or custom path. +# Locate open_simulation_interface if (USE_EXTERNAL_OSI) - message(FATAL_ERROR "Not implemented yet") + # if you use this library in your own project, you need to add + # something like list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/lib/open-simulation-interface) + # to your CMakeLists.txt so that we can fine the open_simulation_interface package. + find_package(open_simulation_interface QUIET REQUIRED) + message(STATUS "Using external OSI, provided by ${open_simulation_interface_DIR}") else () # Download and use our own open_simulation_interface package. include(FetchContent) + message(STATUS "Using internal OSI, downloading open_simulation_interface...") FetchContent_Declare( open_simulation_interface GIT_REPOSITORY https://github.com/OpenSimulationInterface/open-simulation-interface.git GIT_TAG v3.7.0 ) FetchContent_MakeAvailable(open_simulation_interface) - set(OSI_INCLUDE_DIR ${open_simulation_interface_BINARY_DIR}) endif () + # option to enable coverage reporting option(CODE_COVERAGE "Enable coverage reporting" OFF) if (CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fd14d7c..5f2ec8b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,8 +36,9 @@ if (LINK_WITH_SHARED_OSI) target_link_libraries(OSIUtilities PRIVATE open_simulation_interface) else () target_link_libraries(OSIUtilities PRIVATE open_simulation_interface_pic) - include_directories(${OSI_INCLUDE_DIR}) endif () +include_directories(${open_simulation_interface_BINARY_DIR}) + # get mcap and its dependencies find_package(PkgConfig REQUIRED) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0b27e10..e6a1cd9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,6 +20,7 @@ add_executable( ${src_sources} ) target_link_libraries(unit_tests PRIVATE GTest::gtest_main) + # see src/CMakeLists.txt target_compile_definitions(unit_tests PRIVATE OSI_TRACE_FILE_SPEC_VERSION="3.7.1") @@ -28,8 +29,9 @@ if (LINK_WITH_SHARED_OSI) target_link_libraries(unit_tests PRIVATE open_simulation_interface) else () target_link_libraries(unit_tests PRIVATE open_simulation_interface_pic) - include_directories(${OSI_INCLUDE_DIR}) endif () +include_directories(${open_simulation_interface_BINARY_DIR}) + # get mcap and its dependencies find_package(PkgConfig REQUIRED)