diff --git a/CMakeLists.txt b/CMakeLists.txt index b222eca73..ce00cdea0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -257,7 +257,7 @@ target_include_directories(${BTCPP_LIBRARY} ${BTCPP_EXTRA_INCLUDE_DIRS} ) -target_compile_definitions(${BTCPP_LIBRARY} PUBLIC BTCPP_LIBRARY_VERSION="${CMAKE_PROJECT_VERSION}") +target_compile_definitions(${BTCPP_LIBRARY} PUBLIC BTCPP_LIBRARY_VERSION="${PROJECT_VERSION}") target_compile_features(${BTCPP_LIBRARY} PUBLIC cxx_std_17) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1274f2646..49fcce397 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -106,6 +106,15 @@ else() endif() +add_test( + NAME cmake_subproject_version + COMMAND ${CMAKE_COMMAND} + -S ${CMAKE_CURRENT_SOURCE_DIR}/cmake/subproject_version + -B ${CMAKE_CURRENT_BINARY_DIR}/cmake/subproject_version + "-DBTCPP_SOURCE_DIR=${PROJECT_SOURCE_DIR}" + "-DBTCPP_EXPECTED_VERSION=${PROJECT_VERSION}" +) + target_include_directories(behaviortree_cpp_test PRIVATE include) target_link_libraries(behaviortree_cpp_test ${BTCPP_LIBRARY} bt_sample_nodes) if(MSVC) diff --git a/tests/cmake/subproject_version/CMakeLists.txt b/tests/cmake/subproject_version/CMakeLists.txt new file mode 100644 index 000000000..40263a5a4 --- /dev/null +++ b/tests/cmake/subproject_version/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.16.3) + +project(btcpp_parent VERSION 9.8.7 LANGUAGES C CXX) + +if(NOT BTCPP_SOURCE_DIR OR NOT BTCPP_EXPECTED_VERSION) + message(FATAL_ERROR "BTCPP_SOURCE_DIR and BTCPP_EXPECTED_VERSION are required") +endif() + +set(BUILD_TESTING OFF CACHE BOOL "" FORCE) +set(BTCPP_BUILD_TOOLS OFF CACHE BOOL "" FORCE) +set(BTCPP_EXAMPLES OFF CACHE BOOL "" FORCE) +set(BTCPP_GROOT_INTERFACE OFF CACHE BOOL "" FORCE) +set(BTCPP_SQLITE_LOGGING OFF CACHE BOOL "" FORCE) +set(CMAKE_DISABLE_FIND_PACKAGE_ament_cmake TRUE CACHE BOOL "" FORCE) + +add_subdirectory("${BTCPP_SOURCE_DIR}" behaviortree_cpp) + +get_target_property(btcpp_compile_definitions behaviortree_cpp COMPILE_DEFINITIONS) +set(expected_definition "BTCPP_LIBRARY_VERSION=\"${BTCPP_EXPECTED_VERSION}\"") +list(FIND btcpp_compile_definitions "${expected_definition}" expected_version_index) + +if(expected_version_index EQUAL -1) + message(FATAL_ERROR + "Expected ${expected_definition}, got: ${btcpp_compile_definitions}") +endif()