forked from eProsima/foonathan_memory_vendor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
131 lines (116 loc) · 4.77 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
cmake_minimum_required(VERSION 3.5)
project(foonathan_memory_vendor VERSION "1.1.0")
find_package(foonathan_memory QUIET)
if(NOT foonathan_memory_FOUND)
###############################################################################
# Default shared libraries
###############################################################################
# Global flag to cause add_library() to create shared libraries if on.
# If set to true, this will cause all libraries to be built shared
# unless the library was explicitly added as a static library.
option(BUILD_SHARED_LIBS "Create shared libraries by default" ON)
# Option to build memory examples
option(BUILD_MEMORY_EXAMPLES "Build memory examples" OFF)
# Option to build memory tests
option(BUILD_MEMORY_TESTS "Build memory tests" OFF)
# Option to build memory tools
option(BUILD_MEMORY_TOOLS "Build memory tools" ON)
# Validate option dependency
if((NOT BUILD_MEMORY_TOOLS) AND (BUILD_MEMORY_EXAMPLES OR BUILD_MEMORY_TESTS))
message(FATAL_ERROR
"BUILD_MEMORY_TOOLS is required when BUILD_MEMORY_EXAMPLES"
" or BUILD_MEMORY_TESTS are set")
endif()
if(BUILD_SHARED_LIBS)
# Library will be statically created with PIC code
list(APPEND extra_cmake_args -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
endif()
if(DEFINED CMAKE_BUILD_TYPE)
list(APPEND extra_cmake_args -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
endif()
if(DEFINED CMAKE_TOOLCHAIN_FILE)
list(APPEND extra_cmake_args "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
if(ANDROID)
if(DEFINED ANDROID_ABI)
list(APPEND extra_cmake_args "-DANDROID_ABI=${ANDROID_ABI}")
endif()
if(DEFINED ANDROID_CPP_FEATURES)
list(APPEND extra_cmake_args "-DANDROID_CPP_FEATURES=${ANDROID_CPP_FEATURES}")
endif()
if(DEFINED ANDROID_FUNCTION_LEVEL_LINKING)
list(APPEND extra_cmake_args
"-DANDROID_FUNCTION_LEVEL_LINKING=${ANDROID_FUNCTION_LEVEL_LINKING}")
endif()
if(DEFINED ANDROID_NATIVE_API_LEVEL)
list(APPEND extra_cmake_args "-DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL}")
endif()
if(DEFINED ANDROID_NDK)
list(APPEND extra_cmake_args "-DANDROID_NDK=${ANDROID_NDK}")
endif()
if(DEFINED ANDROID_STL)
list(APPEND extra_cmake_args "-DANDROID_STL=${ANDROID_STL}")
endif()
if(DEFINED ANDROID_TOOLCHAIN_NAME)
list(APPEND extra_cmake_args "-DANDROID_TOOLCHAIN_NAME=${ANDROID_TOOLCHAIN_NAME}")
endif()
endif()
endif()
include(ExternalProject)
if(INSTALLER_PLATFORM)
set(PATCH_COMMAND_STR PATCH_COMMAND
git apply ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.patch &&
sed -i -e "s/INSTALLER_PLATFORM/${INSTALLER_PLATFORM}/g" CMakeLists.txt)
elseif(BUILD_MEMORY_TESTS)
# This could be removed whenever we change the GIT_TAG from c619113 to anything above 09b884c
set(PATCH_COMMAND_STR PATCH_COMMAND
curl https://github.com/foonathan/memory/commit/09b884c18abb314bfa678df27141a4dcad71c4ba.diff | git apply -)
endif()
externalproject_add(foo_mem-ext
GIT_REPOSITORY https://github.com/foonathan/memory.git
GIT_TAG c619113
TIMEOUT 600
# Avoid the update (git pull) and so the recompilation of foonathan_memory library each time.
UPDATE_COMMAND ""
CMAKE_ARGS
-DFOONATHAN_MEMORY_BUILD_EXAMPLES=${BUILD_MEMORY_EXAMPLES}
-DFOONATHAN_MEMORY_BUILD_TESTS=${BUILD_MEMORY_TESTS}
-DFOONATHAN_MEMORY_BUILD_TOOLS=${BUILD_MEMORY_TOOLS}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/foo_mem_ext_prj_install
${extra_cmake_args}
-Wno-dev
${PATCH_COMMAND_STR}
)
# The external project will install to the build folder, but we'll install that on make install.
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/foo_mem_ext_prj_install/
DESTINATION ${CMAKE_INSTALL_PREFIX})
else()
message(STATUS "Found foonathan_memory ${foonathan_memory_VERSION}")
endif()
configure_file(foonathan_memory_vendorConfig.cmake.in
"${PROJECT_BINARY_DIR}/foonathan_memory_vendorConfig.cmake" @ONLY)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/foonathan_memory_vendorConfig-version.cmake"
COMPATIBILITY AnyNewerVersion)
find_package(ament_cmake_test QUIET)
if(BUILD_TESTING)
find_package(ament_cmake_copyright QUIET)
find_package(ament_cmake_lint_cmake QUIET)
find_package(ament_cmake_xmllint QUIET)
if(ament_cmake_copyright_FOUND)
ament_copyright()
endif()
if(ament_cmake_lint_cmake_FOUND)
ament_lint_cmake()
endif()
if(ament_cmake_xmllint_FOUND)
ament_xmllint()
endif()
endif()
install(FILES
package.xml
DESTINATION share/${PROJECT_NAME})
install(FILES
"${PROJECT_BINARY_DIR}/foonathan_memory_vendorConfig.cmake"
"${PROJECT_BINARY_DIR}/foonathan_memory_vendorConfig-version.cmake"
DESTINATION share/${PROJECT_NAME}/cmake)