-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
213 lines (204 loc) · 8.19 KB
/
CMakeLists.txt
File metadata and controls
213 lines (204 loc) · 8.19 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
#===============================================================================
# Required installer settings (at beginning now)
#===============================================================================
# Debian Specific
# Installs into /usr (tests go into /usr/bin/tests)
# libsac-format.a goes into /usr/lib64
# sac-format.hpp goes into /usr/include
set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Alexander R. Blanchette \
<arbCoding@gmail.com>")
# Windows Specific NSIS installer
set(CPACK_NSIS_HELP_LINK "https://arbCoding.github.io/sac-format/")
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
# RedHat Specific
# Installs into /usr (tests go into /usr/bin/tests)
# libsac-format.a goes into /usr/lib64
# sac-format.hpp goes into /usr/include
set(CPACK_RPM_COMPONENT_INSTALL ON)
# Don't strip binaries
set(CPACK_RPM_SPEC_MORE_DEFINE "%define __spec_install_post /bin/true")
# General CPack settings
set(CPACK_COMPONENT_license_HIDDEN TRUE)
set(CPACK_COMPONENT_license_REQUIRED TRUE)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "sac-format")
set(CPACK_PACKAGE_VENDOR "Alexander R. Blanchette <arbCoding@gmail.com>")
# Allow separating components instead of monolithic
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
# Meta-data
set(CPACK_PACKAGE_NAME "sac-format")
set(CPACK_PACKAGE_VENDER "https://arbCoding.github.io/sac-format/")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://arbCoding.github.io/sac-format/")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"C++20 Single-Header SAC File library")
# Filename/installation directory
set(CPACK_PACKAGE_FILE_NAME "sac-format")
# Make checksum
set(CPACK_PACKAGE_CHECKSUM SHA512)
# Only one installer, not separate for each group
set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)
#===============================================================================
# Basic Setup
#===============================================================================
# CMake version
cmake_minimum_required (VERSION 3.25)
# Build type
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
#===============================================================================
# Fetch
#===============================================================================
include(FetchContent)
set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
# Random number generation
FetchContent_Declare(xoshiro
GIT_REPOSITORY https://github.com/Reputeless/Xoshiro-cpp
GIT_TAG v1.1
SYSTEM)
if (WIN32)
# Windows
FetchContent_Declare(Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG v3.5.2
SYSTEM)
FetchContent_MakeAvailable(xoshiro Catch2)
else()
# Unix & macOS
FetchContent_MakeAvailable(xoshiro)
# Provides location to search for Catch2 installation from source build
# build via:
# git clone https://github.com/catchorg/Catch2.git
# mkdir build && cd build
# cmake .. -DBUILD_TESTING=Off
# make && sudo make install
# Need to figure out how to get this working on Windows as well!
list(APPEND CMAKE_PREFIX_PATH
"/usr/local/lib64/cmake" # Linux
"/usr/local/lib/cmake" # macOS
"C:/Program Files (x86)/Catch2" # Windows
)
find_package(Catch2 3 CONFIG REQUIRED)
endif()
# Include Xoshiro since it doesn't have a CMakeLists.txt
include_directories(SYSTEM ${xoshiro_SOURCE_DIR})
#==============================================================================
# sac-format
#==============================================================================
project(sac-format
LANGUAGES CXX
DESCRIPTION "C++20 Single-Header SAC File library"
HOMEPAGE_URL https://arbCoding.github.io/sac-format
VERSION 0.6.0)
include_directories(${sac-format_SOURCE_DIR}/include)
add_library(sac-format STATIC
src/sac_format.cpp)
set_target_properties(sac-format PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(sac-format PROPERTIES PUBLIC_HEADER
include/sac-format/sac_format.hpp)
#===============================================================================
# Example programs
#===============================================================================
add_executable(list_sac src/examples/list_sac.cpp)
target_link_libraries(list_sac sac-format)
#===============================================================================
# Benchmarks
#===============================================================================
add_executable(benchmark src/benchmark.cpp)
target_link_libraries(benchmark
PRIVATE Catch2::Catch2WithMain
sac-format)
#===============================================================================
# Unit tests
#===============================================================================
set(basic_sources
src/tests/binary_conversions.cpp
src/tests/constants.cpp)
add_executable(basic_tests ${basic_sources})
target_link_libraries(basic_tests
PRIVATE Catch2::Catch2WithMain
sac-format)
add_executable(trace_tests
src/tests/trace.cpp)
target_link_libraries(trace_tests
PRIVATE Catch2::Catch2WithMain
sac-format)
add_executable(geometry_tests
src/tests/geometry.cpp)
target_link_libraries(geometry_tests
PRIVATE Catch2::Catch2WithMain
sac-format
)
add_executable(datetime_tests
src/tests/datetime.cpp)
target_link_libraries(datetime_tests
PRIVATE Catch2::Catch2WithMain
sac-format
)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
include(CTest)
include(Catch)
catch_discover_tests(basic_tests)
catch_discover_tests(trace_tests)
catch_discover_tests(geometry_tests)
catch_discover_tests(datetime_tests)
#===============================================================================
# Release preparation
#===============================================================================
if (UNIX AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
set(Exes basic_tests trace_tests benchmark list_sac)
foreach(program ${Exes})
message(STATUS "\n ${program} will be stripped to reduce filesize.\n")
add_custom_command(TARGET ${program}
COMMAND strip "$<TARGET_FILE:${program}>"
VERBATIM)
endforeach()
endif()
#===============================================================================
# CPack Installation
#===============================================================================
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
# Archive filename
set(CPACK_ARCHIVE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-\
${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
if(CPACK_GENERATOR MATCHES "productbuild")
# macOS
set(CPACK_RESOURCE_FILE_README
${sac-format_SOURCE_DIR}/installers/macOS/Readme.txt)
set(CPACK_RESOURCE_FILE_WELCOME
${sac-format_SOURCE_DIR}/installers/macOS/Welcome.txt)
install(FILES ${sac-format_SOURCE_DIR}/License.txt DESTINATION .
COMPONENT license)
set(CPACK_RESOURCE_FILE_LICENSE ${sac-format_SOURCE_DIR}/License2.txt)
set(CPACK_SET_DESTDIR "ON")
else()
# Windows/Linux
install(FILES ${sac-format_SOURCE_DIR}/LICENSE DESTINATION .
COMPONENT license)
set(CPACK_RESOURCE_FILE_LICENSE ${sac-format_SOURCE_DIR}/LICENSE)
endif()
# For some reason, order seems to matter more than it should...
include(CPack)
# Setup components
install(TARGETS sac-format COMPONENT library)
install(TARGETS basic_tests trace_tests geometry_tests datetime_tests
RUNTIME DESTINATION bin/tests COMPONENT tests)
install(TARGETS benchmark RUNTIME DESTINATION bin/tests COMPONENT benchmarks)
install(TARGETS list_sac RUNTIME DESTINATION bin COMPONENT list_sac)
# Only specified components (exclude catch2)
set(CPACK_COMPONENTS_ALL library tests benchmarks list_sac license)
# Group components
cpack_add_component(library DISPLAY_NAME "sac-format" GROUP development
DESCRIPTION "sac-format library to use in your own programs.")
cpack_add_component(tests DISPLAY_NAME "Unit/Integration Testing" GROUP misc
DESCRIPTION "Collection of command line unit and integration \
tests that ensure sac-format is working correctly.")
cpack_add_component(benchmarks DISPLAY_NAME "Benchmarks" GROUP misc
DESCRIPTION "benchmarks.exe - Collection of command line benchmarks for \
determining sac-format performance.")
cpack_add_component(list_sac DISPLAY_NAME "list_sac" GROUP programs
DESCRIPTION "list_sac.exe - Example command line program that lists all \
header information from an input SAC file.")
cpack_add_component(license DISPLAY_NAME "license"
DESCRIPTION "sac-format license file.")