Skip to content

Commit 49ad14b

Browse files
committed
ipopt cmake settings
1 parent 4d5fec1 commit 49ad14b

6 files changed

Lines changed: 39 additions & 24 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ endif("${isSystemDir}" STREQUAL "-1")
126126
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
127127

128128
if(GRIDKIT_ENABLE_IPOPT)
129-
include(FindIpopt)
129+
find_package(Ipopt REQUIRED)
130130
enable_language(Fortran) # Needed for linking to HSL
131131
endif()
132132

@@ -217,7 +217,10 @@ configure_package_config_file(
217217
INSTALL_DESTINATION share/cmake/gridkit
218218
NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)
219219

220+
# Make the dependency finder available beside the generated package config.
221+
configure_file(cmake/FindIpopt.cmake ${CMAKE_CURRENT_BINARY_DIR}/FindIpopt.cmake COPYONLY)
222+
220223
# Install configuration file
221224
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/GridKitConfig.cmake
222225
${CMAKE_CURRENT_BINARY_DIR}/GridKitConfigVersion.cmake
223-
DESTINATION share/cmake/gridkit)
226+
${CMAKE_CURRENT_BINARY_DIR}/FindIpopt.cmake DESTINATION share/cmake/gridkit)

‎cmake/Config.cmake.in‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55

66
@PACKAGE_INIT@
77

8-
include ( "${CMAKE_CURRENT_LIST_DIR}/GridKitTargets.cmake" )
9-
108
include(CMakeFindDependencyMacro)
119
set(GridKit_ENABLE_SUNDIALS @GRIDKIT_ENABLE_SUNDIALS@)
1210
if(GridKit_ENABLE_SUNDIALS)
1311
list(APPEND CMAKE_PREFIX_PATH @SUNDIALS_DIR@)
1412
enable_language(C)
1513
find_dependency(SUNDIALS)
1614
endif()
15+
16+
set(GridKit_ENABLE_IPOPT @GRIDKIT_ENABLE_IPOPT@)
17+
if(GridKit_ENABLE_IPOPT AND NOT TARGET IPOPT)
18+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
19+
find_dependency(Ipopt MODULE)
20+
endif()
21+
22+
include("${CMAKE_CURRENT_LIST_DIR}/GridKitTargets.cmake")

‎cmake/FindIpopt.cmake‎

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
#[[
33
4-
Finds Ipopt include directory and libraries and exports target `Ipopt`
4+
Finds Ipopt include directory and libraries and exports target `IPOPT`
55
66
User may set:
77
- IPOPT_ROOT_DIR
@@ -26,7 +26,6 @@ find_library(
2626

2727
if(IPOPT_LIBRARY)
2828
set(IPOPT_LIBRARY CACHE FILEPATH "Path to Ipopt library")
29-
message(STATUS "Found Ipopt library: " ${IPOPT_LIBRARY})
3029
get_filename_component(
3130
IPOPT_LIBRARY_DIR
3231
${IPOPT_LIBRARY}
@@ -56,25 +55,12 @@ find_path(
5655
include/coin-or
5756
include/coinor)
5857

59-
if(IPOPT_LIBRARY)
60-
message(STATUS "Found Ipopt include: ${IPOPT_INCLUDE_DIR}")
61-
mark_as_advanced(IPOPT_INCLUDE_DIR)
58+
include(FindPackageHandleStandardArgs)
59+
find_package_handle_standard_args(Ipopt REQUIRED_VARS IPOPT_LIBRARY IPOPT_INCLUDE_DIR)
60+
mark_as_advanced(IPOPT_LIBRARY IPOPT_INCLUDE_DIR)
61+
62+
if(Ipopt_FOUND AND NOT TARGET IPOPT)
6263
add_library(IPOPT INTERFACE IMPORTED)
6364
target_link_libraries(IPOPT INTERFACE ${IPOPT_LIBRARY})
6465
target_include_directories(IPOPT INTERFACE ${IPOPT_INCLUDE_DIR})
65-
else()
66-
if(NOT IPOPT_ROOT_DIR)
67-
message(STATUS "Ipopt dir not found! Please provide correct filepath.")
68-
set(IPOPT_DIR
69-
${IPOPT_DIR}
70-
CACHE PATH "Path to Ipopt installation root.")
71-
unset(IPOPT_INCLUDE_DIR CACHE)
72-
unset(IPOPT_LIBRARY CACHE)
73-
unset(IPOPT_LIBRARY_DIR CACHE)
74-
elseif(NOT IPOPT_LIB)
75-
message(STATUS "Ipopt library not found! Please provide correct filepath.")
76-
endif()
77-
if(IPOPT_ROOT_DIR AND NOT IPOPT_INCLUDE_DIR)
78-
message(STATUS "Ipopt include directory not found! Please provide correct path.")
79-
endif()
8066
endif()

‎examples/Consumer/CMakeLists.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ else()
3636
GridKit::power_elec_microload)
3737
endif()
3838

39+
if(GRIDKIT_ENABLE_ENZYME AND GRIDKIT_ENABLE_IPOPT)
40+
install(FILES ${CMAKE_SOURCE_DIR}/tests/UnitTests/OptimalPowerFlow/runSystemTests.cpp
41+
${CMAKE_SOURCE_DIR}/tests/UnitTests/OptimalPowerFlow/SystemTests.hpp
42+
DESTINATION ${_rel_consumer_path}/OptimalPowerFlow)
43+
endif()
44+
3945
# Install CMakeLists.txt for example project
4046
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/GridKitConsumer/CMakeLists.txt.in
4147
${CMAKE_CURRENT_BINARY_DIR}/GridKitConsumer/CMakeLists.txt @ONLY)

‎examples/Consumer/GridKitConsumer/CMakeLists.txt.in‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ include(CTest)
2828
add_test(NAME GridKitConsumer
2929
COMMAND consumer
3030
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
31+
32+
if(TARGET GridKit::optimal_power_flow_systemmodel_dependency_tracking
33+
AND TARGET GridKit::solvers_opt_steady)
34+
add_executable(opf_consumer OptimalPowerFlow/runSystemTests.cpp)
35+
target_link_libraries(
36+
opf_consumer
37+
GridKit::optimal_power_flow_systemmodel
38+
GridKit::optimal_power_flow_systemmodel_dependency_tracking
39+
GridKit::solvers_opt_steady
40+
GridKit::testing)
41+
add_test(NAME GridKitOPFConsumer COMMAND opf_consumer)
42+
endif()

‎examples/EconomicDispatch/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Input paths are relative to the solver file; output is relative to the working
3838
directory. Missing state values use the case operating point; supplied currents
3939
must include both `ir` and `ii`.
4040

41+
Machines marked `online: false` in the input state are currently rejected.
42+
4143
Case device | Optimal power flow component
4244
---------------------------------------------|-----------------------------
4345
`Bus`, `BusInfinite` | `Bus`, infinite for `BusInfinite`

0 commit comments

Comments
 (0)