-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
239 lines (202 loc) · 10 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
cmake_minimum_required(VERSION 3.19)
find_package(Git)
project(the-arbor-gui
VERSION 0.8.1
LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
include(GNUInstallDirs)
# Generate a .json file with full compilation command for each file.
set(CMAKE_EXPORT_COMPILE_COMMANDS "YES")
# Do we want to generate a OSX thing?
set(ARBORGUI_BUILD_BUNDLE OFF CACHE BOOL "Make an OSX package")
# Tweak Arbor
set(ARB_WITH_NEUROML ON CACHE BOOL "enable neuroml" FORCE)
set(ARB_WITH_PYTHON OFF CACHE BOOL "disable pyarb" FORCE)
set(ARB_USE_BUNDLED_LIBS ON CACHE BOOL "use internal deps" FORCE)
add_subdirectory(3rd-party/arbor)
# Add OpenGL loader
set(OPTION_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(OPTION_BUILD_TOOLs OFF CACHE BOOL "" FORCE)
set(OPTION_USE_GIT_INFORMATION OFF CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
add_subdirectory(3rd-party/glbinding)
# Tweak GLFW
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_INSTALL ON CACHE BOOL "" FORCE)
set(GLFW_INCLUDE_NONE ON CACHE BOOL "" FORCE)
add_subdirectory(3rd-party/glfw)
# Set up sanitizer targets
list(APPEND CMAKE_CONFIGURATION_TYPES asan)
list(APPEND CMAKE_CONFIGURATION_TYPES msan)
list(APPEND CMAKE_CONFIGURATION_TYPES ubsan)
set(CMAKE_C_FLAGS_ASAN
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C compiler for Asan build type or configuration." FORCE)
set(CMAKE_CXX_FLAGS_ASAN
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C++ compiler for Asan build type or configuration." FORCE)
set(CMAKE_EXE_LINKER_FLAGS_ASAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address" CACHE STRING
"Linker flags to be used to create executables for Asan build type." FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_ASAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address" CACHE STRING
"Linker lags to be used to create shared libraries for Asan build type." FORCE)
set(CMAKE_C_FLAGS_MSAN
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=memory -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C compiler for Msan build type or configuration." FORCE)
set(CMAKE_CXX_FLAGS_MSAN
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=memory -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C++ compiler for Msan build type or configuration." FORCE)
set(CMAKE_EXE_LINKER_FLAGS_MSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=memory" CACHE STRING
"Linker flags to be used to create executables for Msan build type." FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_MSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=memory" CACHE STRING
"Linker lags to be used to create shared libraries for Msan build type." FORCE)
set(CMAKE_C_FLAGS_UBSAN
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C compiler for Ubsan build type or configuration." FORCE)
set(CMAKE_CXX_FLAGS_UBSAN
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C++ compiler for Ubsan build type or configuration." FORCE)
set(CMAKE_EXE_LINKER_FLAGS_UBSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined" CACHE STRING
"Linker flags to be used to create executables for Ubsan build type." FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_UBSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined" CACHE STRING
"Linker lags to be used to create shared libraries for Ubsan build type." FORCE)
# figure out OpenGL on *NIX
if (APPLE)
find_library(cocoa_library Cocoa)
find_library(iokit_library IOKit)
find_library(cf_library CoreFoundation)
list(APPEND ARBORGUI_LIBS ${cf_library} ${cocoa_library} ${iokit_library})
mark_as_advanced(cocoa_library iokit_library)
find_library(corevideo_library CoreVideo)
# find_library(opengl_library OpenGL)
# Disable OpenGL deprecation warnings
add_definitions(-DGL_SILENCE_DEPRECATION=1)
list(APPEND ARBORGUI_LIBS ${corevideo_library})
# mark_as_advanced( corevideo_library)
elseif (CMAKE_SYSTEM MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "BSD")
list(APPEND ARBORGUI_LIBS X11 pthread)
list(APPEND ARBORGUI_LIBS GL)
if (NOT CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
list(APPEND ARBORGUI_LIBS rt)
endif()
if (CMAKE_SYSTEM MATCHES "Linux")
list(APPEND ARBORGUI_LIBS dl)
endif()
endif()
add_library(arbor-gui-deps INTERFACE)
target_link_libraries(arbor-gui-deps INTERFACE glbinding)
target_include_directories(arbor-gui-deps SYSTEM INTERFACE 3rd-party/fmt/include)
target_include_directories(arbor-gui-deps SYSTEM INTERFACE 3rd-party/icons)
target_include_directories(arbor-gui-deps SYSTEM INTERFACE 3rd-party/spdlog/include)
target_include_directories(arbor-gui-deps SYSTEM INTERFACE 3rd-party/json/include)
target_include_directories(arbor-gui-deps SYSTEM INTERFACE 3rd-party/imgui)
target_include_directories(arbor-gui-deps SYSTEM INTERFACE 3rd-party/implot)
target_include_directories(arbor-gui-deps SYSTEM INTERFACE 3rd-party/ImGuizmo)
target_include_directories(arbor-gui-deps SYSTEM INTERFACE 3rd-party/glm)
target_include_directories(arbor-gui-deps SYSTEM INTERFACE 3rd-party/stb)
target_include_directories(arbor-gui-deps SYSTEM INTERFACE 3rd-party/imgui/backends)
add_library(imgui OBJECT
3rd-party/imgui/backends/imgui_impl_opengl3.cpp
3rd-party/imgui/backends/imgui_impl_glfw.cpp
3rd-party/imgui/imgui.cpp
3rd-party/imgui/imgui_draw.cpp
3rd-party/imgui/imgui_widgets.cpp
3rd-party/imgui/imgui_tables.cpp
3rd-party/imgui/imgui_demo.cpp
3rd-party/imgui/misc/cpp/imgui_stdlib.cpp
3rd-party/ImGuizmo/ImGuizmo.cpp
3rd-party/implot/implot.cpp
3rd-party/implot/implot_items.cpp)
target_include_directories(imgui PRIVATE 3rd-party/imgui)
target_include_directories(imgui PUBLIC 3rd-party/implot)
target_include_directories(imgui PUBLIC 3rd-party/ImGuizmo/)
target_link_libraries(imgui PRIVATE glfw)
# Get commit hashes from git and inject into config
execute_process(COMMAND ${GIT_EXECUTABLE} -C ${PROJECT_SOURCE_DIR} describe --always --dirty --abbrev=0
COMMAND_ECHO STDOUT
OUTPUT_VARIABLE ARBORGUI_GIT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE)
configure_file(src/config.hpp.in config.hpp @ONLY)
set(gui_srcs
src/main.cpp
src/cell_builder.hpp src/cell_builder.cpp
src/gui_state.hpp src/gui_state.cpp
src/window.hpp src/window.cpp
src/id.hpp
src/recipe.hpp
src/utils.hpp src/utils.cpp
src/view_state.hpp
src/events.hpp
src/spike_detector.hpp src/spike_detector.cpp
src/stimulus.hpp src/stimulus.cpp
src/probe.hpp src/probe.cpp
src/ion.hpp src/ion.cpp
src/simulation.hpp src/simulation.cpp
src/parameter.hpp src/parameter.cpp
src/cv_policy.hpp src/cv_policy.cpp
src/mechanism.hpp src/mechanism.cpp
src/component.hpp
src/file_chooser.hpp src/file_chooser.cpp
src/loader.hpp src/loader.cpp
src/geometry.hpp src/geometry.cpp
src/location.hpp)
set_source_files_properties("${gui_srcs}" PROPERTIES COMPILE_FLAGS "-Wall -Wextra -pedantic")
if(ARBORGUI_BUILD_BUNDLE)
if (APPLE)
set(resource_path "arbor-gui.app/Contents/Resources")
set(ARBORGUI_ICON arbor.icns)
set(ARBORGUI_ICON_PATH ${CMAKE_SOURCE_DIR}/images/${ARBORGUI_ICON})
set_source_files_properties(${ARBORGUI_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
add_executable(arbor-gui MACOSX_BUNDLE ${ARBORGUI_ICON_PATH} ${gui_srcs} $<TARGET_OBJECTS:imgui>)
set_target_properties(arbor-gui PROPERTIES MACOSX_BUNDLE_ICONFILE ${ARBORGUI_ICON})
target_compile_definitions(arbor-gui PUBLIC FMT_HEADER_ONLY)
target_include_directories(arbor-gui PRIVATE src ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(arbor-gui PRIVATE ${ARBORGUI_LIBS} arbor arborio glbinding glfw arbor-gui-deps)
install(TARGETS arbor-gui
BUNDLE DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION bin COMPONENT Runtime)
install(FILES ${ARBORGUI_ICON_PATH} DESTINATION ${resource_path})
install(FILES default.ini DESTINATION ${resource_path} RENAME imgui.ini)
install(DIRECTORY glsl DESTINATION ${resource_path})
install(DIRECTORY fonts DESTINATION ${resource_path})
set(CPACK_BINARY_DRAGNDROP ON)
set(CPACK_GENERATOR "DragNDrop")
include(CPack)
endif()
if (CMAKE_SYSTEM MATCHES "Linux")
endif()
else()
set(resource_path "${CMAKE_INSTALL_FULL_DATAROOTDIR}/arbor-gui")
add_compile_definitions(ARBORGUI_RESOURCES_BASE="${resource_path}")
add_executable(arbor-gui ${gui_srcs} $<TARGET_OBJECTS:imgui>)
target_include_directories(arbor-gui PRIVATE src ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(arbor-gui PRIVATE ${ARBORGUI_LIBS} arbor arborio glbinding glfw arbor-gui-deps)
target_compile_definitions(arbor-gui PUBLIC FMT_HEADER_ONLY)
# Set icon on output
if (APPLE)
add_custom_command(TARGET arbor-gui POST_BUILD
COMMAND sh ${CMAKE_SOURCE_DIR}/scripts/set-osx-icon.sh ${CMAKE_SOURCE_DIR}/images/arbor.png ${CMAKE_CURRENT_BINARY_DIR}/arbor-gui
DEPENDS ${CMAKE_SOURCE_DIR}/scripts/set-osx-icon.sh ${CMAKE_SOURCE_DIR}/images/arbor.png)
endif()
if (CMAKE_SYSTEM MATCHES "Linux")
install(FILES ${CMAKE_SOURCE_DIR}/images/arbor.png DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/256x256/apps/)
install(FILES ${CMAKE_SOURCE_DIR}/images/arbor.svg DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/icons/hicolor/scalable/apps/)
install(FILES ${CMAKE_SOURCE_DIR}/scripts/arbor-gui.desktop DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/applications/)
endif()
install(TARGETS arbor-gui RUNTIME DESTINATION bin)
# Set icon _again_ since CMake strips installed binaries
if (APPLE)
install(CODE "execute_process(COMMAND sh ${CMAKE_SOURCE_DIR}/scripts/set-osx-icon.sh ${CMAKE_SOURCE_DIR}/images/arbor.png ${CMAKE_INSTALL_PREFIX}/bin/arbor-gui)")
endif()
# install resources
install(DIRECTORY glsl DESTINATION ${resource_path})
install(DIRECTORY fonts DESTINATION ${resource_path})
install(FILES default.ini DESTINATION ${resource_path} RENAME imgui.ini)
endif()