|
1 | 1 | cmake_minimum_required(VERSION 3.11) |
2 | 2 | include(FetchContent) |
3 | 3 |
|
4 | | -# Mark new options from FetchContent as advanced options |
5 | | -mark_as_advanced(FETCHCONTENT_QUIET) |
6 | | -mark_as_advanced(FETCHCONTENT_BASE_DIR) |
7 | | -mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED) |
8 | | -mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED) |
| 4 | +# 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) |
| 5 | +function(get_foonathan_memory) |
9 | 6 |
|
10 | | -message(CHECK_START "Fetching & Installing foonathan_memory...") |
11 | | -list(APPEND CMAKE_MESSAGE_INDENT " ") |
| 7 | + # Mark new options from FetchContent as advanced options |
| 8 | + mark_as_advanced(FETCHCONTENT_QUIET) |
| 9 | + mark_as_advanced(FETCHCONTENT_BASE_DIR) |
| 10 | + mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED) |
| 11 | + mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED) |
12 | 12 |
|
13 | | -FetchContent_Declare( |
14 | | - foonathan_memory |
15 | | - GIT_REPOSITORY https://github.com/foonathan/memory.git |
16 | | - GIT_TAG "v0.7-2" |
17 | | - GIT_SHALLOW ON # No history needed |
18 | | - SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/third-party/foonathan_memory |
19 | | -) |
| 13 | + message(CHECK_START "Fetching foonathan_memory...") |
| 14 | + list(APPEND CMAKE_MESSAGE_INDENT " ") |
20 | 15 |
|
21 | | -# Remove unrequired targets |
22 | | -set(FOONATHAN_MEMORY_BUILD_VARS -DBUILD_SHARED_LIBS=OFF # explicit set static lib |
23 | | - -DFOONATHAN_MEMORY_BUILD_EXAMPLES=OFF |
24 | | - -DFOONATHAN_MEMORY_BUILD_TESTS=OFF |
25 | | - -DFOONATHAN_MEMORY_BUILD_TOOLS=ON) # this tool is needed during configure time only, FastDDS recommend turning it ON. |
26 | | - |
27 | | -# Align STATIC CRT definitions with LRS |
28 | | -if(BUILD_WITH_STATIC_CRT) |
29 | | - set(FOONATHAN_MEMORY_BUILD_VARS ${FOONATHAN_MEMORY_BUILD_VARS} |
30 | | - -DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW |
31 | | - -DCMAKE_MSVC_RUNTIME_LIBRARY:STRING=MultiThreaded$<$<CONFIG:Debug>:Debug>) |
32 | | -endif() |
33 | | - |
| 16 | + FetchContent_Declare( |
| 17 | + foonathan_memory |
| 18 | + GIT_REPOSITORY https://github.com/foonathan/memory.git |
| 19 | + GIT_TAG "v0.7-3" |
| 20 | + GIT_SHALLOW ON # No history needed |
| 21 | + SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/third-party/foonathan_memory |
| 22 | + ) |
34 | 23 |
|
35 | | -# Since `FastDDS` require foonathan_memory package installed during configure time, |
36 | | -# We download it build it and install it both in Release & Debug configuration since we need both available. |
37 | | -# We use `FetchContent_Populate` and not `FetchContent_MakeAvailable` for that reason, we want to manually configure and build it. |
38 | | -FetchContent_GetProperties(foonathan_memory) |
39 | | -if(NOT foonathan_memory_POPULATED) |
40 | | - FetchContent_Populate(foonathan_memory) |
41 | | -endif() |
| 24 | + # Always a static library |
| 25 | + set( BUILD_SHARED_LIBS OFF ) |
42 | 26 |
|
43 | | -# Mark new options from FetchContent as advanced options |
44 | | -mark_as_advanced(FETCHCONTENT_SOURCE_DIR_FOONATHAN_MEMORY) |
45 | | -mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_FOONATHAN_MEMORY) |
| 27 | + # Set foonathan_memory variables |
| 28 | + # These are exposed options; not internal |
| 29 | + set( FOONATHAN_MEMORY_BUILD_EXAMPLES OFF ) |
| 30 | + set( FOONATHAN_MEMORY_BUILD_TESTS OFF ) |
| 31 | + set( FOONATHAN_MEMORY_BUILD_TOOLS OFF ) |
46 | 32 |
|
| 33 | + FetchContent_MakeAvailable( foonathan_memory ) |
47 | 34 |
|
48 | | -# Configure stage |
49 | | -execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/fastdds/fastdds_install |
50 | | - ${FOONATHAN_MEMORY_BUILD_VARS} |
51 | | - . |
52 | | - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/third-party/foonathan_memory" |
53 | | - OUTPUT_QUIET |
54 | | - RESULT_VARIABLE configure_ret |
55 | | -) |
| 35 | + # Mark new options from FetchContent as advanced options |
| 36 | + mark_as_advanced(FETCHCONTENT_SOURCE_DIR_FOONATHAN_MEMORY) |
| 37 | + mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_FOONATHAN_MEMORY) |
56 | 38 |
|
57 | | -# Build and install Debug version |
58 | | -execute_process(COMMAND "${CMAKE_COMMAND}" --build . --config Debug --target install |
59 | | - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/third-party/foonathan_memory" |
60 | | - OUTPUT_QUIET |
61 | | - RESULT_VARIABLE debug_build_ret |
62 | | -) |
| 39 | + list(POP_BACK CMAKE_MESSAGE_INDENT) |
| 40 | + message(CHECK_PASS "Done") |
63 | 41 |
|
64 | | -# Build and install RelWithDeb version |
65 | | -execute_process(COMMAND "${CMAKE_COMMAND}" --build . --config RelWithDebInfo --target install |
66 | | - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/third-party/foonathan_memory" |
67 | | - OUTPUT_QUIET |
68 | | - RESULT_VARIABLE rel_with_deb_info_build_ret |
69 | | -) |
| 42 | +endfunction() |
70 | 43 |
|
71 | | -# Build and install Release version |
72 | | -execute_process(COMMAND "${CMAKE_COMMAND}" --build . --config Release --target install |
73 | | - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/third-party/foonathan_memory" |
74 | | - OUTPUT_QUIET |
75 | | - RESULT_VARIABLE release_build_ret |
76 | | -) |
77 | | - |
78 | | - if(configure_ret OR debug_build_ret OR release_build_ret OR rel_with_deb_info_build_ret) |
79 | | - message( FATAL_ERROR "Failed to build foonathan_memory") |
80 | | - endif() |
81 | | - |
82 | | -list(POP_BACK CMAKE_MESSAGE_INDENT) |
83 | | -message(CHECK_PASS "Done") |
| 44 | +get_foonathan_memory() |
0 commit comments