forked from tomasmark79/MassCode2Md
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
178 lines (135 loc) · 4.97 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
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
# ---- (c) Tomáš Mark 2024 ----
# ---- Project Library namespace::name ----
set(PROJECT_LIBRARY_NAMESPACE dsdotname)
set(PROJECT_LIBRARY_NAME MassCode2Md) # for change use ./TemplateRenamer.sh
# ---- Generate Static/Shared targets (used by Conan as well) ----
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
# ---- Project ----
project(
${PROJECT_LIBRARY_NAME}
VERSION 0.0.2
LANGUAGES C CXX ASM)
# ---- Include guards ----
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(
FATAL_ERROR
"In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there."
)
endif()
# ---- CPMs ----
include(cmake/CPM.cmake)
cpmaddpackage("gh:TheLartians/[email protected]")
cpmaddpackage("gh:fmtlib/fmt#11.0.2")
cpmaddpackage("gh:cpm-cmake/[email protected]")
cpmaddpackage("gh:nlohmann/[email protected]")
if(CPMLicenses.cmake_ADDED)
cpm_licenses_create_disclaimer_target(
write-licenses-${PROJECT_LIBRARY_NAME}
"${CMAKE_CURRENT_BINARY_DIR}/third_party.txt" "${CPM_PACKAGES}")
endif()
# ---- CMake Modules ----
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${PROJECT_SOURCE_DIR}/cmake/Modules")
# find_package(Threads REQUIRED)
# find_package(X11 REQUIRED)
# ---- Conan ----
# find_package(dpp CONFIG REQUIRED) # CONFIG means find_package require
# dpp-config.cmake file
# find_package(BZip2 REQUIRED)
# find_package(CURL REQUIRED)
# Glob not recommended, but the simplest way for this template
file(
GLOB_RECURSE
headers
CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/include/*.h
${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/*.hh
${CMAKE_CURRENT_SOURCE_DIR}/include/*.hxx)
# Glob not recommended, but the simplest way for this template
file(
GLOB_RECURSE
sources
CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/Source/*.c
${CMAKE_CURRENT_SOURCE_DIR}/Source/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Source/*.cc
${CMAKE_CURRENT_SOURCE_DIR}/Source/*.cxx)
# ---- Create library ----
add_library(${PROJECT_LIBRARY_NAME} ${headers} ${sources})
# ---- Library features ----
target_compile_features(${PROJECT_LIBRARY_NAME} PUBLIC cxx_std_17)
# ---- Library options
target_compile_options(${PROJECT_LIBRARY_NAME} PUBLIC "-Wno-c++20-compat")
# "-Wall" "-Wextra" "-Wpedantic")
# header-only libraries change all PUBLIC flags to INTERFACE and create an
# interface target: <add_library(${PROJECT_LIBRARY_NAME} INTERFACE)>
target_include_directories(
${PROJECT_LIBRARY_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_LIBRARY_NAME}-${PROJECT_VERSION}>
# PRIVATE ${PROJECT_SOURCE_DIR}/Source
PRIVATE ${nlohmann_json_SOURCE_DIR}/include
)
# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(
${PROJECT_LIBRARY_NAME}
PUBLIC "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->" # Strict
# conformance
)
# ---- Link libraries ----
target_link_libraries(
${PROJECT_LIBRARY_NAME} PRIVATE fmt::fmt)
# ---- Packaging ----
string(TOLOWER "${PROJECT_LIBRARY_NAME}" PROJECT_LIBRARY_NAME_LOWER)
packageproject(
# the name of the target to export
NAME
${PROJECT_LIBRARY_NAME}
# the version of the target to export
VERSION
${PROJECT_VERSION}
# a temporary directory to create the config files
BINARY_DIR
${PROJECT_BINARY_DIR}
# location of the target's public headers
INCLUDE_DIR
${PROJECT_SOURCE_DIR}/include
# should match the target's INSTALL_INTERFACE include directory
INCLUDE_DESTINATION
include/${PROJECT_LIBRARY_NAME}-${PROJECT_VERSION}
# (optional) option to install only header files with matching pattern
INCLUDE_HEADER_PATTERN
"*.h"
# semicolon separated list of the project's dependencies
DEPENDENCIES
"fmt#11.0.2;[email protected]"
# (optional) create a header containing the version info Note: that the path
# to headers should be lowercase
VERSION_HEADER
"${PROJECT_LIBRARY_NAME_LOWER}/version.h"
# (optional) create a export header using GenerateExportHeader module
EXPORT_HEADER
"${PROJECT_LIBRARY_NAME_LOWER}/export.h"
# (optional) install your library with a namespace (Note: do NOT add extra
# '::')
NAMESPACE
${PROJECT_LIBRARY_NAMESPACE}
# (optional) define the project's version compatibility, defaults to
# `AnyNewerVersion` supported values:
# `AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion`
COMPATIBILITY
AnyNewerVersion
# (optional) option to disable the versioning of install destinations
DISABLE_VERSION_SUFFIX
YES
# (optional) option to ignore target architecture for package resolution
# defaults to YES for header only (i.e. INTERFACE) libraries
ARCH_INDEPENDENT
YES
# (optional) option to generate CPack variables
CPACK
YES)
# ---- Install ---- TODO