diff --git a/CMake/Findfoonathan_memory.cmake b/CMake/Findfoonathan_memory.cmake new file mode 100644 index 00000000000..0f1f49a86dc --- /dev/null +++ b/CMake/Findfoonathan_memory.cmake @@ -0,0 +1,35 @@ + +# This is a dummy file, just so CMake does not complain: + +# CMake Error at build/third-party/fastdds/CMakeLists.txt:239 (find_package): +# By not providing "Findfoonathan_memory.cmake" in CMAKE_MODULE_PATH this +# project has asked CMake to find a package configuration file provided by +# "foonathan_memory", but CMake did not find one. +# +# Could not find a package configuration file provided by "foonathan_memory" +# with any of the following names: +# +# foonathan_memoryConfig.cmake +# foonathan_memory-config.cmake +# +# Add the installation prefix of "foonathan_memory" to CMAKE_PREFIX_PATH or +# set "foonathan_memory_DIR" to a directory containing one of the above +# files. If "foonathan_memory" provides a separate development package or +# SDK, be sure it has been installed. + +# FastDDS requires foonathan_memory and will not find it if we do not provide this +# file. +# +# Since all the variables should already be set by external_foonathan_memory.cmake, +# we don't really do anything. + +# This may not be the proper way to do this. But it works... + + +#message( "In Findfoonathan_memory.cmake" ) + + +#find_package( PkgConfig ) +#pkg_check_modules( foonathan_memory QUIET foonathan_memory ) + + diff --git a/CMake/external_fastdds.cmake b/CMake/external_fastdds.cmake index 8c6739e7b8f..126c9ba9eab 100644 --- a/CMake/external_fastdds.cmake +++ b/CMake/external_fastdds.cmake @@ -47,13 +47,13 @@ function(get_fastdds) mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_FASTDDS) # place FastDDS project with other 3rd-party projects - set_target_properties(fastcdr fastrtps PROPERTIES + set_target_properties(fastcdr fastrtps foonathan_memory PROPERTIES FOLDER "ExternalProjectTargets/fastdds") list(POP_BACK CMAKE_MESSAGE_INDENT) # Unindent outputs add_library(dds INTERFACE) - target_link_libraries(dds INTERFACE fastcdr fastrtps) + target_link_libraries( dds INTERFACE fastcdr fastrtps ) add_definitions(-DBUILD_WITH_DDS) diff --git a/CMake/external_foonathan_memory.cmake b/CMake/external_foonathan_memory.cmake index bcff6b4e3e9..cecf271150d 100644 --- a/CMake/external_foonathan_memory.cmake +++ b/CMake/external_foonathan_memory.cmake @@ -1,83 +1,65 @@ cmake_minimum_required(VERSION 3.11) include(FetchContent) -# Mark new options from FetchContent as advanced options -mark_as_advanced(FETCHCONTENT_QUIET) -mark_as_advanced(FETCHCONTENT_BASE_DIR) -mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED) -mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED) - -message(CHECK_START "Fetching & Installing foonathan_memory...") -list(APPEND CMAKE_MESSAGE_INDENT " ") - -FetchContent_Declare( - foonathan_memory - GIT_REPOSITORY https://github.com/foonathan/memory.git - GIT_TAG "v0.7-2" - GIT_SHALLOW ON # No history needed - SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/third-party/foonathan_memory -) - -# Remove unrequired targets -set(FOONATHAN_MEMORY_BUILD_VARS -DBUILD_SHARED_LIBS=OFF # explicit set static lib - -DFOONATHAN_MEMORY_BUILD_EXAMPLES=OFF - -DFOONATHAN_MEMORY_BUILD_TESTS=OFF - -DFOONATHAN_MEMORY_BUILD_TOOLS=ON) # this tool is needed during configure time only, FastDDS recommend turning it ON. +# We use a function to enforce a scoped variables creation only for FastDDS build (i.e turn off BUILD_SHARED_LIBS which is used on LRS build as well) +function(get_foonathan_memory) + + # Mark new options from FetchContent as advanced options + mark_as_advanced(FETCHCONTENT_QUIET) + mark_as_advanced(FETCHCONTENT_BASE_DIR) + mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED) + mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED) + + message(CHECK_START "Fetching foonathan_memory...") + list(APPEND CMAKE_MESSAGE_INDENT " ") + + FetchContent_Declare( + foonathan_memory + GIT_REPOSITORY https://github.com/foonathan/memory.git + GIT_TAG "v0.7-3" + GIT_SHALLOW ON # No history needed + SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/third-party/foonathan_memory + ) + + set( BUILD_SHARED_LIBS OFF ) + + # Remove unrequired targets + set(FOONATHAN_MEMORY_BUILD_VARS -DFOONATHAN_MEMORY_BUILD_EXAMPLES=OFF + -DFOONATHAN_MEMORY_BUILD_TESTS=OFF + -DFOONATHAN_MEMORY_BUILD_TOOLS=OFF) -# Align STATIC CRT definitions with LRS -if(BUILD_WITH_STATIC_CRT) - set(FOONATHAN_MEMORY_BUILD_VARS ${FOONATHAN_MEMORY_BUILD_VARS} - -DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW - -DCMAKE_MSVC_RUNTIME_LIBRARY:STRING=MultiThreaded$<$:Debug>) -endif() + # Align STATIC CRT definitions with LRS + if(BUILD_WITH_STATIC_CRT) + set(FOONATHAN_MEMORY_BUILD_VARS ${FOONATHAN_MEMORY_BUILD_VARS} + -DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW + -DCMAKE_MSVC_RUNTIME_LIBRARY:STRING=MultiThreaded$<$:Debug>) + endif() -# Since `FastDDS` require foonathan_memory package installed during configure time, -# We download it build it and install it both in Release & Debug configuration since we need both available. -# We use `FetchContent_Populate` and not `FetchContent_MakeAvailable` for that reason, we want to manually configure and build it. -FetchContent_GetProperties(foonathan_memory) -if(NOT foonathan_memory_POPULATED) - FetchContent_Populate(foonathan_memory) -endif() - -# Mark new options from FetchContent as advanced options -mark_as_advanced(FETCHCONTENT_SOURCE_DIR_FOONATHAN_MEMORY) -mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_FOONATHAN_MEMORY) - - -# Configure stage -execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/fastdds/fastdds_install - ${FOONATHAN_MEMORY_BUILD_VARS} - . - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/third-party/foonathan_memory" - OUTPUT_QUIET - RESULT_VARIABLE configure_ret -) - -# Build and install Debug version -execute_process(COMMAND "${CMAKE_COMMAND}" --build . --config Debug --target install - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/third-party/foonathan_memory" - OUTPUT_QUIET - RESULT_VARIABLE debug_build_ret -) - -# Build and install RelWithDeb version -execute_process(COMMAND "${CMAKE_COMMAND}" --build . --config RelWithDebInfo --target install - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/third-party/foonathan_memory" - OUTPUT_QUIET - RESULT_VARIABLE rel_with_deb_info_build_ret -) - -# Build and install Release version -execute_process(COMMAND "${CMAKE_COMMAND}" --build . --config Release --target install - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/third-party/foonathan_memory" - OUTPUT_QUIET - RESULT_VARIABLE release_build_ret -) - - if(configure_ret OR debug_build_ret OR release_build_ret OR rel_with_deb_info_build_ret) - message( FATAL_ERROR "Failed to build foonathan_memory") - endif() - -list(POP_BACK CMAKE_MESSAGE_INDENT) -message(CHECK_PASS "Done") + # Since `FastDDS` require foonathan_memory package installed during configure time, + # We download it build it and install it both in Release & Debug configuration since we need both available. + # We use `FetchContent_Populate` and not `FetchContent_MakeAvailable` for that reason, we want to manually configure and build it. + FetchContent_GetProperties(foonathan_memory) + if(NOT foonathan_memory_POPULATED) + FetchContent_Populate(foonathan_memory) + endif() + + # Mark new options from FetchContent as advanced options + mark_as_advanced(FETCHCONTENT_SOURCE_DIR_FOONATHAN_MEMORY) + mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_FOONATHAN_MEMORY) + + + add_subdirectory( "${foonathan_memory_SOURCE_DIR}" "${foonathan_memory_SOURCE_DIR}/build" ) + + + # Without this line, everything seems to work but find_package() will give: + # Found foonathan_memory: foonathan_memory_DIR-NOTFOUND + set( foonathan_memory_DIR "${foonathan_memory_SOURCE_DIR}" ) + + + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "Done") + +endfunction() + +get_foonathan_memory()