-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
171 lines (143 loc) · 5.69 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
cmake_minimum_required(VERSION 3.15)
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()
project(GurobiLink)
string(TIMESTAMP BUILD_TIME "%d %b %Y at %H:%M")
set(GUROBI_VERSION "9.1.2" CACHE STRING "Gurobi version")
string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" GUROBI_MAJOR_VERSION ${GUROBI_VERSION})
string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" GUROBI_MINOR_VERSION ${GUROBI_VERSION})
string(REGEX REPLACE "\\." "" GUROBI_VER ${GUROBI_VERSION})
set(COMPONENTS_ROOT "/Components" CACHE PATH "Components location")
mark_as_advanced(COMPONENTS_ROOT)
set(INSTALL_PDB OFF CACHE BOOL "Include PDB file in paclet layout")
set(PACLET_VERSION 1.0.3 CACHE STRING "Paclet version")
set(TARGET_WOLFRAM_VERSION 12.3+ CACHE STRING "Target Wolfram version")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/install" CACHE PATH "Install prefix" FORCE)
endif()
set(GUROBI_DLL
${CMAKE_SHARED_LIBRARY_PREFIX}gurobi${GUROBI_MAJOR_VERSION}${GUROBI_MINOR_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}
)
set(GUROBI_LIB ${GUROBI_DLL})
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message(FATAL_ERROR "Only 64-bit platforms are supported by ${PROJECT_NAME}")
endif()
if(WIN32)
set(DEFAULT_SYSTEMID Windows-x86-64)
set(DEFAULT_PLATFORM win64)
set(QUALIFIER Win64)
string(REPLACE "${CMAKE_SHARED_LIBRARY_SUFFIX}" "${CMAKE_IMPORT_LIBRARY_SUFFIX}" GUROBI_LIB ${GUROBI_DLL})
set(WOLFRAM_INSTALLATION "C:/Program Files/Wolfram Research/Mathematica/12.3" CACHE PATH "Wolfram installation")
elseif(APPLE)
if(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
set(DEFAULT_SYSTEMID MacOSX-x86-64)
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "^arm64e?$")
set(DEFAULT_SYSTEMID MacOSX-ARM64)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(DEFAULT_SYSTEMID MacOSX-x86-64)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
set(DEFAULT_SYSTEMID MacOSX-ARM64)
endif()
if(DEFAULT_SYSTEMID STREQUAL "MacOSX-x86-64")
set(DEFAULT_PLATFORM mac64)
else()
set(DEFAULT_PLATFORM macos_universal2)
if(GUROBI_VERSION VERSION_LESS 9.1)
message(FATAL_ERROR "MacOSX-ARM64 is not supported by Gurobi ${GUROBI_VERSION}")
endif()
endif()
set(QUALIFIER Mac64)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
set(WOLFRAM_INSTALLATION "/Applications/Mathematica.app/Contents" CACHE PATH "Wolfram installation")
elseif(UNIX)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
message(FATAL_ERROR "Linux-ARM64 is not supported by ${PROJECT_NAME}")
endif()
set(DEFAULT_SYSTEMID Linux-x86-64)
set(DEFAULT_PLATFORM linux64)
set(QUALIFIER Lin64)
set(CMAKE_INSTALL_RPATH "\$ORIGIN")
set(WOLFRAM_INSTALLATION "/usr/local/Wolfram/Mathematica/12.3" CACHE PATH "Wolfram installation")
endif()
set(SYSTEMID ${DEFAULT_SYSTEMID} CACHE STRING "Machine SystemID")
set(PLATFORM ${DEFAULT_PLATFORM} CACHE STRING "Gurobi platform string")
find_path(DEFAULT_GUROBI_HOME
include/gurobi_c.h
PATHS
${COMPONENTS_ROOT}/Gurobi/${GUROBI_VERSION}
ENV GUROBI_HOME
C:/gurobi${GUROBI_VER}
/opt/gurobi${GUROBI_VER}
/Library/gurobi${GUROBI_VER}
PATH_SUFFIXES ${PLATFORM}
REQUIRED
NO_DEFAULT_PATH
)
set(GUROBI_HOME ${DEFAULT_GUROBI_HOME} CACHE PATH "Gurobi installation")
if(WIN32)
set(GUROBI_DLL_PATH "${GUROBI_HOME}/bin")
else()
set(GUROBI_DLL_PATH "${GUROBI_HOME}/lib")
endif()
set(GUROBI_LIBRARY_PATH "${GUROBI_HOME}/lib")
set(GUROBI_INCLUDE_PATH "${GUROBI_HOME}/include")
if(NOT WOLFRAM_INCLUDE_PATH)
set(WOLFRAM_INCLUDE_PATH "${WOLFRAM_INSTALLATION}/SystemFiles/IncludeFiles/C")
endif()
message(STATUS "WOLFRAM_INCLUDE_PATH: ${WOLFRAM_INCLUDE_PATH}")
message(STATUS "GUROBI_VERSION: ${GUROBI_VERSION}")
message(STATUS "GUROBI_INCLUDE_PATH: ${GUROBI_INCLUDE_PATH}")
message(STATUS "GUROBI_LIBRARY_PATH: ${GUROBI_LIBRARY_PATH}")
find_file(WOLFRAM_LIBRARY_HEADER "WolframLibrary.h" PATHS ${WOLFRAM_INCLUDE_PATH} REQUIRED NO_DEFAULT_PATH)
find_file(GUROBI_LIBRARY ${GUROBI_LIB} PATHS ${GUROBI_LIBRARY_PATH} REQUIRED NO_DEFAULT_PATH)
set(GUROBILINK_SOURCES
CSource/GurobiLink.cpp
CSource/GurobiSolution.cpp
)
set(PACLET_DESTINATION ${CMAKE_INSTALL_PREFIX}/${FULL} CACHE PATH "Full build destination")
set(PACLET_LIBDIR ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/LibraryResources/${SYSTEMID})
add_library(${PROJECT_NAME} SHARED ${GUROBILINK_SOURCES})
set_target_properties(${PROJECT_NAME} PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
PREFIX ""
)
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/CSource
${GUROBI_INCLUDE_PATH}
${WOLFRAM_INCLUDE_PATH}
)
target_link_directories(${PROJECT_NAME} PRIVATE ${GUROBI_LIBRARY_PATH})
target_link_libraries(${PROJECT_NAME} PRIVATE ${GUROBI_LIB})
target_compile_definitions(${PROJECT_NAME} PRIVATE "$<$<CONFIG:DEBUG>:DEBUG>")
if(APPLE)
execute_process(
COMMAND otool -D "${GUROBI_LIBRARY_PATH}/${GUROBI_LIB}"
OUTPUT_VARIABLE OTOOL_OUT
)
string(REGEX REPLACE "^.*:.|.$" "" GUROBI_LIB_INSTALL_NAME ${OTOOL_OUT})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND install_name_tool -change ${GUROBI_LIB_INSTALL_NAME} @loader_path/${GUROBI_LIB} $<TARGET_FILE:${PROJECT_NAME}>
COMMENT "Setting ${PROJECT_NAME} rpath for ${GUROBI_LIB}"
)
endif()
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${PACLET_LIBDIR}
RUNTIME DESTINATION ${PACLET_LIBDIR}
)
install(FILES
${GUROBI_DLL_PATH}/${GUROBI_DLL}
DESTINATION ${PACLET_LIBDIR}
)
if(INSTALL_PDB)
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION ${PACLET_LIBDIR} OPTIONAL)
endif()
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/PacletInfo.wl.in
${CMAKE_BINARY_DIR}/generated/PacletInfo.wl
)
set(WL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${PROJECT_NAME}.wl
${CMAKE_BINARY_DIR}/generated/PacletInfo.wl
)
install(FILES ${WL_SOURCES} DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME})