forked from therion/therion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
170 lines (148 loc) · 5.75 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
cmake_minimum_required(VERSION 3.10)
include(cmake/PreventInSourceBuilds.cmake)
project(Therion)
set(CMAKE_CXX_STANDARD 14)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
option(BUILD_THERION "Build therion executable." ON)
option(BUILD_LOCH "Build loch executable." ON)
option(BUILD_THBOOK "Build thbook.pdf." ON)
option(BUILD_XTHERION "Build xtherion." ON)
include(cmake/BuildType.cmake)
include(cmake/Dependencies.cmake)
include(cmake/TherionSources.cmake)
include(cmake/ECMEnableSanitizers.cmake)
# strip binaries in release build
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s")
set(ECM_ENABLE_SANITIZERS "" CACHE STRING
"Enable runtime sanitizers, available options: address,memory,thread,leak,undefined." )
set(ENABLE_THDEBUG OFF CACHE BOOL "Print debug information.")
option(ENABLE_CLANG_TIDY "Enable static analysis with clang-tidy." OFF)
if (ENABLE_CLANG_TIDY)
find_program(CLANG_TIDY_EXECUTABLE clang-tidy)
if (CLANG_TIDY_EXECUTABLE)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE};--quiet")
endif()
endif()
option(ENABLE_CCACHE "Enable compiler cache." OFF)
if (ENABLE_CCACHE)
find_program(CCACHE_EXECUTABLE ccache)
mark_as_advanced(CCACHE_EXECUTABLE)
if(CCACHE_EXECUTABLE)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_EXECUTABLE})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_EXECUTABLE})
endif()
endif()
# determine platform
if(UNIX AND NOT APPLE)
set(THPLATFORM LINUX)
elseif(APPLE)
set(THPLATFORM MACOSX)
else()
set(THPLATFORM WIN32)
endif()
# tell CMake which files must be generated now, doing so in subfolders is too late
set_source_files_properties(
${CMAKE_BINARY_DIR}/thchencdata.h
${CMAKE_BINARY_DIR}/thchencdata.cxx
${CMAKE_BINARY_DIR}/thlangdata.h
${CMAKE_BINARY_DIR}/thlangdatafields.h
${CMAKE_BINARY_DIR}/thmpost.h
${CMAKE_BINARY_DIR}/thmpost.cxx
${CMAKE_BINARY_DIR}/thsymbolsets.h
${CMAKE_BINARY_DIR}/thsymbolsets.cxx
${CMAKE_BINARY_DIR}/thversion.h
${CMAKE_BINARY_DIR}/thcsdata.h
${CMAKE_BINARY_DIR}/thcsdata.cxx
${CMAKE_BINARY_DIR}/thsymbolsetlist.h
${CMAKE_BINARY_DIR}/thtex.h
${CMAKE_BINARY_DIR}/thtex.cxx
PROPERTIES GENERATED TRUE
)
# copy given files to the build dir
function(therion_copy_files)
foreach(FILE_NAME ${ARGV})
configure_file(${FILE_NAME} ${FILE_NAME} COPYONLY)
endforeach()
endfunction()
# make lists of names with source and binary dir prefixes
macro(therion_make_files_lists LIST_NAME)
foreach(FILE_NAME ${ARGN})
list(APPEND ${LIST_NAME}_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${FILE_NAME})
list(APPEND ${LIST_NAME}_BIN ${CMAKE_CURRENT_BINARY_DIR}/${FILE_NAME})
endforeach()
endmacro()
# copy files needed by some build steps
therion_copy_files(thcsdata.tcl thsymbolsetfont.txt .clang-tidy)
# generate thcsdata sources
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/thcsdata.h
${CMAKE_BINARY_DIR}/thcsdata.cxx
COMMAND tclsh thcsdata.tcl ${PROJ_PREFIX}/share/proj
DEPENDS ${CMAKE_BINARY_DIR}/thcsdata.tcl
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_target(generate_thcsdata DEPENDS
${CMAKE_BINARY_DIR}/thcsdata.h
${CMAKE_BINARY_DIR}/thcsdata.cxx
)
# generate thsymbolsetlist sources
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/thsymbolsetlist.h
COMMAND perl
ARGS ${CMAKE_SOURCE_DIR}/thsymbolsetlist.pl
DEPENDS ${CMAKE_SOURCE_DIR}/thsymbolsetlist.pl
${CMAKE_BINARY_DIR}/mpost/thTrans.mp
${CMAKE_BINARY_DIR}/thsymbolsetfont.txt
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_target(generate_thsymbolsetlist DEPENDS ${CMAKE_BINARY_DIR}/thsymbolsetlist.h)
# generate version files
add_custom_target(version python3 set_version.py ${CMAKE_BINARY_DIR}
COMMENT "Updating version"
BYPRODUCTS ${CMAKE_BINARY_DIR}/thversion.h
${CMAKE_BINARY_DIR}/thbook/version.tex
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
# generate InnoSetup config file
if (WIN32)
configure_file(innosetup.ini.in innosetup.ini)
endif()
if (BUILD_THERION)
# therion lib
add_library(therion-common STATIC ${THERION_HEADERS} ${THERION_SOURCES})
target_include_directories(therion-common BEFORE PUBLIC "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/extern")
target_link_libraries(therion-common PUBLIC PkgConfig::PROJ fmt::fmt shp poly2tri common-utils)
target_compile_definitions(therion-common PUBLIC PROJ_VER=${PROJ_MVER} "TH${THPLATFORM}" $<$<BOOL:${ENABLE_THDEBUG}>:THDEBUG>)
add_dependencies(therion-common
version
generate_thsymbolsetlist
generate_thlang
generate_tex
generate_mpost
generate_thchencdata
generate_thcsdata
)
# therion executable
add_executable(therion therion-main.cxx)
target_link_libraries(therion PUBLIC therion-common)
install(TARGETS therion RUNTIME DESTINATION bin)
# unit tests
add_executable(utest utest-proj.cxx utest-icase.cxx utest-thdouble.cxx utest-main.cxx)
target_link_libraries(utest PUBLIC therion-common Catch2::Catch2)
enable_testing()
if (NOT WIN32)
add_test(NAME utest COMMAND $<TARGET_FILE:utest> WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
# updates thlibrarydata.cxx
add_custom_target(library
${CMAKE_COMMAND} -D THERION=$<TARGET_FILE:therion> -P cmake/Library.cmake
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_subdirectory(extern/poly2tri)
add_subdirectory(mpost)
add_subdirectory(thchencdata)
add_subdirectory(tex)
add_subdirectory(thlang)
add_subdirectory(samples)
endif()
add_subdirectory(loch)
add_subdirectory(thbook)
add_subdirectory(xtherion)