forked from airbus/ED247_LIBRARY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
194 lines (170 loc) · 8.09 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
###############################################################################
# The MIT Licence #
# #
# Copyright (c) 2020 Airbus Operations S.A.S #
# #
# Permission is hereby granted, free of charge, to any person obtaining a #
# copy of this software and associated documentation files (the "Software"), #
# to deal in the Software without restriction, including without limitation #
# the rights to use, copy, modify, merge, publish, distribute, sublicense, #
# and/or sell copies of the Software, and to permit persons to whom the #
# Software is furnished to do so, subject to the following conditions: #
# #
# The above copyright notice and this permission notice shall be included #
# in all copies or substantial portions of the Software. #
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
# DEALINGS IN THE SOFTWARE. #
###############################################################################
cmake_minimum_required(VERSION 3.13)
# Set CMAKE_BUILD_TYPE to Release by default.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()
# SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "" FORCE)
project(ED247_LIBRARY)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/VERSION ED247_LIBRARY_VERSION)
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_C_STANDARD 11)
# Print some useful information to screen
STRING(TIMESTAMP CMAKE_CONFIGURE_DATE UTC)
MESSAGE("########################################################")
MESSAGE("# Project ${PROJECT_NAME}")
MESSAGE("# Version ${ED247_LIBRARY_VERSION}")
MESSAGE("# System Name ${CMAKE_SYSTEM_NAME}")
MESSAGE("# Processor ${CMAKE_SYSTEM_PROCESSOR}")
MESSAGE("# Directory ${CMAKE_SOURCE_DIR}")
MESSAGE("# Date ${CMAKE_CONFIGURE_DATE}")
MESSAGE("########################################################")
# Options
option(BUILD_SAMPLES "Build samples" OFF)
option(BUILD_TESTS "Build tests" OFF)
option(BUILD_DOCS "Build documentation" OFF)
option(BUILD_UTILS "Build utils executables" OFF)
option(BUILD_DEPS_LIBXML2 "Build libxml2 dependency" ON)
if(BUILD_TESTS)
option(BUILD_DEPS_GTEST "Build googletest dependency" ON)
# option(ENABLE_MEMHOOKS "Enable compilation of memory hooks" ON)
set(TEST_MULTICAST_INTERFACE_IP "" CACHE STRING "Ip address of the interface to use for multicast when performing the tests")
else()
# option(ENABLE_MEMHOOKS "Enable compilation of memory hooks" OFF)
endif()
# Set up the common directory structure for output libraries and binaries
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
# For Unix-like operating systems we can put all libraries into a dedicated
# lib/ folder, whereas for Windows the libraries (dll files) need to be put
# into the same directory as the executable, since Windows doesn't have an
# RPATH equivalent where a search path can be put into the executable itself
if(UNIX)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
else()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
if(MSVC)
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:MSVCRT")
set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
set(CMAKE_INSTALL_DEBUG_LIBRARIES TRUE)
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION "lib")
include(InstallRequiredSystemLibraries)
endif()
# Dependencies
## LIBXML2
if(BUILD_DEPS_LIBXML2)
set(LIBXML2_WITH_ICONV OFF CACHE BOOL "" FORCE)
set(LIBXML2_WITH_LZMA OFF CACHE BOOL "" FORCE)
set(LIBXML2_WITH_PYTHON OFF CACHE BOOL "" FORCE)
set(LIBXML2_WITH_ZLIB OFF CACHE BOOL "" FORCE)
set(LIBXML2_WITH_TESTS OFF CACHE BOOL "" FORCE)
set(LIBXML2_WITH_THREADS ON CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) # TO TEST
add_subdirectory(deps/libxml2 EXCLUDE_FROM_ALL)
else()
find_package(LibXml2 REQUIRED)
endif()
## GTEST
if(BUILD_DEPS_GTEST)
if(MSVC)
set(gtest_force_shared_crt ON CACHE BOOL "My option" FORCE)
endif()
set(gtest_disable_pthreads OFF CACHE BOOL "My option" FORCE)
set(BUILD_GMOCK OFF CACHE BOOL "My option" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "My option" FORCE)
set(GTEST_USE_OWN_TR1_TUPLE OFF CACHE BOOL "My option" FORCE)
set(GTEST_HAS_TR1_TUPLE OFF CACHE BOOL "My option" FORCE)
add_subdirectory(deps/googletest EXCLUDE_FROM_ALL)
else()
if(BUILD_TESTS)
find_package(GTest)
endif()
endif()
# if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
# set(CMAKE_EXE_LINKER "${CMAKE_EXE_LINKER} ${CMAKE_EXE_LINKER_DEBUG}")
# else()
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
# set(CMAKE_EXE_LINKER "${CMAKE_EXE_LINKER} ${CMAKE_EXE_LINKER_RELEASE}")
# endif()
# Add compilation flags
# set(CMAKE_CXX_STANDARD 11)
if(MSVC)
else()
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wno-narrowing")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-narrowing")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-unknown-pragmas -fvisibility=hidden")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wno-unknown-pragmas -fvisibility=hidden")
# if(WIN32)
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -static")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++ -static")
# else()
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -rdynamic")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GNU_SOURCE -rdynamic")
# endif()
endif()
if(UNIX)
# if(BUILD_TESTS)
# message("-- Add coverage flags")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -ggdb")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -ggdb")
# set(CMAKE_EXE_LINKER "${CMAKE_EXE_LINKER_FLAGS} --coverage")
# endif()
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_SKIP_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "$ORIGIN:$ORIGIN/../../lib:$ORIGIN/../lib")
endif()
# Add source folder
add_subdirectory(src)
if(BUILD_SAMPLES OR BUILD_TESTS OR BUILD_UTILS)
add_subdirectory(shared)
endif()
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
if(BUILD_SAMPLES)
add_subdirectory(samples)
endif()
if(BUILD_UTILS)
add_subdirectory(utils)
endif()
if(BUILD_DOCS)
add_subdirectory(doc)
endif()
install(FILES LICENSE.md DESTINATION .)