-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
160 lines (135 loc) · 4.33 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
cmake_minimum_required (VERSION 3.25)
project(gempyre LANGUAGES CXX)
# enable ctests, starting from the top build folder
include(CTest)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
set(GEMPYRE_IS_MAIN_PROJECT TRUE)
else()
set(GEMPYRE_IS_MAIN_PROJECT FALSE)
endif()
string(TOLOWER ${CMAKE_BUILD_TYPE} LOWER)
if (${LOWER} STREQUAL debug)
set(IS_RELEASE FALSE)
add_compile_definitions(GEMPYRE_IS_DEBUG)
else()
set(IS_RELEASE TRUE)
endif()
if(NOT EXISTS ${GEMPYRE_DIR})
if(EXISTS $ENV{GEMPYRE_DIR})
set(GEMPYRE_DIR $ENV{GEMPYRE_DIR})
else()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/scripts)
set(GEMPYRE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
else()
message(FATAL_ERROR "GEMPYRE_DIR is not set neither GEMPYRE_DIR Environment variable is not pointing to Gempyre dir")
endif()
endif()
endif()
# NOTE: lib UV is linking only MD, therefore Gempyre to be linked MD, and thus MT wont work here either, sigh
# maybe use Fetch command instead of Externalproject add and then override flags
if(WIN32)
add_compile_definitions(WINDOWS_OS)
add_compile_options(-D_WIN32)
add_compile_options(-DWINDOWS_OS)
add_compile_options(-DLIBUS_NO_SSL)
add_compile_options(-DNOMINMAX)
set(CMAKE_DEBUG_POSTFIX d)
set(CMAKE_RELWITHDEBINFO_POSTFIX rd)
set(CMAKE_MINSIZEREL_POSTFIX rs)
else()
add_compile_options(-Wall -Wextra)
endif()
if(APPLE)
add_compile_definitions(MAC_OS)
if (NOT DEFINED NATIVE_ARCHITECURE)
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "Universal binary" FORCE)
endif()
elseif(RASPBERRY)
add_compile_definitions(UNIX_OS DRASPBERRY_OS)
add_compile_options(-Wno-psabi)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_compile_options(-fPIC)
elseif(ANDROID)
add_compile_definitions(ANDROID_OS)
elseif(UNIX)
add_compile_definitions(UNIX_OS)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_compile_options(-fPIC)
endif()
set(USE_DEFAULT_SUBPROJECTS ${GEMPYRE_IS_MAIN_PROJECT})
set(USE_DEFAULT_PYTHON ON)
if(EMSCRIPTEN)
message("Target is Emscripten")
add_compile_definitions(WASM)
set(USE_DEFAULT_SUBPROJECTS OFF)
set(USE_DEFAULT_PYTHON OFF)
else()
option(USE_LIBWEBSOCKETS "Use libwebsocket as default" ON) # change default websocket from uwebsocket
endif()
option(CI_ACTIONS "Github Actions build" OFF)
if(CI_ACTIONS)
add_compile_options(-DCI_ACTIONS)
message(WARNING "This is for Github actions")
endif()
if(CI_ACTIONS)
set(HAS_PROGRESS FALSE)
else()
set(HAS_PROGRESS TRUE)
endif()
if(SANITIZER)
set(ASAN_FLAGS
-fsanitize=address
-fsanitize=pointer-compare
-fsanitize=pointer-subtract
-fsanitize=leak
-fsanitize=undefined
-fsanitize=shift
-fsanitize=shift-exponent
-fsanitize=shift-base
-fsanitize=integer-divide-by-zero
-fsanitize=unreachable
-fsanitize=vla-bound
-fsanitize=null
-fsanitize=return
-fsanitize=signed-integer-overflow
-fsanitize=bounds
-fsanitize=bounds-strict
-fsanitize=alignment
-fsanitize=object-size
-fsanitize=float-divide-by-zero
-fsanitize=float-cast-overflow
-fsanitize=nonnull-attribute
-fsanitize=returns-nonnull-attribute
-fsanitize=bool
-fsanitize=enum
-fsanitize=vptr
-fsanitize=pointer-overflow
-fsanitize=builtin)
add_compile_options(${ASAN_FLAGS})
add_link_options(${ASAN_FLAGS})
endif()
if(SANITIZER_THREAD)
if(SANITIZER)
message(FATAL_ERROR "SANITIZER_THREAD cannot co exists with SANITIZER flag!")
endif()
set(ASAN_FLAGS -fsanitize=thread)
add_compile_options(${ASAN_FLAGS})
add_link_options(${ASAN_FLAGS})
endif()
add_subdirectory(gempyrelib)
option(HAS_AFFILIATES "Affiliates are built" ${USE_DEFAULT_SUBPROJECTS})
option(HAS_TEST "Test are built" ${USE_DEFAULT_SUBPROJECTS})
option(HAS_EXAMPLES "Examples are built" ${USE_DEFAULT_SUBPROJECTS})
option(USE_PYTHON_UI, "Use Python Webview as default UI instead of system browser" ${USE_DEFAULT_PYTHON})
if(HAS_AFFILIATES)
add_subdirectory(affiliates)
endif()
if(HAS_TEST)
add_subdirectory(test)
endif()
if(HAS_EXAMPLES)
add_subdirectory(examples)
endif()