-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
236 lines (207 loc) · 10.1 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
#############################################################################
# Name: CMakeLists.txt
# Purpose: Build script for Wisteria Dataviz library and demo project
# Author: Blake Madden
# Created: 2022-01-17
# Copyright: (c) 2005-2022 Blake Madden
# License: 3-Clause BSD license
#############################################################################
# Declare the minimum required CMake version
# Note that CMake 3.24 is needed if compiling wxWidgets 3.2
CMAKE_MINIMUM_REQUIRED(VERSION 3.14)
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD_REQUIRED True)
IF(NOT CMAKE_CONFIGURATION_TYPES)
GET_PROPERTY(HAVE_MULTI_CONFIG_GENERATOR GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
# Set default configuration types for multi-config generators
IF(HAVE_MULTI_CONFIG_GENERATOR)
SET(CMAKE_CONFIGURATION_TYPES "Debug;Release")
ENDIF()
ENDIF()
# https://blog.kitware.com/cmake-and-the-default-build-type/
IF(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
SET(default_build_type "Debug")
MESSAGE(STATUS "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." FORCE)
# Set the possible values of build type for cmake-gui
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
ENDIF()
PROJECT(Wisteria)
# Build the documentation (not available on Windows)
########################
IF(NOT WIN32)
# https://vicrucann.github.io/tutorials/quick-cmake-doxygen/
FIND_PACKAGE(Doxygen)
IF(DOXYGEN_FOUND)
# set input and output files
SET(DOXYGEN_IN "${CMAKE_SOURCE_DIR}/docs/doxygen/Doxyfile")
IF(EXISTS ${DOXYGEN_IN})
MESSAGE("Doxygen build started")
# note the option ALL which allows to build the docs together with the application
ADD_CUSTOM_TARGET( doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_IN}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/docs/doxygen"
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
ELSE()
MESSAGE("Doxygen project file missing (${DOXYGEN_IN}).")
ENDIF()
ELSE(DOXYGEN_FOUND)
MESSAGE("Doxygen not found. API documentation will not be generated.")
ENDIF()
ENDIF()
# Setup wxWidgets
########################
# Linux: install the wxWidgets development files to your system
# Windows: set wxWidgets_ROOT_DIR to the wxWidgets root path
# Find wxWidgets and select its components
FIND_PACKAGE(wxWidgets REQUIRED core base adv html ribbon xml xrc qa propgrid OPTIONAL_COMPONENTS net)
# Include the wxWidgets use file to initialize various settings
INCLUDE(${wxWidgets_USE_FILE})
MESSAGE(STATUS "Adding wxWidgets libraries: ${wxWidgets_LIBRARIES}")
MESSAGE(STATUS "Adding wxWidgets configuration file: ${wxWidgets_CONFIGURATION}/wx/setup.h")
IF(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
# If no deployment target has been set default to the minimum supported
# OS version (this has to be set before the first project() call)
IF(CMAKE_SYSTEM_NAME STREQUAL "iOS")
SET(CMAKE_OSX_DEPLOYMENT_TARGET 12.0 CACHE STRING "iOS Deployment Target")
ELSE()
SET(CMAKE_OSX_DEPLOYMENT_TARGET 10.10 CACHE STRING "macOS Deployment Target")
ENDIF()
ENDIF()
ADD_COMPILE_OPTIONS("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
ADD_COMPILE_OPTIONS("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
# Build Wisteria library
########################
# (run "tools/Build CMake Files List.R" to update this)
INCLUDE(${CMAKE_SOURCE_DIR}/tools/libfiles.cmake)
ADD_LIBRARY(WisteriaLib STATIC ${WISTERIA_SRC})
# Add OpenMP for mutlithreading
FIND_PACKAGE(OpenMP)
IF(OpenMP_CXX_FOUND)
MESSAGE(STATUS "OpenMP available; will be included.")
TARGET_LINK_LIBRARIES(WisteriaLib PUBLIC OpenMP::OpenMP_CXX)
ENDIF()
TARGET_INCLUDE_DIRECTORIES(WisteriaLib PUBLIC ${wxWidgets_INCLUDE_DIRS})
# Set definitions, warnings, and optimizations (will propagate to the demo project also)
IF(MSVC)
TARGET_COMPILE_DEFINITIONS(WisteriaLib PUBLIC __WXMSW__ _CRT_SECURE_NO_WARNINGS
$<$<CONFIG:Debug>:__WXDEBUG__> $<$<CONFIG:Release>:NDEBUG>)
# /Zc:__cplusplus tells MSVC to set the C++ version what we are
# actually compiling as. The default behavior in MSVC is to say that the
# C++ version is 98 always (for compatibility reasons).
# /MP enables multi-core build support, speeding up compilation time.
# /W3 cranks up the warning level, /WX treats all warnings as error.
# Note that simply using /W4 causes a warning that it is overriding
# /W3, and then that turns into an error because of /W4. So /W3 is the
# highest you can go with /WX.
# /wd6211 turns off C6211 warning: leaking memory due to an exception.
# wxWidgets uses heap-based objects for most everything, and MVSC complains
# about not wrapping all of this logic in try blocks.
TARGET_COMPILE_OPTIONS(WisteriaLib PUBLIC /Zc:__cplusplus /MP /W3 /WX /wd6211
$<$<CONFIG:Debug>:/Od> $<$<CONFIG:Release>:/O2>)
ELSEIF(MINGW OR MSYS)
TARGET_COMPILE_DEFINITIONS(WisteriaLib PUBLIC __WXMSW__
$<$<CONFIG:Debug>:__WXDEBUG__> $<$<CONFIG:Release>:NDEBUG>)
TARGET_COMPILE_OPTIONS(WisteriaLib PUBLIC -Wall -Wextra -Wpedantic -Wshadow -Werror
$<$<CONFIG:Debug>:-Og> $<$<CONFIG:Release>:-O2>)
# TODO: Experimental code for macOS (undergoing testing currently)
ELSEIF(APPLE)
TARGET_COMPILE_DEFINITIONS(WisteriaLib PUBLIC __WXOSX__
$<$<CONFIG:Debug>:__WXDEBUG__> $<$<CONFIG:Release>:NDEBUG>)
TARGET_COMPILE_OPTIONS(WisteriaLib PUBLIC -Wall -Wextra -Wpedantic -Wshadow -Werror
$<$<CONFIG:Debug>:-Og> $<$<CONFIG:Release>:-O2>)
ELSEIF(UNIX)
TARGET_COMPILE_DEFINITIONS(WisteriaLib PUBLIC __WXGTK__
$<$<CONFIG:Debug>:__WXDEBUG__> $<$<CONFIG:Release>:NDEBUG>)
TARGET_COMPILE_OPTIONS(WisteriaLib PUBLIC -Wall -Wextra -Wpedantic -Wshadow -Werror
$<$<CONFIG:Debug>:-Og> $<$<CONFIG:Release>:-O2>)
ENDIF()
# Build the library demo
########################
SET(DEMO_SRC_FILES ${CMAKE_SOURCE_DIR}/demo/demo.cpp)
IF(WIN32)
# Include an RC file and HiDPI manifest for Windows (provided by wxWidgets)
SET(wxUSE_DPI_AWARE_MANIFEST 1)
LIST(APPEND DEMO_SRC_FILES ${wxWidgets_ROOT_DIR}/include/wx/msw/wx.rc)
LIST(APPEND DEMO_SRC_FILES ${wxWidgets_ROOT_DIR}/include/wx/msw/wx_dpi_aware.manifest)
ELSEIF(APPLE)
# Add an icon for the apple .app file
LIST(APPEND DEMO_SRC_FILES ${CMAKE_SOURCE_DIR}/demo/wxmac.icns)
ENDIF()
# Define the build target for the executable and copy it into the "demo" subfolder
MESSAGE(STATUS "Building the demonstration program...")
SET(DEMO_APP WisteriaDemo)
ADD_EXECUTABLE(${DEMO_APP} WIN32 MACOSX_BUNDLE ${DEMO_SRC_FILES})
SET_TARGET_PROPERTIES(${DEMO_APP} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/demo")
# Link required libraries to the executable
IF(WIN32)
TARGET_LINK_LIBRARIES(${DEMO_APP} WisteriaLib ${wxWidgets_LIBRARIES})
ELSEIF(UNIX)
FIND_LIBRARY(TBB_LIB tbb)
TARGET_LINK_LIBRARIES(${DEMO_APP} WisteriaLib ${wxWidgets_LIBRARIES} ${TBB_LIB})
ENDIF()
# Copy resources and datasets into build folder
MESSAGE(STATUS "Copying demo resources...")
ADD_CUSTOM_COMMAND(TARGET ${DEMO_APP}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/demo/res $<TARGET_FILE_DIR:${DEMO_APP}>/res)
ADD_CUSTOM_COMMAND(TARGET ${DEMO_APP}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/datasets $<TARGET_FILE_DIR:${DEMO_APP}>/datasets)
IF(APPLE)
SET_TARGET_PROPERTIES(${DEMO_APP} PROPERTIES
RESOURCE "demo/wxmac.icns"
MACOSX_BUNDLE_ICON_FILE wxmac.icns
MACOSX_BUNDLE_COPYRIGHT "Copyright Blake Madden"
MACOSX_BUNDLE_GUI_IDENTIFIER "org.wisteria.demo")
ENDIF()
# Build the app (not currently available)
########################
IF(EXISTS "${CMAKE_SOURCE_DIR}/app" AND EXISTS "${CMAKE_SOURCE_DIR}/app/wisteriaapp.cpp")
SET(APP_SRC_FILES ${CMAKE_SOURCE_DIR}/app/wisteriaapp.cpp
${CMAKE_SOURCE_DIR}/app/wisteriaview.cpp
${CMAKE_SOURCE_DIR}/app/wisteriadoc.cpp)
IF(WIN32)
# Include an RC file and HiDPI manifest for Windows (provided by wxWidgets)
SET(wxUSE_DPI_AWARE_MANIFEST 1)
LIST(APPEND APP_SRC_FILES ${wxWidgets_ROOT_DIR}/include/wx/msw/wx.rc)
LIST(APPEND APP_SRC_FILES ${wxWidgets_ROOT_DIR}/include/wx/msw/wx_dpi_aware.manifest)
ELSEIF(APPLE)
# Add an icon for the apple .app file
LIST(APPEND APP_SRC_FILES ${CMAKE_SOURCE_DIR}/app/wxmac.icns)
ENDIF()
# Define the build target for the executable and copy it into the "app" subfolder
MESSAGE(STATUS "Building the program...")
SET(WISTERIA_APP WisteriaDV)
ADD_EXECUTABLE(${WISTERIA_APP} WIN32 MACOSX_BUNDLE ${APP_SRC_FILES})
SET_TARGET_PROPERTIES(${WISTERIA_APP} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/app")
# Link required libraries to the executable
IF(WIN32)
TARGET_LINK_LIBRARIES(${WISTERIA_APP} WisteriaLib ${wxWidgets_LIBRARIES})
ELSEIF(UNIX)
FIND_LIBRARY(TBB_LIB tbb)
TARGET_LINK_LIBRARIES(${WISTERIA_APP} WisteriaLib ${wxWidgets_LIBRARIES} ${TBB_LIB})
ENDIF()
# Copy resources and datasets into build folder
MESSAGE(STATUS "Copying application resources...")
ADD_CUSTOM_COMMAND(TARGET ${WISTERIA_APP}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/app/res $<TARGET_FILE_DIR:${WISTERIA_APP}>/res)
ADD_CUSTOM_COMMAND(TARGET ${WISTERIA_APP}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/datasets $<TARGET_FILE_DIR:${WISTERIA_APP}>/datasets)
IF(APPLE)
SET_TARGET_PROPERTIES(${WISTERIA_APP} PROPERTIES
RESOURCE "app/wxmac.icns"
MACOSX_BUNDLE_ICON_FILE wxmac.icns
MACOSX_BUNDLE_COPYRIGHT "Copyright Blake Madden"
MACOSX_BUNDLE_GUI_IDENTIFIER "org.wisteria.app")
ENDIF()
ENDIF()