-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
237 lines (187 loc) · 8.85 KB
/
CMakeLists.txt
File metadata and controls
237 lines (187 loc) · 8.85 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
235
236
237
cmake_minimum_required(VERSION 3.30...4.2)
project(incplot
HOMEPAGE_URL "https://github.com/InCom-0/incplot"
VERSION "1.0.2"
DESCRIPTION
"CLI tool for drawing great looking plots in the terminal focused on user ergonomics and simplicity."
LANGUAGES CXX)
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(CPM_USE_LOCAL_PACKAGES "Use local (usually system installed) packages for dependencies." ON)
option(CPM_LOCAL_PACKAGES_ONLY "Forbid the build system from downloading missing dependencies." OFF)
option(incplot_STAGE_OUTPUTS "Stage build output artifacts into proper directory structure" ON)
option(incplot_PORTABLE_LAYOUT "Use flat (Windows-like / portable) install layout" OFF)
option(incplot_CPR_USE_SYSTEM_CURL "Incplot transitively needs libcurl. Set to ON if you have and want to use system installed one" OFF)
#####################################################################
### Staging and Install dirs setting ###
#####################################################################
include(cmake/incom/StageOutputs.cmake)
include(cmake/incom/MingwRuntimeDeps.cmake)
include(GNUInstallDirs)
set(incplot_PORTABLE_LAYOUT_INSTALL_DIR "/" CACHE PATH "Dir under prefix to install to in portable layout mode")
if(incplot_STAGE_OUTPUTS)
stageOutputDirs(${PROJECT_NAME} ${incplot_PORTABLE_LAYOUT})
endif()
#####################################################################
### Platform specifics + hacks + LTO ###
#####################################################################
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
add_compile_options(/utf-8)
add_compile_definitions(NOMINMAX)
endif()
### This attempts to compile sample program to find out if we are using libc++(USING_LIBCXX) or libstdc++(USING_LIBSTDCXX) or MSVC_STL(USING_MSVC_STL)
include(cmake/incom/StdlibQuery.cmake)
include(CheckIPOSupported)
check_ipo_supported(RESULT INCPLOT_LTO OUTPUT INCPLOT_LTO_OUTPUT)
# Enable LTO if supported and only when NOT in debug mode
if(INCPLOT_LTO)
message(STATUS "LTO is supported")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
message(STATUS "LTO is disabled because of Debug build")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
message(STATUS "LTO is disabled on MacOS")
else()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
message(STATUS "LTO is enabled")
# set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
else()
message(WARNING "LTO is NOT supported: ${INCPLOT_LTO_OUTPUT}")
endif()
######################################################################
### Target specification ###
######################################################################
add_executable(incplot)
target_sources(incplot PRIVATE src/main.cpp src/config.cpp src/args.cpp)
target_sources(incplot
PRIVATE
FILE_SET priv_headers
TYPE HEADERS
BASE_DIRS
include)
set(INCPLOT_GENERATED_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
include(cmake/config/configScript.cmake)
target_sources(incplot
PRIVATE
FILE_SET priv_auto_config
TYPE HEADERS
BASE_DIRS
"${INCPLOT_GENERATED_CONFIG_DIR}")
target_compile_features(incplot PRIVATE cxx_std_23)
# TODO: Need to finish the script that drives this
# if(MINGW)
# add_mingw_runtime_deps(incplot)
# endif(MINGW)
##########################################################################
### Settings the right options for linking for Windows and Apple ###
##########################################################################
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(BUILD_SHARED_LIBS OFF)
if(USING_LIBSTDCXX)
target_link_options(incplot PUBLIC -static)
elseif(USING_LIBCXX)
target_link_options(incplot PUBLIC -stdlib=libc++ -static)
elseif(USING_MSVC_STL)
endif()
elseif(APPLE)
if(USING_LIBSTDCXX)
target_link_options(incplot PUBLIC -static)
elseif(USING_LIBCXX)
target_link_options(incplot PUBLIC -stdlib=libc++)
elseif(USING_MSVC_STL)
message(FATAL_ERROR "CMake reports we are using MSVC STL on APPLE platform. That is impossible.")
endif()
else()
endif()
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
endif()
##########################################################################
### Dependencies and library linking ###
##########################################################################
include(CMake_dependencies.cmake) ### Loads and declares the required external libraries using CPM or CMake's FetchContent.
target_link_libraries(incplot PRIVATE incplot-lib::incplot-lib incfontdisc::incfontdisc)
target_link_libraries(incplot PRIVATE sqlpp23::sqlpp23 sqlpp23::sqlite3)
target_link_libraries(incplot PRIVATE argparse::argparse cpr::cpr indicators::indicators)
target_link_libraries(incplot PRIVATE LibArchive::LibArchive)
target_link_libraries(incplot PRIVATE ots::ots)
if(USING_LIBSTDCXX)
target_link_libraries(incplot PRIVATE "-lstdc++exp")
endif()
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(incplot PRIVATE LIBARCHIVE_STATIC)
endif()
# TODO: Figure out how to silence that warning on MinGW ... does not work like it is below
# if(SQLite3_ADDED)
# set(sqlite3c_FILE "${CMAKE_BINARY_DIR}/_deps/sqlite3_ext-src/sqlite3.c")
# set_source_files_properties(
# ${sqlite3c_FILE}
# PROPERTIES
# COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wno-stringop-overread>"
# )
# unset(sqlite3c_FILE)
# endif()
############################################################################################
### Automatic copying certain assets to build directory (mimic structure as installed) ###
############################################################################################
if(incplot_PORTABLE_LAYOUT)
add_custom_command(TARGET incplot POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Recreating portable installation file structure in build staging directory"
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
"${CMAKE_SOURCE_DIR}/data/"
"${${PROJECT_NAME}_STAGEDIR}/${incplot_PORTABLE_LAYOUT_INSTALL_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/README.md"
"${${PROJECT_NAME}_STAGEDIR}/${incplot_PORTABLE_LAYOUT_INSTALL_DIR}/README.md"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/LICENSE.txt"
"${${PROJECT_NAME}_STAGEDIR}/${incplot_PORTABLE_LAYOUT_INSTALL_DIR}/LICENSE.txt"
)
else()
### '.incplot-dev-build' gets created next to the binary in 'CMAKE_RUNTIME_OUTPUT_DIRECTORY'
### The above enables running incplot from inside build directory (without installing it)
add_custom_command(TARGET incplot POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Recreating GNUInstallDirs installation file structure in build staging directory"
COMMAND ${CMAKE_COMMAND} -E touch "$<TARGET_FILE_DIR:incplot>/.incplot-dev-build"
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
"${CMAKE_SOURCE_DIR}/data/"
"${${PROJECT_NAME}_STAGEDIR}/${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/README.md"
"${${PROJECT_NAME}_STAGEDIR}/${CMAKE_INSTALL_DOCDIR}/README.md"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/LICENSE.txt"
"${${PROJECT_NAME}_STAGEDIR}/${CMAKE_INSTALL_DATAROOTDIR}/licenses/${PROJECT_NAME}/LICENSE.txt"
)
endif()
########################################################
### Install specification ###
########################################################
if(incplot_PORTABLE_LAYOUT)
install(TARGETS incplot
RUNTIME DESTINATION ${incplot_PORTABLE_LAYOUT_INSTALL_DIR}
)
install(FILES $<TARGET_RUNTIME_DLLS:incplot>
DESTINATION ${incplot_PORTABLE_LAYOUT_INSTALL_DIR}
OPTIONAL
)
install(FILES data/configDB.seed.sqlite DESTINATION "${incplot_PORTABLE_LAYOUT_INSTALL_DIR}")
install(FILES README.md DESTINATION ${incplot_PORTABLE_LAYOUT_INSTALL_DIR})
install(FILES LICENSE.txt DESTINATION "${incplot_PORTABLE_LAYOUT_INSTALL_DIR}")
else()
install(TARGETS incplot
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(FILES $<TARGET_RUNTIME_DLLS:incplot>
DESTINATION ${CMAKE_INSTALL_BINDIR}
OPTIONAL
)
install(FILES data/configDB.seed.sqlite DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/")
install(FILES README.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
install(FILES LICENSE.txt DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${PROJECT_NAME}/")
endif()
if(PROJECT_IS_TOP_LEVEL)
add_subdirectory(cmake/packaging)
endif()