-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
337 lines (290 loc) · 9.62 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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#######################################################
## General
#######################################################
cmake_minimum_required(VERSION 3.15)
project(Comp3D)
set(COMP3D_TARGET Comp3D)
set(TRANSLATIONS fr)
# strict C++17 required
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)
#######################################################
## Options
#######################################################
option(ADD_PROJ_CC "Add proj CC" ON)
option(ADD_PROJ_NTF "Add proj NTF" ON)
option(ADD_PROJ_UTM "Add Proj UTM" OFF)
option(USE_AUTO "Automatic mode" ON)
option(USE_GUI "GUI" ON)
if (NOT ${USE_GUI})
option(USE_RES "ressources" ON)
else()
set(USE_RES ON CACHE BOOL "ressources" FORCE)
endif()
if (NOT ${USE_RES})
option(USE_QT "QT" ON)
else()
set(USE_QT ON CACHE BOOL "QT" FORCE)
endif()
set(COMP3D_DOC_DIR "${CMAKE_SOURCE_DIR}/doc_uni" CACHE STRING "Path to doc")
if ("${COMP3D_DOC_DIR}" STREQUAL "")
set(COMP3D_DOC_DIR "${CMAKE_SOURCE_DIR}/doc_uni" CACHE STRING "Path to doc" FORCE)
endif()
set(PROJ_DATA_LOCAL_PATH "" CACHE STRING "Path to proj data")
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
# build type. Default: Release
if(NOT is_multi_config)
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE)
message(NOTICE "-- Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build, options are: Release RelWithDebInfo Debug" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Release RelWithDebInfo Debug)
endif()
endif()
#######################################################
## Dependencies
#######################################################
# Eigen
find_package(Eigen3 REQUIRED NO_MODULE)
# Boost
set (BOOST_VERSION_MIN 1.60.0)
set (BOOST_COMPONENTS system date_time graph)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9")
list(APPEND BOOST_COMPONENTS filesystem)
endif()
set (BOOST_COMPONENTS_FULL ${BOOST_COMPONENTS})
list (TRANSFORM BOOST_COMPONENTS_FULL PREPEND Boost::)
find_package(Boost ${BOOST_VERSION_MIN} REQUIRED COMPONENTS ${BOOST_COMPONENTS})
# Proj
find_package(PROJ QUIET)
if (NOT PROJ_FOUND)
# needed on Ubuntu
find_package(PkgConfig)
pkg_search_module(PROJ REQUIRED proj)
endif()
if (PROJ_FOUND)
message(STATUS "PROJ ${PROJ_VERSION} FOUND: ${PROJ_BINARY_DIRS}")
endif()
if (CMAKE_HOST_WIN32)
find_file(PROJ_PROJ_DB_FILE proj.db PATHS ${PROJ_DIR} ${PROJ_BINARY_DIRS}/../share/proj NO_DEFAULT_PATH)
file(COPY ${PROJ_PROJ_DB_FILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/proj)
endif()
# Qt
set (QT_COMPONENTS Widgets)
set (QT_COMPONENTS_FULL ${QT_COMPONENTS})
list (TRANSFORM QT_COMPONENTS_FULL PREPEND Qt5::)
find_package(Qt5 REQUIRED COMPONENTS ${QT_COMPONENTS} LinguistTools)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
# Windows: install PROJ grids
if (CMAKE_HOST_WIN32)
include(FetchContent)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 OLD)
endif()
FetchContent_Declare(
proj-data
URL https://download.osgeo.org/proj/proj-datumgrid-1.8.zip
)
FetchContent_MakeAvailable(proj-data)
file(COPY ${proj-data_SOURCE_DIR}/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/proj)
endif()
#######################################################
## Compilation toolchain
#######################################################
# ccache
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
endif(CCACHE_FOUND)
# compilers specific options : warnings, MSVC specific defines
set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>")
set(gnu_cxx "$<COMPILE_LANG_AND_ID:CXX,GNU>")
add_library(COMP3D_compiler_flags INTERFACE)
target_compile_options(COMP3D_compiler_flags INTERFACE
"$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Wall;-Werror>>"
"$<${msvc_cxx}:$<BUILD_INTERFACE:/W3;/D_USE_MATH_DEFINES;/D_HAS_STD_BYTE=0;/wd4244;/wd4267;/wd4305;/wd4661;/D_CRT_SECURE_NO_WARNINGS>>"
"$<$<CONFIG:Debug>:$<$<CXX_COMPILER_ID:MSVC>:/bigobj>>"
"$<$<CONFIG:RelWithDebInfo>:$<$<CXX_COMPILER_ID:MSVC>:/bigobj>>"
)
# we really want -O3 instead of -O2 when available (GNU, Clang) in RelWithDebInfo mode
string(REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
#######################################################
## Versionning
#######################################################
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/version.cmake)
#######################################################
## Configuration
#######################################################
configure_file (
"${PROJECT_SOURCE_DIR}/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
#######################################################
## Sources
#######################################################
set(SOURCES
main.cpp
lib_ex.cpp
src/fformat.cpp
src/filerefjson.cpp
src/leastsquares.cpp
src/misc_tools.cpp
src/obs.cpp
src/point.cpp
src/coord.cpp
src/projection.cpp
src/station.cpp
src/station_eq.cpp
src/station_simple.cpp
src/parameter.cpp
src/project.cpp
src/mathtools.cpp
src/station_hz.cpp
src/jsoncpp.cpp
src/project_config.cpp
src/datafile.cpp
src/ellipsoid.cpp
src/station_axis.cpp
src/axisobs.cpp
src/station_bascule.cpp
src/matrixordering.cpp
src/info.cpp
src/varcovarmatrix.cpp
)
set(SOURCES_GUI
gui/customtablewidgetitem.cpp
gui/exportcoorddialog.cpp
gui/infinityasctobasdialog.cpp
gui/sinexdialog.cpp
gui/maintables.cpp
gui/mainwindow.cpp
gui/calcthread.cpp
gui/configdialog.cpp
gui/errordialog.cpp
gui/applytransfodialog.cpp
gui/sightmatrixdialog.cpp
gui/conversiondialog.cpp
gui/dialogpreferences.cpp
gui/framewidget.cpp
gui/multisorttable.cpp
gui/exportpointsdialog.cpp
)
set(HEADERS
src/info.h
src/fformat.h
src/filerefjson.h
src/leastsquares.h
src/misc_tools.h
src/obs.h
src/point.h
src/coord.h
src/projection.h
src/station.h
src/station_eq.h
src/station_simple.h
src/parameter.h
src/project.h
src/mathtools.h
src/station_hz.h
src/json/json-forwards.h
src/json/json.h
src/compile.h
src/project_config.h
src/datafile.h
src/ellipsoid.h
src/station_axis.h
src/axisobs.h
src/station_bascule.h
src/matrixordering.h
src/uni_stream.h
src/varcovarmatrix.h
src/filesystem_compat.h
gui/customtablewidgetitem.h
gui/exportcoorddialog.h
gui/infinityasctobasdialog.h
gui/sinexdialog.h
gui/maintables.h
gui/mainwindow.h
gui/calcthread.h
gui/configdialog.h
gui/errordialog.h
gui/applytransfodialog.h
gui/sightmatrixdialog.h
gui/conversiondialog.h
gui/dialogpreferences.h
gui/framewidget.h
gui/multisorttable.h
gui/exportpointsdialog.h
)
set(UI_FILES
gui/applytransfodialog.ui
gui/configdialog.ui
gui/conversiondialog.ui
gui/dialogpreferences.ui
gui/errordialog.ui
gui/exportcoorddialog.ui
gui/exportpointsdialog.ui
gui/framewidget.ui
gui/infinityasctobasdialog.ui
gui/maintables.ui
gui/mainwindow.ui
gui/sightmatrixdialog.ui
gui/sinexdialog.ui
)
set (ALL_SOURCES ${SOURCES} ${SOURCES_GUI} ${HEADERS} ${UI_FILES})
#######################################################
## Translation
#######################################################
list (TRANSFORM TRANSLATIONS PREPEND "Comp3D_")
set(TS_FILES ${TRANSLATIONS})
list (TRANSFORM TS_FILES PREPEND "gui/translations/")
list (TRANSFORM TS_FILES APPEND ".ts")
set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/i18n")
qt5_add_translation(QM_FILES ${TS_FILES})
set (QM_FILES_QRC ${TRANSLATIONS})
list (TRANSFORM QM_FILES_QRC PREPEND "<file>i18n/")
list (TRANSFORM QM_FILES_QRC APPEND ".qm</file>\n")
SET(WITHOUT_SEMICOLON "")
FOREACH(file ${QM_FILES_QRC})
SET(WITHOUT_SEMICOLON "${WITHOUT_SEMICOLON}${file}")
ENDFOREACH(file)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cmake_qm.qrc"
"
<RCC>
<qresource>
${WITHOUT_SEMICOLON}
</qresource>
</RCC>
")
add_custom_target(lupdate
COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${ALL_SOURCES} -ts ${TS_FILES}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Updating translations"
)
#######################################################
## Target
#######################################################
add_executable(${COMP3D_TARGET}
${ALL_SOURCES}
comp3d.rc ressource.qrc ${CMAKE_BINARY_DIR}/cmake_qm.qrc ${CMAKE_BINARY_DIR}/git_revision.cpp
)
set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE $<CONFIG:Release>)
target_include_directories (${COMP3D_TARGET} PRIVATE src gui . ${PROJECT_BINARY_DIR} ${PROJ_INCLUDE_DIRS})
target_link_libraries (${COMP3D_TARGET} PRIVATE COMP3D_compiler_flags ${BOOST_COMPONENTS_FULL} ${QT_COMPONENTS_FULL} ${PROJ_LIBRARIES} Eigen3::Eigen)
#######################################################
## Install
#######################################################
set(PROJLIB_PATH "/usr/lib/")
set(PROJLIB_FILE "${PROJ_LIBRARY_DIRS}/libproj.a")
set(TARGET_PATH "/usr/bin/")
set(INSTALL_PREFIX "" CACHE PATH "Path prefix for installation")
install(FILES ${PROJLIB_FILE} DESTINATION ${INSTALL_PREFIX}/${PROJLIB_PATH})
install(TARGETS ${COMP3D_TARGET} DESTINATION ${INSTALL_PREFIX}/${TARGET_PATH})