-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
161 lines (136 loc) · 5.59 KB
/
Copy pathCMakeLists.txt
File metadata and controls
161 lines (136 loc) · 5.59 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
# CereLink Build System
# Author: chadwick.boulay@gmail.com
#
# Modular architecture: cbproto → cbshm → cbdev → cbsdk
cmake_minimum_required(VERSION 3.16)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" ${CMAKE_MODULE_PATH})
include(AppleSilicon)
include(GetVersionFromGit)
include(CheckAtomicNeeded)
# Get version from git tags
get_version_from_git()
project(CBSDK
DESCRIPTION "Blackrock Neurotech CereBus Software Development Kit"
LANGUAGES C CXX
VERSION ${GIT_VERSION_FULL}
)
# Common Configuration
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Required for static libs linked into shared lib (cbsdk_shared)
##########################################################################################
# Optional Targets
include(CMakeDependentOption)
# Build options for new architecture
cmake_dependent_option(CBSDK_BUILD_TEST "Build tests" ON
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
cmake_dependent_option(CBSDK_BUILD_SAMPLE "Build sample applications" ON
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
cmake_dependent_option(CBSDK_BUILD_TOOLS "Build validation tools" ON
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
##########################################################################################
# Misc Configuration
# -Make sure debug builds are recognized
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Add a postfix, usually d on windows")
# -Force universal binary on macOS
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
if(WIN32)
# Preprocessor definitions for Windows
add_compile_definitions(
WIN32 _WINDOWS NO_AFX NOMINMAX
_CRT_SECURE_NO_WARNINGS
_WINSOCK_DEPRECATED_NO_WARNINGS
)
# Ensure Windows SDK architecture macros are defined.
# Required when consumed as a dependency (FetchContent) where the consuming
# project may not properly propagate architecture settings.
# Without this, winnt.h fails with "No Target Architecture" error.
if(CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|aarch64")
add_compile_definitions(_ARM64_)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_compile_definitions(_AMD64_)
else()
add_compile_definitions(_X86_)
endif()
endif(WIN32)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
cmake_policy(SET CMP0063 NEW) # Honor visibility properties for all target types
cmake_policy(SET CMP0042 NEW) # MACOSX_RPATH is enabled by default
##########################################################################################
# Standard installation directories
include(GNUInstallDirs)
##########################################################################################
# New Modular Architecture
message(STATUS "Building modular architecture")
add_subdirectory(src/cbproto)
add_subdirectory(src/cbutil)
add_subdirectory(src/ccfutils)
add_subdirectory(src/cbshm)
add_subdirectory(src/cbdev)
add_subdirectory(src/cbsdk)
##########################################################################################
# Tests for Modular Architecture
if(CBSDK_BUILD_TEST)
enable_testing()
add_subdirectory(tests/unit)
add_subdirectory(tests/integration)
endif(CBSDK_BUILD_TEST)
##########################################################################################
# Validation Tools
# Gated like tests and samples: a project consuming CereLink wants the
# libraries, not our benchmark executables. rx_bench in particular pulls in
# ccfutils -> pugixml, which breaks a consumer building for an architecture
# pugixml was not configured for (e.g. a macOS universal binary).
if(CBSDK_BUILD_TOOLS)
add_subdirectory(tools/validate_clock_sync)
add_subdirectory(tools/rx_bench)
endif(CBSDK_BUILD_TOOLS)
##########################################################################################
# Sample Applications for New Architecture
if(CBSDK_BUILD_SAMPLE)
add_subdirectory(examples)
endif(CBSDK_BUILD_SAMPLE)
##########################################################################################
# Installation
# The actual installation targets are defined in the subdirectories:
# - src/cbproto/CMakeLists.txt installs cbproto
# - src/cbshm/CMakeLists.txt installs cbshm
# - src/cbdev/CMakeLists.txt installs cbdev
# - src/cbsdk/CMakeLists.txt installs cbsdk
# Install sample applications if built
if(CBSDK_BUILD_SAMPLE AND SAMPLE_TARGET_LIST)
install(TARGETS ${SAMPLE_TARGET_LIST}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
##########################################################################################
# CMake Package Config for new architecture
include(CMakePackageConfigHelpers)
# Install the export targets (collected from subdirectories)
install(EXPORT CBSDKTargets
FILE CBSDKTargets.cmake
NAMESPACE CBSDK::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CBSDK
)
# Create a basic config file
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CBSDKConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CBSDKConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CBSDK
)
# Create a version file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/CBSDKConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
# Install the config and version files
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/CBSDKConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CBSDKConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CBSDK
)
##########################################################################################
# Packaging
# Invoke with `cmake --build <cmake_build_dir> --target package`
include(Packing)