forked from sogno-platform/dpsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
238 lines (200 loc) · 8.45 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
cmake_minimum_required(VERSION 3.11...3.23)
project(DPsim
VERSION 1.1.0
DESCRIPTION "C++ Power System Simulation Library"
LANGUAGES CXX
HOMEPAGE_URL "https://dpsim.fein-aachen.org/")
set(PROJECT_AUTHOR "The DPsim Authors.")
set(PROJECT_COPYRIGHT "2017-2021, The DPsim Authors.")
set(PROJECT_DESCRIPTION "C++ Power System Simulation Library")
set(PROJECT_HOMEPAGE_URL "https://dpsim.fein-aachen.org/")
set(PROJECT_VCS_URL "https://github.com/sogno-platform/dpsim")
# Required for dpsim_python
if(POLICY CMP0076)
cmake_policy(SET CMP0076 NEW)
endif()
# Allow setting Graphviz_ROOT for windows builds
if(WIN32)
cmake_policy(SET CMP0074 NEW)
endif()
# Select C++-Version
# For the pybind11-python interface to compile, a minimum version of C++14 is required
# If you need to compile using C++11, either disable the python interface or modify the source-files in Source/pybind,
# replacing all occurences of py::overload_cast with py::detail::overload_cast_impl as specified on
# https://pybind11.readthedocs.io/en/stable/classes.html#overloaded-methods
set(CMAKE_CXX_STANDARD 17)
if(CMAKE_CXX_COMPILER_ID STREQUAL Intel)
# needed by icc, but for some reason not added by CMake
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()
if(NOT WIN32)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(CheckCXXCompilerFlag)
if(MSVC)
# Silence Visual Studio deprecation warnings
add_definitions(-D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
add_definitions(-D_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING)
# Set exception handling for portability
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
check_cxx_compiler_flag("/W4 /WX" CXX_SUPPORTS_WERROR)
if(CXX_SUPPORTS_WERROR)
# TODO activate this again after fixing warnings
# set(DPSIM_CXX_FLAGS /W4 /WX)
endif()
else()
check_cxx_compiler_flag("-Wall -Werror" CXX_SUPPORTS_WERROR)
if(CXX_SUPPORTS_WERROR)
set(DPSIM_CXX_FLAGS -Wall -Werror)
endif()
endif()
include(CheckSymbolExists)
check_symbol_exists(pipe unistd.h HAVE_PIPE)
check_symbol_exists(timerfd_create sys/timerfd.h HAVE_TIMERFD)
check_symbol_exists(getopt_long getopt.h HAVE_GETOPT)
# Get version info and buildid from Git
include(GetVersion)
GetVersion(${PROJECT_SOURCE_DIR} "DPSIM")
option(WITH_EIGEN_MODULE "Build with Eigen as module" OFF)
option(WITH_SPDLOG_SUBMODULE "Build with Spdlog as module" OFF)
option(WITH_CIM_SUBMODULE "Build with CIMpp as module" OFF)
option(WITH_PYBIND_MODULE "Build with pybind11 as module" OFF)
option(WITH_PROFILING "Add `-pg` profiling flag to compiliation" OFF)
option(WITH_ASAN "Adds compiler flags to use the address sanitizer" OFF)
option(WITH_TSAN "Adds compiler flags to use the thread sanitizer" OFF)
option(CGMES_BUILD "Build with CGMES instead of CIM" OFF)
find_package(Threads REQUIRED)
if (WITH_EIGEN_MODULE OR WIN32)
include(cmake/GetEigenModule.cmake)
else()
find_package(Eigen3 3.0 REQUIRED)
endif()
if (WITH_SPDLOG_SUBMODULE OR WIN32)
include(cmake/GetSpdlogModule.cmake)
else()
find_package(spdlog REQUIRED)
find_package(fmt REQUIRED)
endif()
if (WITH_CIM_SUBMODULE OR WIN32)
include(cmake/GetCIMppModule.cmake)
else()
find_package(CIMpp)
endif()
if (WITH_PROFILING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
endif()
if (WITH_ASAN)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize-address-use-after-scope")
else()
message(WARNING "WITH_ASAN is only supported when using GCC")
endif()
endif()
if (WITH_TSAN)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
else()
message(WARNING "WITH_TSAN is only supported when using GCC")
endif()
endif()
find_package(Sundials)
find_package(OpenMP)
find_package(CUDA)
find_package(GSL)
find_package(Graphviz)
find_package(VILLASnode)
find_package(MAGMA)
find_package (Python COMPONENTS Interpreter Development)
if (WITH_PYBIND_MODULE)
include(cmake/GetPybindModule.cmake)
else()
find_package(pybind11 CONFIG QUIET)
endif()
if("${CMAKE_SYSTEM}" MATCHES "Linux")
set(Linux_FOUND ON)
elseif("${CMAKE_SYSTEM}" MATCHES "Darwin")
set(MacOS_FOUND ON)
endif()
option(BUILD_SHARED_LIBS "Build shared library" OFF)
option(DPSIM_BUILD_EXAMPLES "Build C++ examples" ON )
option(GET_GRID_DATA "Download grid data" ON )
option(WITH_JSON "Include json library" ON )
if(WITH_JSON)
include(cmake/GetJsonLibrary.cmake)
endif()
# WITH_SPARSE and WITH_CUDA can be combined
option(WITH_SPARSE "Use sparse matrices in MNA-Solver" ON )
include(CMakeDependentOption)
cmake_dependent_option(WITH_SUNDIALS "Enable sundials solver suite" ON "Sundials_FOUND" OFF)
cmake_dependent_option(WITH_VILLAS "Enable VILLASnode interface" ON "VILLASnode_FOUND" OFF)
cmake_dependent_option(WITH_RT "Enable real-time features" ON "Linux_FOUND" OFF)
cmake_dependent_option(WITH_CIM "Enable support for parsing CIM" ON "CIMpp_FOUND" OFF)
cmake_dependent_option(WITH_OPENMP "Enable OpenMP-based parallelisation" ON "OPENMP_FOUND" OFF)
cmake_dependent_option(WITH_CUDA "Enable CUDA-based parallelisation" OFF "CUDA_FOUND" OFF)
cmake_dependent_option(WITH_GRAPHVIZ "Enable Graphviz Graphs" ON "GRAPHVIZ_FOUND" OFF)
cmake_dependent_option(WITH_PYBIND "Enable PYBIND support" ON "pybind11_FOUND" OFF)
cmake_dependent_option(WITH_MAGMA "Enable MAGMA features" ON "MAGMA_FOUND" OFF)
cmake_dependent_option(WITH_MNASOLVERPLUGIN "Enable MNASolver Plugins" ON "NOT WIN32" OFF)
if(WITH_CUDA)
# BEGIN OF WORKAROUND - enable cuda dynamic linking.
# Starting with Cmake 3.17 we can use
# set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "SHARED") instead
set( CMAKE_CUDA_FLAGS "" CACHE STRING "" )
if ( CMAKE_CUDA_FLAGS )
list(REMOVE_ITEM CMAKE_CUDA_FLAGS "-cudart static")
endif()
string(APPEND CMAKE_CUDA_FLAGS "-cudart shared")
# END OF WORKAROUND
enable_language(CUDA)
# BEGIN OF WORKAROUND - enable cuda dynamic linking.
if ( CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES )
list( REMOVE_ITEM CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES "cudart_static" )
list( REMOVE_ITEM CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES "cudadevrt" )
list( APPEND CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES "cudart" )
endif()
if ( CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES )
list( REMOVE_ITEM CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "cudart_static" )
list( REMOVE_ITEM CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "cudadevrt" )
list( APPEND CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "cudart" )
endif()
if ( CUDA_LIBRARIES )
list ( REMOVE_ITEM CUDA_LIBRARIES "${CUDA_cudart_static_LIBRARY}")
list ( APPEND CUDA_LIBRARIES "${CUDA_CUDART_LIBRARY}")
endif()
# END OF WORKAROUND
endif()
add_subdirectory(dpsim)
add_subdirectory(dpsim-models)
if (WITH_VILLAS)
add_subdirectory(dpsim-villas)
endif(WITH_VILLAS)
add_subdirectory(docs)
include(cmake/GetGridData.cmake)
message(VERBOSE "Compiler Release Flags: " ${CMAKE_CXX_FLAGS_RELEASE})
message(VERBOSE "Compiler Debug Flags: " ${CMAKE_CXX_FLAGS_DEBUG})
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(FeatureSummary)
add_feature_info(CIM WITH_CIM "Loading Common Information Model Files")
add_feature_info(Villas WITH_VILLAS "Interface DPsim solvers via VILLASnode interfaces")
add_feature_info(RT WITH_RT "Extended real-time features")
add_feature_info(JSON WITH_JSON "Use JSON library")
add_feature_info(GSL WITH_GSL "Use GNU Scientific library")
add_feature_info(Graphviz WITH_GRAPHVIZ "Graphviz Graphs")
add_feature_info(Sundials WITH_SUNDIALS "Sundials solvers")
add_feature_info(PYBIND WITH_PYBIND "Use DPsim as a PYBIND module")
feature_summary(WHAT ALL VAR enabledFeaturesText)
if (FOUND_GIT_VERSION)
message(STATUS "Building ${CMAKE_PROJECT_NAME}:")
message(STATUS "Feature summary for DPsim")
message(STATUS "${enabledFeaturesText}")
message(STATUS " VERSION: ${DPSIM_VERSION}")
message(STATUS " RELEASE: ${DPSIM_RELEASE}")
message(STATUS " GIT_REV: ${DPSIM_GIT_REV}")
message(STATUS " GIT_BRANCH: ${DPSIM_GIT_BRANCH}")
message(STATUS " VARIANT: ${DPSIM_VARIANT}")
message(STATUS " BUILD_ID: ${DPSIM_BUILD_ID}")
message(STATUS " BUILD_DATE: ${DPSIM_BUILD_DATE}")
endif()
endif()
include(DPsimPackaging)