-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
179 lines (156 loc) · 5.06 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
cmake_minimum_required(VERSION 3.22)
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0114 NEW)
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
project(
dtk
VERSION 0.1.0
LANGUAGES CXX C)
#-------------------------------------------------------------------------------
# Options
set(dtk_UI_LIB ON CACHE BOOL "Build the user interface library")
set(dtk_API "GL_4_1" CACHE STRING "Graphics API (GL_4_1, GL_4_1_Debug, GLES_2)")
if(WIN32 OR APPLE)
set(dtk_NFD_DEFAULT TRUE)
else()
set(dtk_NFD_DEFAULT FALSE)
endif()
set(dtk_NFD ${dtk_NFD_DEFAULT} CACHE BOOL "Enable support for native file dialogs")
set(dtk_PYTHON OFF CACHE BOOL "Enable support for Python")
set(dtk_TESTS ON CACHE BOOL "Enable tests")
set(dtk_EXAMPLES ON CACHE BOOL "Enable examples")
if(APPLE)
set(dtk_IGNORE_PREFIX_PATH_DEFAULT /opt/homebrew)
endif()
set(dtk_IGNORE_PREFIX_PATH ${dtk_IGNORE_PREFIX_PATH_DEFAULT} CACHE STRING "Ignore the given prefix path")
set(dtk_GCOV FALSE CACHE BOOL "Enable gcov code coverage")
set(dtk_GPROF FALSE CACHE BOOL "Enable gprof code profiling")
#-------------------------------------------------------------------------------
# Configuration
set(CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake/Modules)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_FIND_FRAMEWORK LAST)
if(WIN32)
elseif(APPLE)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
else()
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "../lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
endif()
if(dtk_UI_LIB)
add_definitions(-DDTK_UI_LIB)
endif()
if(dtk_IGNORE_PREFIX_PATH)
set(CMAKE_IGNORE_PREFIX_PATH ${dtk_IGNORE_PREFIX_PATH})
endif()
if(CMAKE_BUILD_TYPE MATCHES "^Debug$")
add_definitions(-DDTK_ASSERT)
endif()
if(dtk_TESTS)
set(CTEST_OUTPUT_ON_FAILURE ON)
enable_testing()
endif()
if(dtk_GCOV)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")# -fkeep-inline-functions")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")# -fkeep-inline-functions")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()
if(dtk_GPROF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include_directories(lib etc)
if(dtk_TESTS)
include_directories(tests)
endif()
#-------------------------------------------------------------------------------
# Dependencies
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(PNG REQUIRED)
find_package(Freetype REQUIRED)
find_package(lunasvg REQUIRED)
if(dtk_UI_LIB)
if ("${dtk_API}" STREQUAL "GL_4_1")
include_directories(${PROJECT_SOURCE_DIR}/deps/glad_GL_4_1/include)
elseif ("${dtk_API}" STREQUAL "GL_4_1_Debug")
include_directories(${PROJECT_SOURCE_DIR}/deps/glad_GL_4_1_Debug/include)
elseif ("${dtk_API}" STREQUAL "GLES_2")
include_directories(${PROJECT_SOURCE_DIR}/deps/glad_GLES_2/include)
endif()
if ("${dtk_API}" STREQUAL "GL_4_1" OR
"${dtk_API}" STREQUAL "GL_4_1_Debug" OR
"${dtk_API}" STREQUAL "GLES_2")
find_package(OpenGL REQUIRED)
find_package(glfw3 REQUIRED)
add_subdirectory(deps/glad_${dtk_API})
endif()
add_definitions(-Ddtk_API_${dtk_API})
if("${dtk_API}" STREQUAL "GL_4_1_Debug")
add_definitions(-Ddtk_API_GL_4_1)
endif()
if(dtk_NFD)
find_package(NFD REQUIRED)
if(NFD_FOUND)
add_definitions(-Ddtk_NFD)
endif()
endif()
if(dtk_PYTHON)
include_directories(python/lib)
if(dtk_TESTS)
include_directories(python/tests)
endif()
add_definitions(-Ddtk_PYTHON)
find_package(Python3 REQUIRED Interpreter Development)
find_package(pybind11 REQUIRED)
endif()
endif()
#-------------------------------------------------------------------------------
# Subdirectories
add_subdirectory(lib/dtk)
add_subdirectory(bin)
if(dtk_UI_LIB AND dtk_PYTHON)
add_subdirectory(python)
endif()
if(dtk_TESTS)
add_subdirectory(tests)
endif()
if(dtk_UI_LIB AND dtk_EXAMPLES)
add_subdirectory(examples)
endif()
install(
FILES cmake/Modules/FindZLIB.cmake
DESTINATION lib/cmake/dtk)
install(
FILES cmake/Modules/FindPNG.cmake
DESTINATION lib/cmake/dtk)
if(dtk_UI_LIB)
install(
FILES cmake/Modules/FindNFD.cmake
DESTINATION lib/cmake/dtk)
endif()
include(CMakePackageConfigHelpers)
set(INCLUDE_INSTALL_DIR include/dtk)
configure_package_config_file(
dtkConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/dtkConfig.cmake
INSTALL_DESTINATION lib/cmake/dtk
PATH_VARS INCLUDE_INSTALL_DIR)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/dtkConfig.cmake
DESTINATION lib/cmake/dtk)