This repository was archived by the owner on Feb 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
234 lines (185 loc) · 8.32 KB
/
CMakeLists.txt
File metadata and controls
234 lines (185 loc) · 8.32 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# Set the module directory for ease of use in other parts of the configuration
set(MSCL_MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake")
# Append the custom CMake directory so the files can be imported
list(APPEND CMAKE_MODULE_PATH "${MSCL_MODULE_DIR}")
# Set some options for the build
# Any options needed to configure the root project are defined here
include(mscl-options)
# Configure vcpkg for use
include(mscl-configure-vcpkg)
cmake_minimum_required(VERSION 3.23)
project("MSCL"
LANGUAGES CXX
VERSION 68.1.0
)
# Enable the use of organizing projects into folders for IDEs that support it
set_property(GLOBAL PROPERTY
USE_FOLDERS ON
)
# Set the root folder name for IDE folders
set(CMAKE_FOLDER "${PROJECT_NAME}")
# Supported build configurations
set(CMAKE_CONFIGURATION_TYPES "Release;Debug")
# Export compile commands by default (helpful for clang-tidy and autocomplete for certain IDEs)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Set some global C++ options
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
# If a build type was not specified, default to debug
if(NOT GENERATOR_IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
if(BUILD_SHARED_LIBS AND (MSCL_BUILD_PYTHON OR MSCL_BUILD_CSHARP))
message(WARNING "${PROJECT_NAME} needs to be built as a static library to build language bindings. Disabling BUILD_SHARED_LIBS")
set(BUILD_SHARED_LIBS OFF)
endif()
# Create the common dependencies directory in the project root
# This is for use by downloaded dependencies during project configuration
if(NOT MSCL_DEPS_BASE_DIR)
set(MSCL_DEPS_BASE_DIR "${CMAKE_CURRENT_LIST_DIR}/_deps")
endif()
# Get the current year to make sure the file copyright is up-to-date in any generated files that use it
string(TIMESTAMP MSCL_CURRENT_YEAR "%Y")
# Include some utilities used for MicroStrain projects
include(microstrain-utilities)
# Update the copyright in the license and readme files if needed
microstrain_update_copyright_in_files(FILES
"${CMAKE_CURRENT_LIST_DIR}/LICENSE"
"${CMAKE_CURRENT_LIST_DIR}/README.md"
)
# Detect if this is a x64 or x86 build
microstrain_get_architecture(MSCL_ARCH_NAME)
if(${MSCL_ARCH_NAME} STREQUAL "x64")
# This needs to be enabled to properly find any libraries that use the lib64 naming convention
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
endif()
# This will make windows create a .lib file with all the symbols of the .dll files exported
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Parse some flags
# These are all ON/OFF flags. For example, -DBUILD_SHARED_LIBS="ON"
option(MSCL_WITH_WEBSOCKETS "Whether or not to compile the library with Websocket support" ON)
option(MSCL_BUILD_CPP_EXAMPLES "Whether to build the C++ examples" OFF)
option(MSCL_BUILD_PACKAGE "Whether to build a package from the resulting binaries" OFF)
if(WIN32)
option(MSCL_BUILD_CSHARP "Whether to build the C# bindings. Only supported on Windows" OFF)
option(MSCL_BUILD_CSHARP_EXAMPLES "Whether to build the C# examples" OFF)
if(MSCL_BUILD_CSHARP_EXAMPLES AND NOT MSCL_BUILD_CSHARP)
message(WARNING "'MSCL_BUILD_CSHARP_EXAMPLES' is ON but 'MSCL_BUILD_CSHARP' is not. Enabling 'MSCL_BUILD_CSHARP'")
set(MSCL_BUILD_CSHARP ON)
endif()
option(MSCL_BUILD_DOCUMENTATION "Whether to build the documentation" OFF)
else()
if(MSCL_BUILD_CSHARP)
message(WARNING "'MSCL_BUILD_CSHARP' is enabled but not supported. Disabling")
set(MSCL_BUILD_CSHARP OFF)
endif()
if(MSCL_BUILD_CSHARP_EXAMPLES)
message(WARNING "'MSCL_BUILD_CSHARP_EXAMPLES' is enabled but not supported. Disabling")
set(MSCL_BUILD_CSHARP_EXAMPLES OFF)
endif()
if(MSCL_BUILD_DOCUMENTATION)
message(WARNING "'MSCL_BUILD_DOCUMENTATION' is enabled but not supported. Disabling")
set(MSCL_BUILD_DOCUMENTATION OFF)
endif()
endif()
# Use Git to find the version and commit of this repo
microstrain_get_git_version(MSCL_GIT_VERSION MSCL_GIT_VERSION_CLEAN)
microstrain_get_git_commit(MSCL_GIT_COMMIT)
string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER)
# Configure packaging before including all the targets with add_subdirectory
# Subdirectories depend on most of these options
if(MSCL_BUILD_PACKAGE)
# Set the CPack generators to use based on the system
microstrain_set_cpack_archive_generators()
set(CPACK_PACKAGE_VENDOR "MicroStrain by HBK")
set(CPACK_PACKAGE_CONTACT "MicroStrain Support <microstrainsupport@hbkworld.com>")
microstrain_get_package_architecture(CPACK_SYSTEM_NAME)
microstrain_get_git_branch(MSCL_GIT_BRANCH MSCL_BRANCH) # Second param is used to set a cache variable
if("${MSCL_GIT_BRANCH}" STREQUAL "master")
# Use the project version for assets built on master
set(CPACK_PACKAGE_VERSION "v${PROJECT_VERSION}")
else()
# Use the tag for all other assets
set(CPACK_PACKAGE_VERSION "${MSCL_GIT_VERSION}")
endif()
# Don't group packages
set(CPACK_COMPONENTS_GROUPING IGNORE)
if(CPACK_BINARY_DEB)
# Turn on automatic dependency detection for Linux packages (RPM has this option enabled by default)
# Allow dpkg to determine the package dependencies
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
# Create one package per component
set(CPACK_DEB_COMPONENT_INSTALL ON)
# Set the Debian package version to conform to the standard
if(CPACK_PACKAGE_VERSION MATCHES "^v([0-9.]+)$")
set(CPACK_DEBIAN_PACKAGE_VERSION "${CMAKE_MATCH_1}")
elseif(CPACK_PACKAGE_VERSION MATCHES "^v([0-9.]+)-([0-9]+)-g([0-9a-f]+)")
set(CPACK_DEBIAN_PACKAGE_VERSION "${CMAKE_MATCH_1}+git${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
endif()
elseif(CPACK_BINARY_RPM)
# Create one package per component
set(CPACK_RPM_COMPONENT_INSTALL ON)
else()
# Create one package per component
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
endif()
# Setup the install prefix for all packages
if(MSVC)
string(APPEND CPACK_PACKAGING_INSTALL_PREFIX "/${PROJECT_NAME_LOWER}")
endif()
endif()
if(MSVC)
# Set the runtime library linking for all projects
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
# Use common installation directory naming conventions
include(GNUInstallDirs)
# Set the proper library install directory
set(MSCL_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
# Set the library install directory for x86 builds
if(${MSCL_ARCH_NAME} STREQUAL "x86")
string(APPEND MSCL_INSTALL_LIBDIR "32")
endif()
# Set the library install directory for debug builds
string(APPEND MSCL_INSTALL_LIBDIR "$<$<CONFIG:Debug>:/debug>")
# Build the library
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/src")
# Build the documentation
if(MSCL_BUILD_DOCUMENTATION)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/docs")
endif()
# Build the testing suite
if(MSCL_BUILD_TESTS)
enable_testing()
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/tests")
endif()
# Build one or more of the bindings
if(MSCL_BUILD_PYTHON OR MSCL_BUILD_CSHARP)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/bindings")
endif()
# Build the examples
if(MSCL_BUILD_CPP_EXAMPLES OR MSCL_BUILD_CSHARP_EXAMPLES OR MSCL_BUILD_PYTHON_EXAMPLES)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/examples")
endif()
# Include the CPack module for packaging
# Package options are configured before including any subdirectories to ensure proper configurations
if(MSCL_BUILD_PACKAGE)
# Make sure to always create separate packages per component
# When only one component is specified CPack will make a project package instead of a component package
get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS)
# NOTE: CPack requires all configuration variables to be set before including this module
# Always include this AFTER configuring everything for CPack
include(CPack)
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL
PROPERTY GENERATOR_IS_MULTI_CONFIG
)
# Add the packaging configuration file to the build directory for single-config generators
# This allows easy access to the file from the build directory
if(NOT GENERATOR_IS_MULTI_CONFIG)
file(
COPY "${MSCL_MODULE_DIR}/microstrain-package-all.cmake"
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}"
)
endif()
endif()