CMakeLists.txt 5.25 KB
Newer Older
1
2
3
cmake_minimum_required(VERSION 3.5)
project(DPsim CXX)

4
5
6
7
8
9
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
	set(TOPLEVEL_PROJECT ON)
else()
		set(TOPLEVEL_PROJECT OFF)
endif()

Steffen Vogel's avatar
Steffen Vogel committed
10
# Enable C++11 support
11
set(CMAKE_CXX_STANDARD 11)
Georg Martin Reinke's avatar
Georg Martin Reinke committed
12
13
14
15
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++11")
endif()
Markus Mirz's avatar
Markus Mirz committed
16
add_definitions(-D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
17
add_definitions(-D_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING)
18

Markus Mirz's avatar
Markus Mirz committed
19
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake;${PROJECT_SOURCE_DIR}/models/CMake")
20

21
set(PROJECT_AUTHOR "Institute for Automation of Complex Power Systems, RWTH Aachen University")
Markus Mirz's avatar
Markus Mirz committed
22
23
24
25
set(PROJECT_COPYRIGHT "2017-2020, Institute for Automation of Complex Power Systems, RWTH Aachen University")
set(PROJECT_DESCRIPTION "C++ Power System Simulation Library")
set(PROJECT_HOMEPAGE_URL "http://www.fein-aachen.org/projects/dpsim/")
set(PROJECT_VCS_URL "https://git.rwth-aachen.org/acs/public/simulation/dpsim")
26

27
include(CheckCXXCompilerFlag)
Markus Mirz's avatar
Markus Mirz committed
28
if(MSVC)	
Markus Mirz's avatar
Markus Mirz committed
29
30
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")

31
32
33
	check_cxx_compiler_flag("/W4 /WX" CXX_SUPPORTS_WERROR)

	if(CXX_SUPPORTS_WERROR)
Markus Mirz's avatar
Markus Mirz committed
34
35
	# TODO activate this again after fixing warnings
	#		set(DPSIM_CXX_FLAGS /W4 /WX)
36
37
38
39
40
41
42
43
	endif()
else()
	check_cxx_compiler_flag("-Wall -Werror" CXX_SUPPORTS_WERROR)

	if(CXX_SUPPORTS_WERROR)
		set(DPSIM_CXX_FLAGS -Wall -Werror)
	endif()
endif()
44

45
46
47
include(CheckSymbolExists)
check_symbol_exists(pipe unistd.h HAVE_PIPE)
check_symbol_exists(timerfd_create sys/timerfd.h HAVE_TIMERFD)
Steffen Vogel's avatar
Steffen Vogel committed
48
check_symbol_exists(getopt_long getopt.h HAVE_GETOPT)
49

50
51
52
# Get version info and buildid from Git
include(GetVersion)
GetVersion(${PROJECT_SOURCE_DIR} "DPSIM")
53

Markus Mirz's avatar
Markus Mirz committed
54
55
56
57
58
59
60
61
62
63
64
65
66
find_package(Eigen3 3.0 REQUIRED)
option(SPDLOG_BUILD_TESTING "Build spdlog tests" OFF)
option(SPDLOG_BUILD_BENCH "Build spdlog benchmarks" OFF)
option(SPDLOG_BUILD_EXAMPLES "Build spdlog examples" OFF)
# Workaround for spdlog in Windows
# A custom FindSpdlog does not work currently
option(WITH_SPDLOG_SUBMODULE "Build with Spdlog as submodule" OFF)
if (WITH_SPDLOG_SUBMODULE OR WIN32)	
	set(SPDLOG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/spdlog/include)
else()
	find_package(spdlog REQUIRED)
endif()
find_package(CIMpp)
Markus Mirz's avatar
Markus Mirz committed
67
add_subdirectory(models)
Markus Mirz's avatar
Markus Mirz committed
68

69
70
find_package(PythonInterp 3.6)
find_package(PythonLibs 3.6)
71
find_package(Sundials)
Markus Mirz's avatar
Markus Mirz committed
72

Markus Mirz's avatar
Markus Mirz committed
73
find_package(OpenMP)
Markus Mirz's avatar
Markus Mirz committed
74

Jan Dinkelbach's avatar
add GSL    
Jan Dinkelbach committed
75
find_package(GSL)
76
find_package(VILLASnode)
77

Steffen Vogel's avatar
Steffen Vogel committed
78
79
80
81
82
83
if(PythonInterp_FOUND AND PythonLibs_FOUND)
	set(Python_FOUND ON)
endif()

if("${CMAKE_SYSTEM}" MATCHES "Linux")
	set(Linux_FOUND ON)
84
85
endif()

Steffen Vogel's avatar
Steffen Vogel committed
86
# Options
87
88
include(CMakeDependentOption)

Steffen Vogel's avatar
Steffen Vogel committed
89
option(BUILD_SHARED_LIBS "Build shared library" OFF)
90
option(BUILD_EXAMPLES "Build C++ examples" ON)
91
option(COMPARE_REFERENCE "Download reference results and compare" OFF)
Steffen Vogel's avatar
Steffen Vogel committed
92

93
94
95
96
97
98
99
cmake_dependent_option(WITH_GSL			"Enable GSL"        					ON "GSL_FOUND"			OFF)
cmake_dependent_option(WITH_SUNDIALS	"Enable sundials solver suite"			ON "Sundials_FOUND"		OFF)
cmake_dependent_option(WITH_SHMEM		"Enable shared memory interface"		ON "VILLASnode_FOUND"	OFF)
cmake_dependent_option(WITH_RT			"Enable real-time features"				ON "Linux_FOUND"		OFF)
cmake_dependent_option(WITH_PYTHON		"Enable Python support"					ON "Python_FOUND"		OFF)
cmake_dependent_option(WITH_CIM			"Enable support for parsing CIM files"	ON "CIMpp_FOUND"		OFF)
cmake_dependent_option(WITH_OPENMP		"Enable OpenMP-based parallelisation"	ON "OPENMP_FOUND"		OFF)
100
101

configure_file(
102
103
	${CMAKE_CURRENT_SOURCE_DIR}/Include/dpsim/Config.h.in
	${CMAKE_CURRENT_BINARY_DIR}/Include/dpsim/Config.h
104
105
106
)

set(INCLUDE_DIRS
107
108
	${CMAKE_CURRENT_BINARY_DIR}/Include
	${CMAKE_CURRENT_SOURCE_DIR}/Include
109
110
)

111
add_subdirectory(Tests)
112
add_subdirectory(Source)
113
add_subdirectory(Documentation)
Markus Mirz's avatar
Markus Mirz committed
114

115
if(BUILD_EXAMPLES)
116
	add_subdirectory(Examples)
117
endif(BUILD_EXAMPLES)
118

119
120
121
122
123
124
125
126
127
128
129
if(COMPARE_REFERENCE)
	include(ExternalProject)
	ExternalProject_Add(reference-results
	  GIT_REPOSITORY    https://git.rwth-aachen.de/acs/public/simulation/reference-results.git
	  #GIT_TAG           origin/master
	  PREFIX			reference-results
	  CONFIGURE_COMMAND	""
	  BUILD_COMMAND		""
	  INSTALL_COMMAND	""
	)
endif()
Steffen Vogel's avatar
Steffen Vogel committed
130

Markus Mirz's avatar
Markus Mirz committed
131
132
133
134
135
message("Compiler Release Flags:")
message(${CMAKE_CXX_FLAGS_RELEASE})
message("Compiler Debug Flags:")
message(${CMAKE_CXX_FLAGS_DEBUG})

136
137
138
139
140
141
142
143
if(TOPLEVEL_PROJECT)
	# Show feature summary
	include(FeatureSummary)

	add_feature_info(CIM	WITH_CIM	"Loading Common Information Model Files")
	add_feature_info(Python WITH_PYTHON "Use DPsim as a Python module")
	add_feature_info(Shmem  WITH_SHMEM  "Interface DPsim solvers via shared-memory interfaces")
	add_feature_info(RT	    WITH_RT     "Extended real-time features")
Jan Dinkelbach's avatar
add GSL    
Jan Dinkelbach committed
144
	add_feature_info(GSL	WITH_GSL     "Use GNU Scientific library")
145
146
	feature_summary(WHAT ALL VAR enabledFeaturesText)

147
148
149
150
151
152
153
154
155
156
157
158
	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()
159
endif()
160

Steffen Vogel's avatar
Steffen Vogel committed
161
include(DPsimPackaging)