forked from google/or-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glop.cmake
381 lines (362 loc) · 11.9 KB
/
glop.cmake
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# Copyright 2010-2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if(NOT BUILD_GLOP)
return()
endif()
# Generate Protobuf cpp sources
set(PROTO_HDRS)
set(PROTO_SRCS)
set(proto_files
"ortools/linear_solver/linear_solver.proto"
"ortools/glop/parameters.proto"
"ortools/util/optional_boolean.proto"
)
## Get Protobuf include dir
get_target_property(protobuf_dirs protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
foreach(dir IN LISTS protobuf_dirs)
if (NOT "${dir}" MATCHES "INSTALL_INTERFACE|-NOTFOUND")
message(STATUS "Adding proto path: ${dir}")
list(APPEND PROTO_DIRS "--proto_path=${dir}")
endif()
endforeach()
foreach(PROTO_FILE IN LISTS proto_files)
#message(STATUS "protoc proto(cc): ${PROTO_FILE}")
get_filename_component(PROTO_DIR ${PROTO_FILE} DIRECTORY)
get_filename_component(PROTO_NAME ${PROTO_FILE} NAME_WE)
set(PROTO_HDR ${PROJECT_BINARY_DIR}/${PROTO_DIR}/${PROTO_NAME}.pb.h)
set(PROTO_SRC ${PROJECT_BINARY_DIR}/${PROTO_DIR}/${PROTO_NAME}.pb.cc)
#message(STATUS "protoc hdr: ${PROTO_HDR}")
#message(STATUS "protoc src: ${PROTO_SRC}")
add_custom_command(
OUTPUT ${PROTO_SRC} ${PROTO_HDR}
COMMAND ${PROTOC_PRG}
"--proto_path=${PROJECT_SOURCE_DIR}"
${PROTO_DIRS}
"--cpp_out=${PROJECT_BINARY_DIR}"
${PROTO_FILE}
DEPENDS ${PROTO_FILE} ${PROTOC_PRG}
COMMENT "Generate C++ protocol buffer for ${PROTO_FILE}"
VERBATIM)
list(APPEND PROTO_HDRS ${PROTO_HDR})
list(APPEND PROTO_SRCS ${PROTO_SRC})
endforeach()
list(APPEND GLOP_COMPILE_DEFINITIONS
"-DOR_TOOLS_MAJOR=${PROJECT_VERSION_MAJOR}"
"-DOR_TOOLS_MINOR=${PROJECT_VERSION_MINOR}"
"-DOR_TOOLS_PATCH=${PROJECT_VERSION_PATCH}"
)
add_library(glop_proto OBJECT ${PROTO_SRCS} ${PROTO_HDRS})
set_target_properties(glop_proto PROPERTIES
POSITION_INDEPENDENT_CODE ON
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)
target_include_directories(glop_proto PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR}
$<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>
)
target_compile_definitions(glop_proto PUBLIC ${GLOP_COMPILE_DEFINITIONS})
target_compile_options(glop_proto PUBLIC ${GLOP_COMPILE_OPTIONS})
target_link_libraries(glop_proto PRIVATE protobuf::libprotobuf)
# Main Target
add_library(glop)
target_sources(glop PRIVATE
ortools/base/commandlineflags.h
ortools/base/file.cc
ortools/base/file.h
ortools/base/integral_types.h
ortools/base/logging.h
ortools/base/macros.h
ortools/base/sysinfo.cc
ortools/base/sysinfo.h
ortools/base/version.cc
ortools/base/version.h
ortools/base/vlog_is_on.cc
ortools/base/vlog_is_on.h
ortools/glop/basis_representation.cc
ortools/glop/basis_representation.h
ortools/glop/dual_edge_norms.cc
ortools/glop/dual_edge_norms.h
ortools/glop/entering_variable.cc
ortools/glop/entering_variable.h
ortools/glop/initial_basis.cc
ortools/glop/initial_basis.h
ortools/glop/lp_solver.cc
ortools/glop/lp_solver.h
ortools/glop/lu_factorization.cc
ortools/glop/lu_factorization.h
ortools/glop/markowitz.cc
ortools/glop/markowitz.h
ortools/glop/preprocessor.cc
ortools/glop/preprocessor.h
ortools/glop/primal_edge_norms.cc
ortools/glop/primal_edge_norms.h
ortools/glop/reduced_costs.cc
ortools/glop/reduced_costs.h
ortools/glop/revised_simplex.cc
ortools/glop/revised_simplex.h
ortools/glop/status.cc
ortools/glop/status.h
ortools/glop/update_row.cc
ortools/glop/update_row.h
ortools/glop/variable_values.cc
ortools/glop/variable_values.h
ortools/glop/variables_info.cc
ortools/glop/variables_info.h
ortools/lp_data/lp_data.cc
ortools/lp_data/lp_data.h
ortools/lp_data/lp_data_utils.cc
ortools/lp_data/lp_data_utils.h
ortools/lp_data/lp_print_utils.cc
ortools/lp_data/lp_print_utils.h
ortools/lp_data/lp_types.cc
ortools/lp_data/lp_types.h
ortools/lp_data/lp_utils.cc
ortools/lp_data/lp_utils.h
ortools/lp_data/matrix_scaler.cc
ortools/lp_data/matrix_scaler.h
ortools/lp_data/matrix_utils.cc
ortools/lp_data/matrix_utils.h
ortools/lp_data/proto_utils.cc
ortools/lp_data/proto_utils.h
ortools/lp_data/sparse.cc
ortools/lp_data/sparse.h
ortools/lp_data/sparse_column.cc
ortools/port/sysinfo.h
ortools/port/sysinfo.cc
ortools/util/file_util.cc
ortools/util/file_util.h
ortools/util/fp_utils.cc
ortools/util/fp_utils.h
ortools/util/logging.cc
ortools/util/logging.h
ortools/util/rational_approximation.cc
ortools/util/rational_approximation.h
ortools/util/stats.cc
ortools/util/stats.h
ortools/util/strong_integers.h
ortools/util/time_limit.cc
ortools/util/time_limit.h
)
if(BUILD_LP_PARSER)
target_sources(glop PRIVATE
ortools/base/case.cc
ortools/base/case.h
ortools/lp_data/lp_parser.cc
ortools/lp_data/lp_parser.h)
endif()
if(WIN32)
list(APPEND GLOP_COMPILE_DEFINITIONS "__WIN32__")
endif()
if(MSVC)
list(APPEND GLOP_COMPILE_OPTIONS
"/bigobj" # Allow big object
"/DNOMINMAX"
"/DWIN32_LEAN_AND_MEAN=1"
"/D_CRT_SECURE_NO_WARNINGS"
"/D_CRT_SECURE_NO_DEPRECATE"
"/MP" # Build with multiple processes
"/DNDEBUG"
)
# MSVC warning suppressions
list(APPEND GLOP_COMPILE_OPTIONS
"/wd4005" # 'macro-redefinition'
"/wd4018" # 'expression' : signed/unsigned mismatch
"/wd4065" # switch statement contains 'default' but no 'case' labels
"/wd4068" # 'unknown pragma'
"/wd4101" # 'identifier' : unreferenced local variable
"/wd4146" # unary minus operator applied to unsigned type, result still unsigned
"/wd4200" # nonstandard extension used : zero-sized array in struct/union
"/wd4244" # 'conversion' conversion from 'type1' to 'type2', possible loss of data
"/wd4251" # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
"/wd4267" # 'var' : conversion from 'size_t' to 'type', possible loss of data
"/wd4305" # 'identifier' : truncation from 'type1' to 'type2'
"/wd4307" # 'operator' : integral constant overflow
"/wd4309" # 'conversion' : truncation of constant value
"/wd4334" # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
"/wd4355" # 'this' : used in base member initializer list
"/wd4477" # 'fwprintf' : format string '%s' requires an argument of type 'wchar_t *'
"/wd4506" # no definition for inline function 'function'
"/wd4715" # function' : not all control paths return a value
"/wd4800" # 'type' : forcing value to bool 'true' or 'false' (performance warning)
"/wd4996" # The compiler encountered a deprecated declaration.
)
else()
list(APPEND GLOP_COMPILE_OPTIONS "-fwrapv")
endif()
# Includes
target_include_directories(glop PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
# Compile options
set_target_properties(glop PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
)
target_compile_features(glop PUBLIC cxx_std_17)
target_compile_definitions(glop PUBLIC ${GLOP_COMPILE_DEFINITIONS})
target_compile_options(glop PUBLIC ${GLOP_COMPILE_OPTIONS})
# Properties
if(NOT APPLE)
set_target_properties(glop PROPERTIES VERSION ${PROJECT_VERSION})
else()
# Clang don't support version x.y.z with z > 255
set_target_properties(glop PROPERTIES
INSTALL_RPATH "@loader_path"
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
endif()
set_target_properties(glop PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
)
set_target_properties(glop PROPERTIES INTERFACE_glop_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
set_target_properties(glop PROPERTIES COMPATIBLE_INTERFACE_STRING glop_MAJOR_VERSION)
# Dependencies
target_sources(glop PRIVATE $<TARGET_OBJECTS:glop_proto>)
add_dependencies(glop glop_proto)
target_link_libraries(glop PUBLIC
absl::memory
absl::hash
absl::flags
absl::log
absl::log_globals
absl::log_initialize
absl::check
absl::die_if_null
absl::status
absl::time
absl::strings
absl::statusor
absl::str_format
protobuf::libprotobuf
${RE2_DEPS}
)
if(WIN32)
#target_link_libraries(glop PUBLIC psapi.lib ws2_32.lib)
endif()
# ALIAS
add_library(${PROJECT_NAME}::glop ALIAS glop)
# Install rules
include(GNUInstallDirs)
include(GenerateExportHeader)
GENERATE_EXPORT_HEADER(glop)
install(FILES ${PROJECT_BINARY_DIR}/glop_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ortools/glop
COMPONENT Devel)
install(TARGETS glop
EXPORT glopTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(EXPORT glopTargets
NAMESPACE ortools::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/glop)
# glop headers
install(DIRECTORY ortools/glop
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ortools
COMPONENT Devel
FILES_MATCHING
PATTERN "*.h")
# dependencies headers
install(FILES
ortools/base/accurate_sum.h
ortools/base/basictypes.h
ortools/base/commandlineflags.h
ortools/base/file.h
ortools/base/hash.h
ortools/base/int_type.h
ortools/base/strong_int.h
ortools/base/strong_vector.h
ortools/base/integral_types.h
ortools/base/logging.h
ortools/base/macros.h
ortools/base/recordio.h
ortools/base/sysinfo.h
ortools/base/timer.h
ortools/base/vlog_is_on.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ortools/base
COMPONENT Devel)
install(FILES
ortools/lp_data/lp_data.h
ortools/lp_data/permutation.h
ortools/lp_data/scattered_vector.h
ortools/lp_data/sparse_column.h
ortools/lp_data/sparse_row.h
ortools/lp_data/sparse_vector.h
ortools/lp_data/lp_types.h
ortools/lp_data/lp_utils.h
ortools/lp_data/lp_print_utils.h
ortools/lp_data/matrix_scaler.h
ortools/lp_data/matrix_utils.h
ortools/lp_data/proto_utils.h
ortools/lp_data/sparse.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ortools/lp_data
COMPONENT Devel)
install(FILES
ortools/graph/iterators.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ortools/graph
COMPONENT Devel)
install(FILES
ortools/port/sysinfo.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ortools/port
COMPONENT Devel)
install(FILES
ortools/util/bitset.h
ortools/util/file_util.h
ortools/util/fp_utils.h
ortools/util/logging.h
ortools/util/random_engine.h
ortools/util/rational_approximation.h
ortools/util/return_macros.h
ortools/util/running_stat.h
ortools/util/stats.h
ortools/util/strong_integers.h
ortools/util/time_limit.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ortools/util
COMPONENT Devel)
# proto headers
install(FILES
${PROJECT_BINARY_DIR}/ortools/glop/parameters.pb.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ortools/glop
COMPONENT Devel)
install(FILES
${PROJECT_BINARY_DIR}/ortools/linear_solver/linear_solver.pb.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ortools/linear_solver
COMPONENT Devel)
install(FILES
${PROJECT_BINARY_DIR}/ortools/util/optional_boolean.pb.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ortools/util
COMPONENT Devel)
include(CMakePackageConfigHelpers)
string (TOUPPER "glop" PACKAGE_PREFIX)
configure_package_config_file(cmake/glopConfig.cmake.in
"${PROJECT_BINARY_DIR}/glopConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/glop"
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/glopConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)
install(
FILES
"${PROJECT_BINARY_DIR}/glopConfig.cmake"
"${PROJECT_BINARY_DIR}/glopConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/glop"
COMPONENT Devel)