Commit 9069f2e5 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

more improvements to CMake

parent 1984b55c
option(CIMPP_DIR "Location of CIMpp library" ${CMAKE_CURRENT_SOURCE_DIR}/../cimpp)
option(CIMPP_DIR "CIM++ installation directory" ../CIMpp)
if(IS_DIRECTORY ${CIMPP_DIR})
set(CIMPP_INCLUDE_DIR ${CIMPP_DIR})
else()
find_path(CIMPP_INCLUDE_DIR
NAMES CIMModel.hpp
PATH_SUFFIXES
cimpp/16v29a_12v08
cimpp/16v29a
cimpp/17v07
)
endif()
file(TO_CMAKE_PATH $ENV{APPDATA} APPDATA)
find_library(CIMPP_LIBRARY NAMES cimpp libcimpp)
find_path(CIMPP_INCLUDE_DIR
NAMES CIMModel.hpp
PATH_SUFFIXES
cimpp/16v29a_12v08
cimpp/16v29a
cimpp/17v07
PATHS
../CIMpp/include
${APPDATA}/CIMpp/include
${CIMPP_DIR}
)
find_library(CIMPP_LIBRARY
NAMES cimpp
PATH_SUFFIXES
lib/static
PATHS
../CIMpp
${APPDATA}/CIMpp
${CIMPP_DIR}
)
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set CIMPP_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(CIMpp DEFAULT_MSG
CIMPP_LIBRARY CIMPP_INCLUDE_DIR)
find_package_handle_standard_args(CIMpp DEFAULT_MSG CIMPP_LIBRARY CIMPP_INCLUDE_DIR)
mark_as_advanced(CIMPP_INCLUDE_DIR CIMPP_LIBRARY)
set(CIMPP_LIBRARIES ${CIMPP_LIBRARY})
set(CIMPP_INCLUDE_DIRS ${CIMPP_INCLUDE_DIR} ${CIMPP_DIR}/cmake-build-debug/include)
set(CIMPP_INCLUDE_DIRS ${CIMPP_INCLUDE_DIR})
# We first try to find a version inside our local Libraries folder
find_path(EIGEN3_INCLUDE_DIR
NAMES signature_of_eigen3_matrix_library
PATHS
Libraries/eigen
../Eigen
)
if(NOT EIGEN3_INCLUDE_DIR)
set(TEMP_PATH ${CMAKE_MODULE_PATH})
# We temporarily clear the module path to avoid recursion
set(CMAKE_MODULE_PATH "")
find_package(Eigen3 REQUIRED)
set(CMAKE_MODULE_PATH ${TEMP_PATH})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Eigen3 REQUIRED_VARS EIGEN3_INCLUDE_DIR)
find_path(VILLASNODE_INCLUDE_DIR
NAMES villas/shmem.h
)
find_library(VILLASNODE_LIBRARY
NAMES villas-ext
)
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set VILLASNODE_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(VILLASnode DEFAULT_MSG
VILLASNODE_LIBRARY VILLASNODE_INCLUDE_DIR)
mark_as_advanced(VILLASNODE_INCLUDE_DIR VILLASNODE_LIBRARY)
set(VILLASNODE_LIBRARIES ${VILLASNODE_LIBRARY})
set(VILLASNODE_INCLUDE_DIRS ${VILLASNODE_INCLUDE_DIR})
......@@ -14,14 +14,29 @@ set(DPSIM_VERSION ${DPSIM_MAJOR_VERSION}.${DPSIM_MINOR_VERSION}.${DPSIM_PATCH_VE
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
# library configuration etc.
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/eigen)
set(EIGEN3_INCLUDE_DIR Libraries/eigen)
else()
find_package(Eigen3 REQUIRED)
set(Python_ADDITIONAL_VERSIONS 3.5 3.6 3.7)
find_package(Eigen3 3.0 REQUIRED)
find_package(CIMpp)
find_package(VILLASnode)
find_package(PythonInterp 3.5)
find_package(PythonLibs 3.5)
if(PythonInterp_FOUND AND PythonLibs_FOUND)
set(Python_FOUND ON)
endif()
if("${CMAKE_SYSTEM}" MATCHES "Linux")
set(Linux_FOUND ON)
endif()
include_directories(${EIGEN3_INCLUDE_DIR})
# Options
option(BUILD_SHARED_LIBS "Build shared library" OFF)
option(WITH_RT "Enable real-time features" ${Linux_FOUND})
option(WITH_SHMEM "Enable shared memory interface" ${VILLASnode_FOUND})
option(WITH_PYTHON "Enable Python support" ${Python_FOUND})
option(WITH_CIM "Enable support for parsing CIM files" ${CIMpp_FOUND})
add_subdirectory(Documentation)
add_subdirectory(Source)
......@@ -29,8 +44,13 @@ add_subdirectory(Examples/Cxx)
# Show feature summary
include(FeatureSummary)
feature_summary(WHAT ALL
VAR enabledFeaturesText)
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 "Execute simulation in real time")
feature_summary(WHAT ALL VAR enabledFeaturesText)
message(STATUS "${enabledFeaturesText}")
# CPack configuration
......
option(BUILD_SHARED_LIBS "Build shared library" OFF)
add_library(dpsim
IntegrationMethod.cpp
Logger.cpp
MathLibrary.cpp
Simulation.cpp
SystemModel.cpp
Utilities.cpp
)
list(APPEND SOURCES
Components/BaseComponent.cpp
Components/CapacitorDP.cpp
Components/CurrentSourceDP.cpp
Components/ExternalCurrentSource.cpp
Components/ExternalVoltageSource.cpp
Components/IdealTransformerDP.cpp
Components/IdealVoltageSourceDP.cpp
Components/IdealVoltageSourceEMT.cpp
Components/InductorDP.cpp
Components/InductorEMT.cpp
Components/InterfacedInductorDP.cpp
Components/PQLoadDP.cpp
Components/PiLineDP.cpp
Components/ResistorDP.cpp
Components/ResistorEMT.cpp
Components/RxLineDP.cpp
Components/SimplifiedSynGenEMT.cpp
Components/SimplifiedSynchronGeneratorEMT.cpp
Components/SynchGenBase.cpp
Components/SynchronGeneratorDP.cpp
Components/SynchronGeneratorEMT.cpp
Components/TransformerDP.cpp
Components/VoltSourceResDP.cpp
Components/VoltSourceResEMT.cpp
Components/VoltSourceResFreqDP.cpp
Components/VoltSourceResFreqEMT.cpp
Components/VoltageBehindReachtanceDP.cpp
Components/VoltageBehindReactanceEMT.cpp
)
find_package(Eigen3 REQUIRED)
set(INCLUDE_DIRS
${EIGEN3_INCLUDE_DIR}
)
if (NOT WIN32)
# needed so CIMParser and arabica (which are first compiled into static libs)
# can be included in the .so
set(CMAKE_CXX_FLAGS "-fPIC")
# we use PyArg_ParseTupleAndKeywords several times, which erroneously accepts
# a char* array instead of a const char* array
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-write-strings")
endif()
if(WIN32)
set(PYTHON_MODULE_SUFFIX "pyd")
set(ARABICA_XML_BACKEND USE_MSXML)
elseif(LINUX)
set(PYTHON_MODULE_SUFFIX "so")
set(LIBS "-lrt -lvillas-ext")
else(APPLE)
if(UNIX OR APPLE)
set(PYTHON_MODULE_SUFFIX "so")
elseif(WIN32)
set(PYTHON_MODULE_SUFFIX "pyd")
endif()
file(GLOB SOURCES *.cpp Components/*.cpp)
add_library(dpsim ${SOURCES})
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Python module
set(Python_ADDITIONAL_VERSIONS 3.5 3.6 3.7)
find_package(PythonInterp 3.5)
find_package(PythonLibs 3.5)
if(WITH_RT)
list(APPEND LIBRARIES "-lrt")
endif()
if(PythonInterp_FOUND AND PythonLibs_FOUND)
file(GLOB PYTHON_SOURCES Python/*.cpp)
target_sources(dpsim PUBLIC ${PYTHON_SOURCES})
if(WITH_SHMEM)
list(APPEND LIBRARIES ${VILLASNODE_LIBRARIES})
list(APPEND INCLUDE_DIRS ${VILLASNODE_INCLUDE_DIRS})
target_include_directories(dpsim PUBLIC ${PYTHON_INCLUDE_DIRS})
target_link_libraries(dpsim ${PYTHON_LIBRARIES})
list(APPEND SOURCES
ExternalInterface.cpp
ShmemInterface.cpp
)
endif()
if (WITH_PYTHON)
get_target_property(DPSIM_TYPE dpsim TYPE)
if(${DPSIM_TYPE} STREQUAL SHARED_LIBRARY)
add_custom_target(link_dpsim ALL DEPENDS dpsim COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE_NAME:dpsim> dpsim.${PYTHON_MODULE_SUFFIX})
list(APPEND SOURCES
Python/Component.cpp
Python/Module.cpp
Python/Simulation.cpp
Python/LoadCim.cpp
Python/Interface.cpp
)
list(APPEND INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})
list(APPEND LIBRARIES ${PYTHON_LIBRARIES})
add_custom_target(link_dpsim ALL DEPENDS dpsim COMMAND ${CMAKE_COMMAND} -E create_symlink $<TARGET_FILE_NAME:dpsim> dpsim.${PYTHON_MODULE_SUFFIX})
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_path('platlib'), end='')" OUTPUT_VARIABLE PYTHON_PKGPATH)
install(FILES $<TARGET_FILE:dpsim> DESTINATION ${PYTHON_PKGPATH} RENAME dpsim.${PYTHON_MODULE_SUFFIX})
......@@ -49,12 +92,15 @@ if(PythonInterp_FOUND AND PythonLibs_FOUND)
endif()
endif()
# CIMpp
find_package(CIMpp)
if(CIMpp_FOUND)
file(GLOB CIM_SOURCES CIM/*.cpp)
target_sources(dpsim PUBLIC ${CIM_SOURCES})
target_include_directories(dpsim PUBLIC ${CIMPP_INCLUDE_DIRS})
target_link_libraries(dpsim ${CIMPP_LIBRARIES})
if(WITH_CIM)
list(APPEND SOURCES CIM/Reader.cpp)
list(APPEND INCLUDE_DIRS ${CIMPP_INCLUDE_DIRS})
list(APPEND LIBRARIES ${CIMPP_LIBRARIES})
endif()
target_sources(dpsim PRIVATE ${SOURCES})
target_link_libraries(dpsim ${LIBRARIES})
target_include_directories(dpsim PRIVATE ${INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
configure_file(Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Config.h)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment