Skip to content

Commit

Permalink
Merge branch 'cmake-modular-dev' into 'master'
Browse files Browse the repository at this point in the history
Refactor CMake configuration

See merge request gridkit/gridkit!16
  • Loading branch information
Peles, Slaven committed Apr 6, 2021
2 parents adeaa6e + 16307e6 commit a84832b
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 159 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ macro(gridkit_add_library target)

add_library(GRIDKIT::${target} ALIAS ${_actual_target_name})

# Set output name
if(gridkit_add_library_OUTPUT_NAME)
set_target_properties(${_actual_target_name} PROPERTIES
OUTPUT_NAME ${gridkit_add_library_OUTPUT_NAME}
Expand All @@ -76,6 +77,12 @@ macro(gridkit_add_library target)
OUTPUT_NAME ${target}
CLEAN_DIRECT_OUTPUT 1)
endif()

# Set the library version
set_target_properties(${_actual_target_name} PROPERTIES
VERSION ${PACKAGE_VERSION}
SOVERSION ${PACKAGE_VERSION_MAJOR})

install(TARGETS ${_actual_target_name} DESTINATION lib EXPORT gridkit-targets)
endforeach()
endmacro()
Expand Down
44 changes: 19 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ set(PACKAGE_NAME "GRIDKIT")
set(PACKAGE_STRING "GRIDKIT 0.0.6")
set(PACKAGE_TARNAME "gridkit")

set(PACKAGE_VERSION_MAJOR "1")
set(PACKAGE_VERSION_MAJOR "0")
set(PACKAGE_VERSION_MINOR "0")
set(PACKAGE_VERSION_PATCH "6")

set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}")
set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}")

# Ipopt support is disabled by default
option(GRIDKIT_ENABLE_IPOPT "Enable Ipopt support" ON)
Expand All @@ -84,7 +85,7 @@ option(GRIDKIT_ENABLE_SUNDIALS_SPARSE "Enable SUNDIALS sparse linear solvers" ON

set(CMAKE_MACOSX_RPATH 1)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/config)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake)

# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath
# use, i.e. don't skip the full RPATH for the build tree
Expand Down Expand Up @@ -129,25 +130,29 @@ endif()
if(GRIDKIT_ENABLE_SUNDIALS_SPARSE)
include(FindSuiteSparse)
endif()
# Set up configuration header file
# configure_file(gridkit_config.h.in gridkit_config.h)

# Macro that adds libraries
include(GridkitAddLibrary)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Create component models
add_subdirectory(ComponentLib)
add_subdirectory(Solver)
add_subdirectory(Examples)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Create solvers
add_subdirectory(Solver)

export(EXPORT gridkit-targets FILE "${CMAKE_CURRENT_BINARY_DIR}/GridKitTargets.cmake")
# Create examples and tests
enable_testing()
add_subdirectory(Examples)

export(EXPORT gridkit-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/GridKitTargets.cmake)

# Configuring exporting cmake config
install(EXPORT gridkit-targets
FILE GridKitTargets.cmake
NAMESPACE GRIDKIT::
DESTINATION lib/cmake/gridkit)
DESTINATION share/cmake/gridkit)

include(CMakePackageConfigHelpers)

Expand All @@ -158,25 +163,14 @@ write_basic_package_version_file(
COMPATIBILITY SameMajorVersion)

# Generate config file that includes exports
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/config/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/GridKitConfig.cmake"
INSTALL_DESTINATION "lib/cmake/gridkit"
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/GridKitConfig.cmake
INSTALL_DESTINATION share/cmake/gridkit
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

# Install configuration file
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/GridKitConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/GridKitConfigVersion.cmake
DESTINATION lib/cmake/gridkit)

# TESTING
enable_testing()
add_test(NAME AdjointSens COMMAND $<TARGET_FILE:adjoint> )
add_test(NAME Grid3Bus COMMAND $<TARGET_FILE:grid3bus>)
if(GRIDKIT_ENABLE_IPOPT)
add_test(NAME DynamicConOpt COMMAND $<TARGET_FILE:dynconopt> )
add_test(NAME GenConstLoad COMMAND $<TARGET_FILE:genconstload>)
add_test(NAME GenInfiniteBus COMMAND $<TARGET_FILE:geninfbus> )
add_test(NAME ParameterEst COMMAND $<TARGET_FILE:paramest> ${CMAKE_SOURCE_DIR}/Examples/ParameterEstimation/lookup_table.dat)
endif()
DESTINATION share/cmake/gridkit)
3 changes: 3 additions & 0 deletions Examples/AdjointSensitivity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ add_executable(adjoint AdjointSensitivity.cpp)
target_link_libraries(adjoint GRIDKIT::bus GRIDKIT::generator4 GRIDKIT::solvers_dyn)
install(TARGETS adjoint DESTINATION bin)

add_test(NAME AdjointSens COMMAND $<TARGET_FILE:adjoint> )


19 changes: 12 additions & 7 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@
# endorsement purposes.
#

add_subdirectory(AdjointSensitivity)
add_subdirectory(Grid3Bus)
if(GRIDKIT_ENABLE_IPOPT)
add_subdirectory(DynamicConstrainedOpt)
add_subdirectory(GenConstLoad)
add_subdirectory(GenInfiniteBus)
add_subdirectory(ParameterEstimation)
if(TARGET SUNDIALS::kinsol)
add_subdirectory(Grid3Bus)
endif()

if(TARGET SUNDIALS::idas)
add_subdirectory(AdjointSensitivity)
if(GRIDKIT_ENABLE_IPOPT)
add_subdirectory(DynamicConstrainedOpt)
add_subdirectory(GenConstLoad)
add_subdirectory(GenInfiniteBus)
add_subdirectory(ParameterEstimation)
endif()
endif()
1 change: 1 addition & 0 deletions Examples/DynamicConstrainedOpt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ add_executable(dynconopt DynamicConstrainedOpt.cpp)
target_link_libraries(dynconopt GRIDKIT::generator4 GRIDKIT::generator2 GRIDKIT::bus GRIDKIT::solvers_dyn GRIDKIT::solvers_opt)
install(TARGETS dynconopt DESTINATION bin)

add_test(NAME DynamicConOpt COMMAND $<TARGET_FILE:dynconopt>)
2 changes: 2 additions & 0 deletions Examples/GenConstLoad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@
add_executable(genconstload GenConstLoad.cpp)
target_link_libraries(genconstload GRIDKIT::generator4governor GRIDKIT::bus GRIDKIT::load GRIDKIT::solvers_dyn GRIDKIT::solvers_opt)
install(TARGETS genconstload DESTINATION bin)

add_test(NAME GenConstLoad COMMAND $<TARGET_FILE:genconstload>)
1 change: 1 addition & 0 deletions Examples/GenInfiniteBus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ add_executable(geninfbus GenInfiniteBus.cpp)
target_link_libraries(geninfbus GRIDKIT::bus GRIDKIT::generator4 GRIDKIT::solvers_opt GRIDKIT::solvers_dyn)
install(TARGETS geninfbus DESTINATION bin)

add_test(NAME GenInfiniteBus COMMAND $<TARGET_FILE:geninfbus>)
2 changes: 2 additions & 0 deletions Examples/Grid3Bus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@
add_executable(grid3bus Grid3BusSys.cpp)
target_link_libraries(grid3bus GRIDKIT::minigrid GRIDKIT::bus GRIDKIT::branch GRIDKIT::load GRIDKIT::solvers_steady)
install(TARGETS grid3bus RUNTIME DESTINATION bin)

add_test(NAME Grid3Bus COMMAND $<TARGET_FILE:grid3bus>)
119 changes: 0 additions & 119 deletions Examples/Grid3Bus/Grid3Bus.cpp

This file was deleted.

2 changes: 2 additions & 0 deletions Examples/ParameterEstimation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ add_executable(paramest ParameterEstimation.cpp)
target_link_libraries(paramest GRIDKIT::bus GRIDKIT::generator4param GRIDKIT::solvers_opt GRIDKIT::solvers_dyn)
install(TARGETS paramest RUNTIME DESTINATION bin)
install(FILES lookup_table.dat DESTINATION bin)

add_test(NAME ParameterEst COMMAND $<TARGET_FILE:paramest> ${CMAKE_SOURCE_DIR}/Examples/ParameterEstimation/lookup_table.dat)
14 changes: 10 additions & 4 deletions Solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@
# [[
# Author(s):
# - Cameron Rutherford <[email protected]>
# - Slaven Peles <[email protected]>
#]]

add_subdirectory(Dynamic)
add_subdirectory(SteadyState)
if(GRIDKIT_ENABLE_IPOPT)
add_subdirectory(Optimization)
if(TARGET SUNDIALS::kinsol)
add_subdirectory(SteadyState)
endif()

if(TARGET SUNDIALS::idas)
add_subdirectory(Dynamic)
if(GRIDKIT_ENABLE_IPOPT)
add_subdirectory(Optimization)
endif()
endif()
2 changes: 0 additions & 2 deletions Solver/Dynamic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ gridkit_add_library(solvers_dyn
LINK_LIBRARIES
PUBLIC SUNDIALS::nvecserial
PUBLIC SUNDIALS::idas
PUBLIC SUNDIALS::kinsol
PUBLIC IPOPT
OUTPUT_NAME
gridkit_solvers_dyn)

2 changes: 0 additions & 2 deletions Solver/Optimization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ gridkit_add_library(solvers_opt
DynamicObjective.cpp
DynamicConstraint.cpp
LINK_LIBRARIES
PUBLIC SUNDIALS::nvecserial
PUBLIC SUNDIALS::idas
PUBLIC IPOPT
PUBLIC GRIDKIT::solvers_dyn
OUTPUT_NAME
Expand Down

0 comments on commit a84832b

Please sign in to comment.