forked from Pyomo/pyomo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
172 lines (153 loc) · 5.92 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
cmake_minimum_required(VERSION 3.0)
# CMake 3.0 added GIT_SUBMODULES to ExternalProject_ADD, and without it
# the Ampl/MP checkout fails because one of the submodules (gecode) is a
# private repository.
PROJECT( pynumero )
include(ExternalProject)
# Targets in this project
OPTION(BUILD_ASL "Build the PyNumero ASL interface" ON)
OPTION(BUILD_MA27 "Build the PyNumero ma27 interface" OFF)
OPTION(BUILD_MA57 "Build the PyNumero ma57 interface" OFF)
# Dependencies that we manage / can install
SET(AMPLMP_TAG "3.1.0" CACHE STRING
"AMPL/MP git tag/branch to checkout and build")
OPTION(BUILD_AMPLMP
"Download and build AMPL/MP ${AMPLMP_TAG} from GitHub" OFF)
# Other build / environment options
OPTION(BUILD_AMPLMP_IF_NEEDED
"Automatically enable AMPLMP build if ASL not found" OFF)
MARK_AS_ADVANCED(BUILD_AMPLMP_IF_NEEDED)
#OPTION(STATIC_LINK "STATIC_LINK" OFF)
# If we build AMPLMP, then we will get a dependency on dlopen
FIND_LIBRARY(DL_LIBRARY dl)
# We need the ASL and HSL libraries. We can get them from Ipopt,
# AMPL/MP, or ASL (netlib)
SET(IPOPT_DIR "" CACHE PATH "Path to compiled Ipopt installation")
SET(AMPLMP_DIR "" CACHE PATH "Path to compiled AMPL/MP installation")
#SET(ASL_NETLIB_DIR "" CACHE PATH "Path to compiled ASL (netlib) installation")
# Use pkg-config to get the ASL/HSL directories from the Ipopt/COIN-OR build
FIND_PACKAGE(PkgConfig)
IF( PKG_CONFIG_FOUND )
SET(_TMP "$ENV{PKG_CONFIG_PATH}")
SET(ENV{PKG_CONFIG_PATH} "${IPOPT_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
pkg_check_modules(PC_COINASL QUIET coinasl)
pkg_check_modules(PC_COINHSL QUIET coinhsl)
SET(ENV{PKG_CONFIG_PATH} "${_TMP}")
ENDIF()
# Note: the directory search order is intentional: first the modules we
# are creating, then directories specifically set by the user, and
# finally automatically located installations (e.g., from pkg-config)
FIND_PATH(ASL_INCLUDE_DIR asl_pfgh.h
HINTS "${CMAKE_INSTALL_PREFIX}/include"
"${IPOPT_DIR}/include/coin-or/asl"
"${IPOPT_DIR}/include/coin/ThirdParty"
"${AMPLMP_DIR}/include"
"${PC_COINASL_INCLUDEDIR}"
"${PC_COINASL_INCLUDE_DIRS}"
PATH_SUFFIXES asl
)
FIND_LIBRARY(ASL_LIBRARY NAMES coinasl asl
HINTS "${CMAKE_INSTALL_PREFIX}/lib"
"${IPOPT_DIR}/lib"
"${AMPLMP_DIR}/lib"
"${PC_COINASL_LIBDIR}"
"${PC_COINASL_LIBRARY_DIRS}"
)
FIND_LIBRARY(HSL_LIBRARY NAMES coinhsl libcoinhsl
HINTS "${CMAKE_INSTALL_PREFIX}/lib"
"${IPOPT_DIR}/lib"
"${PC_COINHSL_LIBDIR}"
"${PC_COINHSL_LIBRARY_DIRS}"
)
# If BUILD_AMPLMP_IF_NEEDED is set and we couldn't find / weren't
# pointed to an ASL build, then we will forcibly enable the AMPLMP build
# to provide the ASL.
IF( BUILD_AMPLMP_IF_NEEDED AND (NOT ASL_LIBRARY OR NOT ASL_INCLUDE_DIR) )
set_property(CACHE BUILD_AMPLMP PROPERTY VALUE ON)
ENDIF()
IF( BUILD_AMPLMP )
get_filename_component(ABS_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE)
ExternalProject_Add(amplmp
GIT_TAG ${AMPLMP_TAG}
GIT_REPOSITORY https://github.com/ampl/mp.git
# We don't need *any* submodules, but leaving it as an empty string
# doesn't disable it as suggested by the documentation. A
# "workaround" from the web is to specify an existing directory that
# is *not* a submodule
GIT_SUBMODULES test
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:STRING=${ABS_INSTALL_PREFIX}
UPDATE_DISCONNECTED TRUE
# 3.1.0 needs to be patched to compile with recent compilers,
# notably ubuntu 18.04. The patch applies a backport of fmtlib/fmt
# abbefd7; see https://github.com/fmtlib/fmt/issues/398
PATCH_COMMAND git apply
${CMAKE_CURRENT_SOURCE_DIR}/amplmp-${AMPLMP_TAG}.patch
)
# Update the ASL paths (if necessary). Since these do not (yet)
# exist, we need to bypass find_path / find_library and explicitly set
# the directories that this build will create. However, we will only
# do this if the paths have not already been set (so users can always
# override what we do here)
IF(NOT ASL_INCLUDE_DIR OR NOT ASL_LIBRARY)
set_property(CACHE ASL_INCLUDE_DIR PROPERTY VALUE
"${ABS_INSTALL_PREFIX}/include/asl")
IF( WIN32 )
set_property(CACHE ASL_LIBRARY PROPERTY VALUE
"${ABS_INSTALL_PREFIX}/lib/asl.lib")
ELSE()
set_property(CACHE ASL_LIBRARY PROPERTY VALUE
"${ABS_INSTALL_PREFIX}/lib/libasl.a")
ENDIF()
ENDIF()
ENDIF()
set(PYNUMERO_ASL_SOURCES
"AmplInterface.cpp"
"AmplInterface.hpp"
"AssertUtils.hpp"
)
IF( BUILD_ASL )
ADD_LIBRARY( pynumero_ASL SHARED ${PYNUMERO_ASL_SOURCES} )
TARGET_LINK_LIBRARIES( pynumero_ASL PUBLIC ${ASL_LIBRARY} )
if ( DL_LIBRARY )
TARGET_LINK_LIBRARIES( pynumero_ASL PUBLIC ${DL_LIBRARY} )
ENDIF()
TARGET_INCLUDE_DIRECTORIES( pynumero_ASL
PUBLIC ${ASL_INCLUDE_DIR}
INTERFACE . )
TARGET_COMPILE_DEFINITIONS( pynumero_ASL PRIVATE BUILDING_PYNUMERO_ASL )
SET_TARGET_PROPERTIES( pynumero_ASL PROPERTIES ENABLE_EXPORTS 1 )
INSTALL( TARGETS pynumero_ASL LIBRARY DESTINATION lib
RUNTIME DESTINATION lib )
IF( BUILD_AMPLMP )
# If we are building AMPL/MP, it is possible that we are linking
# against it, so we will add the appropriate dependency
add_dependencies(pynumero_ASL amplmp)
ENDIF()
ENDIF()
#
# build hsl interfaces
#
set(PYNUMERO_MA27_SOURCES
"ma27Interface.c"
)
IF( BUILD_MA27 )
ADD_LIBRARY( pynumero_MA27 SHARED ${PYNUMERO_MA27_SOURCES} )
TARGET_LINK_LIBRARIES( pynumero_MA27 ${HSL_LIBRARY} )
SET_TARGET_PROPERTIES( pynumero_MA27 PROPERTIES ENABLE_EXPORTS 1 )
INSTALL(TARGETS pynumero_MA27 LIBRARY DESTINATION lib
RUNTIME DESTINATION lib )
ENDIF()
set(PYNUMERO_MA57_SOURCES
"ma57Interface.c"
)
IF( BUILD_MA57 )
ADD_LIBRARY( pynumero_MA57 SHARED ${PYNUMERO_MA57_SOURCES} )
TARGET_LINK_LIBRARIES( pynumero_MA57 ${HSL_LIBRARY} )
SET_TARGET_PROPERTIES( pynumero_MA57 PROPERTIES ENABLE_EXPORTS 1 )
INSTALL(TARGETS pynumero_MA57 LIBRARY DESTINATION lib
RUNTIME DESTINATION lib )
ENDIF()
#
# build the tests for the interfaces
#
add_subdirectory(tests)