-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
108 lines (87 loc) · 2.87 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
cmake_minimum_required(VERSION 3.1.0)
project(Grate LANGUAGES CXX)
# trying to force 64bit under MSVC
set(CMAKE_VS_PLATFORM_NAME "x64")
#set(CMAKE_GENERATOR_PLATFORM "x64")
# options to build CLI and GUI versions
option(BUILD_GUI "Build Qt5 GUI version" ON)
option(BUILD_CLI "Build command line version" ON)
# enable testing (disable with -DBUILD_TESTING=OFF)
include(CTest)
# default to RELWITHDEBINFO build if not specified
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "RELWITHDEBINFO" CACHE STRING "" FORCE)
endif()
# option to gather profiling data
option(ENABLE_PROFILING "Enable gprof profiling" OFF)
if (ENABLE_PROFILING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
# disable some optimisations as recommended here: https://github.com/jrfonseca/gprof2dot
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fno-inline-functions -fno-inline-functions-called-once -fno-optimize-sibling-calls")
endif()
endif()
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# common sources
set(CPP_SOURCES
tinyxml2/tinyxml2.cpp
tinyxml2_wrapper.cpp
gratetime.cpp
sed.cpp
riverprofile.cpp
hydro.cpp
model.cpp
)
# GUI specific sources
set(GUI_SOURCES
qcustomplot.cpp
mainwindow.cpp
main.cpp
)
set(UI_SOURCES
RwaveWin.ui
)
# CLI specific sources
set(CLI_SOURCES
cli.cpp
)
# build library from common sources
add_library(grate_common ${CPP_SOURCES})
target_include_directories(grate_common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# option for debugging output in hydro::regimeModel
option(DEBUG_REGIME_MODEL "Write CSV file with function values for plotting from hydro::regimeModel" OFF)
if (DEBUG_REGIME_MODEL)
target_compile_definitions(grate_common PRIVATE DEBUG_REGIME_MODEL)
endif()
# GUI build
if (BUILD_GUI)
if (APPLE)
set(OS_BUNDLE MACOSX_BUNDLE)
elseif (WIN32)
set(OS_BUNDLE WIN32)
endif()
# Instruct CMake to run moc automatically when needed
set(CMAKE_AUTOMOC ON)
# Create code from a list of Qt designer ui files
set(CMAKE_AUTOUIC ON)
# Find the Qt libraries
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5PrintSupport REQUIRED)
set(QT5_LIBRARIES Qt5::Core Qt5::Widgets Qt5::PrintSupport)
# Tell CMake to create the Grate executable
add_executable(Grate ${OS_BUNDLE} ${UI_SOURCES} ${GUI_SOURCES})
# Link against Qt 5 libraries
target_link_libraries(Grate grate_common ${QT5_LIBRARIES})
endif()
# CLI build
if (BUILD_CLI)
# create CLI executable and link
add_executable(GrateCLI ${CLI_SOURCES})
target_link_libraries(GrateCLI grate_common)
endif()
# copy input files to build dir for testing
configure_file(test_out.xml ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
# add tests
add_subdirectory(tests)