forked from mosys/opentrackio-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
136 lines (110 loc) · 5.25 KB
/
Copy pathCMakeLists.txt
File metadata and controls
136 lines (110 loc) · 5.25 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
# Copyright 2025 Mo-Sys Engineering Ltd
# 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.15.7)
project(opentrackio-cpp VERSION 1.0.1 LANGUAGES CXX)
# Optional test suite
option(OPENTRACKIO_BUILD_TESTS "Build the test suite" OFF)
option(BUILD_STATIC_LIBS "Build opentrackio static libraries" OFF)
# Set optimization flags for Release builds
if(MSVC)
# Windows/MSVC optimizations
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Ob2 /GL")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG /OPT:REF /OPT:ICF")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /OPT:REF /OPT:ICF")
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /LTCG")
else()
# Linux/macOS/GCC/Clang optimizations
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -flto")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -flto")
endif()
set (
source_list
src/OpenTrackIOProperties.cpp
src/OpenTrackIOSample.cpp
)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(nlohmann_json REQUIRED)
# Build static library if requested, otherwise build shared
if(BUILD_STATIC_LIBS)
add_library(${PROJECT_NAME} STATIC)
else()
add_library(${PROJECT_NAME} SHARED)
endif()
target_sources(${PROJECT_NAME} PRIVATE ${source_list})
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
# Handle debug vs release builds and their separate libs
# Standard generator
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "${PROJECT_NAME}d")
else()
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "${PROJECT_NAME}")
endif()
# Multi-config generator
if(CMAKE_CONFIGURATION_TYPES)
set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_NAME_DEBUG "${PROJECT_NAME}d"
OUTPUT_NAME_RELEASE "${PROJECT_NAME}"
OUTPUT_NAME_RELWITHDEBINFO "${PROJECT_NAME}"
OUTPUT_NAME_MINSIZEREL "${PROJECT_NAME}"
)
endif()
include(GNUInstallDirs)
target_include_directories(
${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(${PROJECT_NAME} PUBLIC nlohmann_json::nlohmann_json)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Write targets and config out to different folders depending on OS relating to the differing search procedure cmake does.
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(cmake_targets_install_dir cmake)
else()
set(cmake_targets_install_dir cmake/${PROJECT_NAME})
endif()
install(EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${cmake_targets_install_dir}
)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/${PROJECT_NAME}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
# If json dep isn't covered by conan then copy ours to the install
get_target_property(IS_CONAN_PACKAGE nlohmann_json::nlohmann_json INTERFACE_COMPILE_OPTIONS)
if (NOT IS_CONAN_PACKAGE)
message("Build isn't Conan. Copying JSON deps.")
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external/nlohmann/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/external/nlohmann/)
endif()
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${cmake_targets_install_dir}
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION ${cmake_targets_install_dir}
)
if(OPENTRACKIO_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
option(OPENTRACKIO_BUILD_TOOLS "Build battery-tester CLI tools (dump_sample)" OFF)
if(OPENTRACKIO_BUILD_TOOLS)
add_subdirectory(tools/dump_sample)
endif()