-
Notifications
You must be signed in to change notification settings - Fork 30
/
CMakeLists.txt
213 lines (178 loc) · 7.86 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
cmake_minimum_required(VERSION 3.24)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}")
if (APPLE)
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "OS X target architectures")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")
endif()
project(emil LANGUAGES C CXX VERSION 7.0.0) # x-release-please-version
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set_directory_properties(PROPERTY USE_FOLDERS On)
include(CMakePackageConfigHelpers)
include(emil_antora)
include(emil_build_for)
include(emil_folderize)
include(emil_clang_tools)
include(emil_docker_tools)
include(emil_generate_artifacts)
include(emil_test_helpers)
include(emil_version_generator)
include(emil_xsltproc)
include(FetchContent)
include(GNUInstallDirs) # included to supply proper defaults to install(...) commands
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(EMIL_STANDALONE On)
endif()
if (MINGW)
# When compiling with MINGW, dynamically linking to the standard C++ library results in linking to libstdc++-6.dll.
# The libstdc++-6.dll found during runtime is often different than the one with which the application is compiled with,
# so instead of linking dynamically, we statically link to the standard C++ library.
add_link_options("-static-libstdc++")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(EMIL_BUILD_WIN On)
set(EMIL_HOST_BUILD On)
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/EHsc>)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(EMIL_BUILD_UNIX On)
set(EMIL_HOST_BUILD On)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(EMIL_BUILD_DARWIN On)
set(EMIL_HOST_BUILD On)
# Suppress warnings about *.a files having no symbols on Darwin.
# The warning is emitted when *.cpp.o contains no operational code.
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Generic")
enable_language(ASM)
endif()
# When building EmIL by itself the examples and tests will be built
# by-default. When consuming EmIL as a dependency the tests and
# examples are disabled. This behavior can be overridden by below
# options.
if (EMIL_STANDALONE AND EMIL_HOST_BUILD)
set(EMIL_DEFAULTOPT On)
set(EMIL_DEFAULTOPT_INVERTED Off)
else()
set(EMIL_DEFAULTOPT Off)
set(EMIL_DEFAULTOPT_INVERTED On)
endif()
# When building EmIL by itself do not exclude any targets from all
# Libraries will only be excluded from all when EmIL is a consumed as a dependency.
if (EMIL_STANDALONE)
set(EMIL_EXCLUDE_FROM_ALL "")
else()
set(EMIL_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL")
endif()
option(EMIL_BUILD_TESTS "Enable building the tests" ${EMIL_DEFAULTOPT})
option(EMIL_BUILD_EXAMPLES "Enable building the examples" ${EMIL_DEFAULTOPT})
option(EMIL_ENABLE_FUZZING "Enable building the fuzzing targets" Off)
option(EMIL_ENABLE_DOCKER_TOOLS "Enable shift-left tools (e.g. linters, formatters) that are run using Docker" On)
option(EMIL_GENERATE_PACKAGE_CONFIG "Enable generation of package configuration and install files" ${EMIL_HOST_BUILD})
option(EMIL_ENABLE_TRACING "Enable Tracing" On)
option(EMIL_FETCH_ECHO_COMPILERS "Fetch the Protobuf ECHO compilers from GitHub" ${EMIL_DEFAULTOPT_INVERTED})
if (NOT EMIL_FETCH_ECHO_COMPILERS)
set(EMIL_DEFAULTOPT_BUILD_ECHO_COMPILERS ${EMIL_DEFAULTOPT})
else()
set(EMIL_DEFAULTOPT_BUILD_ECHO_COMPILERS Off)
endif()
option(EMIL_BUILD_ECHO_COMPILERS "Build and install the Protobuf ECHO compilers" ${EMIL_DEFAULTOPT_BUILD_ECHO_COMPILERS})
if (EMIL_FETCH_ECHO_COMPILERS AND EMIL_BUILD_ECHO_COMPILERS)
message(FATAL_ERROR "Invalid combination: EMIL_FETCH_ECHO_COMPILERS AND EMIL_BUILD_ECHO_COMPILERS. Please select only one of these.")
endif()
# Enable or disable optional features.
option(EMIL_INCLUDE_MBEDTLS "Include MbedTLS as part of EmIL" On)
set(EMIL_EXTERNAL_MBEDTLS_TARGET "" CACHE STRING "Specify an external MbedTLS target")
option(EMIL_INCLUDE_FREERTOS "Include FreeRTOS as part of EmIL" Off)
option(EMIL_INCLUDE_THREADX "Include ThreadX as part of EmIL (Incomplete, experimental)" Off)
option(EMIL_INCLUDE_SEGGER_RTT "Include support for Segger RTT" Off)
set(EMIL_EXTERNAL_LWIP_TARGET "" CACHE STRING "Specify an external LWIP target")
if (EMIL_ENABLE_DOCKER_TOOLS)
emil_enable_docker_tools()
endif()
if (EMIL_HOST_BUILD)
add_compile_definitions(EMIL_HOST_BUILD)
if (EMIL_BUILD_TESTS)
include(CTest)
emil_enable_testing()
endif()
if (EMIL_ENABLE_FUZZING)
set(EMIL_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL")
emil_enable_fuzzing()
endif()
endif()
if (NOT EMIL_STANDALONE)
set(EMIL_HOST_BUILD "${EMIL_HOST_BUILD}" PARENT_SCOPE)
set(EMIL_BUILD_WIN "${EMIL_BUILD_WIN}" PARENT_SCOPE)
set(EMIL_BUILD_UNIX "${EMIL_BUILD_UNIX}" PARENT_SCOPE)
set(EMIL_BUILD_DARWIN "${EMIL_BUILD_DARWIN}" PARENT_SCOPE)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Suppress warnings about parameter passing for argument of type '...' changed in GCC 7.1
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wno-psabi>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-psabi>)
endif()
add_version_header_target(generated.version_header)
add_subdirectory(external)
add_subdirectory(infra)
add_subdirectory(hal)
add_subdirectory(protobuf)
add_subdirectory(services)
add_subdirectory(upgrade)
add_subdirectory(lwip)
add_subdirectory(osal)
if (EMIL_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
emil_clangformat_directories(emil DIRECTORIES .)
if (EMIL_STANDALONE)
emil_generate_antora_docs_target(antora-playbook-branch.yml)
emil_folderize_all_targets()
endif()
if (EMIL_BUILD_ECHO_COMPILERS AND NOT CMAKE_CROSSCOMPILING)
function(generate_export_targets name)
install(EXPORT emil${name}Targets
FILE emil${name}Targets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/emil
)
endfunction()
foreach(target IN ITEMS Protobuf)
generate_export_targets(${target})
endforeach()
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
# When cross-compiling for a 32-bit architecture and re-using host tooling from a 64-bit architecture
# ARCH_INDEPENDENT is necessary here. See: https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html.
ARCH_INDEPENDENT
)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
endif()
set(CPACK_GENERATOR "ZIP;TGZ")
set(CPACK_SOURCE_IGNORE_FILES ".vs/;.git/;build/")
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_VENDOR "Koninklijke Philips N.V")
set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
set(CPACK_DEBIAN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
include(CPack)