forked from google/or-tools
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile.cpp.mk
680 lines (604 loc) · 21.3 KB
/
Makefile.cpp.mk
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
# Copyright 2010-2024 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.
# ---------- C++ support ----------
.PHONY: help_cpp # Generate list of C++ targets with descriptions.
help_cpp:
@echo Use one of the following C++ targets:
ifeq ($(PLATFORM),WIN64)
@$(GREP) "^.PHONY: .* #" $(CURDIR)/makefiles/Makefile.cpp.mk | $(SED) "s/\.PHONY: \(.*\) # \(.*\)/\1\t\2/"
@echo off & echo(
else
@$(GREP) "^.PHONY: .* #" $(CURDIR)/makefiles/Makefile.cpp.mk | $(SED) "s/\.PHONY: \(.*\) # \(.*\)/\1\t\2/" | expand -t20
@echo
endif
# Checks if the user has overwritten default install prefix.
# cf https://www.gnu.org/prep/standards/html_node/Directory-Variables.html#index-prefix
ifeq ($(PLATFORM),WIN64)
prefix ?= C:\\Program Files\\or-tools
else
prefix ?= /usr/local
endif
# Checks if the user has overwritten default libraries and binaries.
BUILD_TYPE ?= Release
USE_COINOR ?= ON
USE_GLPK ?= OFF
USE_HIGHS ?= OFF
USE_PDLP := ON # OFF not supported
USE_SCIP ?= ON
USE_CPLEX ?= OFF
USE_DOTNET_CORE_31 ?= OFF
USE_DOTNET_6 ?= ON
BUILD_VENV ?= ON
JOBS ?= 4
# Main targets.
.PHONY: detect_cpp # Show variables used to build C++ OR-Tools.
.PHONY: third_party # Build OR-Tools Prerequisite
.PHONY: cpp # Build C++ OR-Tools library.
.PHONY: check_cpp # Run all C++ OR-Tools samples and examples targets.
.PHONY: test_cpp # Run all C++ OR-Tools test targets.
.PHONY: test_fz # Run all Flatzinc test targets.
.PHONY: archive_cpp # Add C++ OR-Tools to archive.
.PHONY: clean_cpp # Clean C++ output from previous build.
GENERATOR ?= $(CMAKE_PLATFORM)
third_party:
cmake -S . -B $(BUILD_DIR) -DBUILD_DEPS=ON \
-DBUILD_DOTNET=$(BUILD_DOTNET) \
-DBUILD_JAVA=$(BUILD_JAVA) \
-DBUILD_PYTHON=$(BUILD_PYTHON) \
-DBUILD_EXAMPLES=OFF \
-DBUILD_SAMPLES=OFF \
-DBUILD_TESTING=OFF \
-DUSE_COINOR=$(USE_COINOR) \
-DUSE_GLPK=$(USE_GLPK) \
-DUSE_HIGHS=$(USE_HIGHS) \
-DUSE_PDLP=$(USE_PDLP) \
-DUSE_SCIP=$(USE_SCIP) \
-DUSE_CPLEX=$(USE_CPLEX) \
-DUSE_DOTNET_CORE_31=$(USE_DOTNET_CORE_31) \
-DUSE_DOTNET_6=$(USE_DOTNET_6) \
-DBUILD_VENV=$(BUILD_VENV) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) \
$(CMAKE_ARGS) \
-G $(GENERATOR)
# OR Tools unique library.
cpp:
$(MAKE) third_party
cmake --build $(BUILD_DIR) --target install --config $(BUILD_TYPE) -j $(JOBS) -v
check_cpp: check_cpp_pimpl
test_cpp: \
cpp \
test_cc_tests \
test_cc_contrib \
test_cc_cpp
test_fz: \
cpp \
rfz_golomb \
rfz_alpha
TEMP_CPP_DIR := temp_cpp
$(TEMP_CPP_DIR):
$(MKDIR) $(TEMP_CPP_DIR)
# Deprecated alias
.PHONY: help_cc
help_cc: help_cpp
$(warning $@ is deprecated please use $< instead.)
.PHONY: detect_cc
detect_cc: detect_cpp
$(warning $@ is deprecated please use $< instead.)
.PHONY: cc
cc: cpp
$(warning $@ is deprecated please use @< instead.)
.PHONY: check_cc
check_cc: check_cpp
$(warning $@ is deprecated please use $< instead.)
.PHONY: check_cpp_%
check_cc_%: check_cpp_%
$(warning $@ is deprecated please use @< instead.)
.PHONY: test_cc
test_cc: test_cpp
$(warning $@ is deprecated please use @< instead.)
.PHONY: test_cc_%
test_cc_%: test_cpp_%
$(warning $@ is deprecated please use @< instead.)
.PHONY: package_cpp
package_cpp: archive_cpp
.PHONY: package_cc
package_cc: package_cpp
$(warning $@ is deprecated please use @< instead.)
.PHONY: clean_cc
clean_cc: clean_cpp
$(warning $@ is deprecated please use $< instead.)
# Now flatzinc is build with cpp
fz: cpp
$(warning $@ is deprecated please use $< instead.)
##################
## C++ SOURCE ##
##################
ifeq ($(SOURCE_SUFFIX),.cc) # Those rules will be used if SOURCE contain a .cc file
SOURCE_PROJECT_DIR := $(SOURCE)
SOURCE_PROJECT_DIR := $(subst /$(SOURCE_NAME).cc,, $(SOURCE_PROJECT_DIR))
SOURCE_PROJECT_PATH = $(subst /,$S,$(SOURCE_PROJECT_DIR))
$(TEMP_CPP_DIR)/$(SOURCE_NAME): | $(TEMP_CPP_DIR)
$(MKDIR) $(TEMP_CPP_DIR)$S$(SOURCE_NAME)
$(TEMP_CPP_DIR)/$(SOURCE_NAME)/CMakeLists.txt: ${SRC_DIR}/ortools/cpp/CMakeLists.txt.in | $(TEMP_CPP_DIR)/$(SOURCE_NAME)
$(COPY) ortools$Scpp$SCMakeLists.txt.in $(TEMP_CPP_DIR)$S$(SOURCE_NAME)$SCMakeLists.txt
$(SED) -i -e 's/@CPP_NAME@/$(SOURCE_NAME)/' \
$(TEMP_CPP_DIR)$S$(SOURCE_NAME)$SCMakeLists.txt
$(SED) -i -e 's/@CPP_FILE_NAME@/$(SOURCE_NAME).cc/' \
$(TEMP_CPP_DIR)$S$(SOURCE_NAME)$SCMakeLists.txt
$(SED) -i -e 's;@TEST_ARGS@;$(ARGS);' \
$(TEMP_CPP_DIR)$S$(SOURCE_NAME)$SCMakeLists.txt
.PHONY: build # Build a C++ program.
build: cpp \
$(SOURCE) \
$(TEMP_CPP_DIR)/$(SOURCE_NAME)/CMakeLists.txt
-$(DELREC) $(TEMP_CPP_DIR)$S$(SOURCE_NAME)$Sbuild
$(COPY) $(subst /,$S,$(SOURCE)) $(TEMP_CPP_DIR)$S$(SOURCE_NAME)$S$(SOURCE_NAME).cc
cd $(TEMP_CPP_DIR)$S$(SOURCE_NAME) &&\
cmake -S. -Bbuild \
-DCMAKE_PREFIX_PATH=$(OR_ROOT_FULL)/$(INSTALL_DIR) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-G $(GENERATOR) \
$(CMAKE_ARGS)
ifneq ($(PLATFORM),WIN64)
cd $(TEMP_CPP_DIR)$S$(SOURCE_NAME) && cmake --build build --config $(BUILD_TYPE) --target all -v
else
cd $(TEMP_CPP_DIR)$S$(SOURCE_NAME) && cmake --build build --config $(BUILD_TYPE) --target ALL_BUILD -v
endif
.PHONY: run # Run a C++ program.
run: build
ifneq ($(PLATFORM),WIN64)
cd $(TEMP_CPP_DIR)$S$(SOURCE_NAME) && cmake --build build --config $(BUILD_TYPE) --target test -v
else
cd $(TEMP_CPP_DIR)$S$(SOURCE_NAME) && cmake --build build --config $(BUILD_TYPE) --target RUN_TESTS -v
endif
endif
##################################
## CPP Tests/Examples/Samples ##
##################################
# Samples
define cpp-sample-target =
$(TEMP_CPP_DIR)/$1: | $(TEMP_CPP_DIR)
-$(MKDIR) $(TEMP_CPP_DIR)$S$1
$(TEMP_CPP_DIR)/$1/%: \
$(SRC_DIR)/ortools/$1/samples/%.cc \
| $(TEMP_CPP_DIR)/$1
-$(MKDIR) $(TEMP_CPP_DIR)$S$1$S$$*
$(TEMP_CPP_DIR)/$1/%/CMakeLists.txt: \
$(SRC_DIR)/ortools/$1/samples/%.cc \
${SRC_DIR}/ortools/cpp/CMakeLists.txt.in \
| $(TEMP_CPP_DIR)/$1/%
$(COPY) ortools$Scpp$SCMakeLists.txt.in $(TEMP_CPP_DIR)$S$1$S$$*$SCMakeLists.txt
$(SED) -i -e 's/@CPP_NAME@/$$*/' \
$(TEMP_CPP_DIR)$S$1$S$$*$SCMakeLists.txt
$(SED) -i -e 's/@CPP_FILE_NAME@/$$*.cc/' \
$(TEMP_CPP_DIR)$S$1$S$$*$SCMakeLists.txt
$(SED) -i -e 's/@TEST_ARGS@//' \
$(TEMP_CPP_DIR)$S$1$S$$*$SCMakeLists.txt
$(TEMP_CPP_DIR)/$1/%/%.cc: \
$(SRC_DIR)/ortools/$1/samples/%.cc \
| $(TEMP_CPP_DIR)/$1/%
$(MKDIR_P) $(TEMP_CPP_DIR)$S$1$S$$*
$(COPY) $(SRC_DIR)$Sortools$S$1$Ssamples$S$$*.cc \
$(TEMP_CPP_DIR)$S$1$S$$*
rcpp_%: \
cpp \
$(SRC_DIR)/ortools/$1/samples/%.cc \
$(TEMP_CPP_DIR)/$1/%/CMakeLists.txt \
$(TEMP_CPP_DIR)/$1/%/%.cc \
FORCE
cd $(TEMP_CPP_DIR)$S$1$S$$* &&\
cmake -S. -Bbuild \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_PREFIX_PATH=$(OR_ROOT_FULL)/$(INSTALL_DIR) \
-DCMAKE_INSTALL_PREFIX=install \
$(CMAKE_ARGS) \
-G $(GENERATOR)
ifneq ($(PLATFORM),WIN64)
cd $(TEMP_CPP_DIR)$S$1$S$$* && cmake --build build --config $(BUILD_TYPE) --target all -v
cd $(TEMP_CPP_DIR)$S$1$S$$* && cmake --build build --config $(BUILD_TYPE) --target test -v
else
cd $(TEMP_CPP_DIR)$S$1$S$$* && cmake --build build --config $(BUILD_TYPE) --target ALL_BUILD -v
cd $(TEMP_CPP_DIR)$S$1$S$$* && cmake --build build --config $(BUILD_TYPE) --target RUN_TESTS -v
endif
endef
CPP_SAMPLES := algorithms graph glop constraint_solver linear_solver math_opt model_builder pdlp routing sat
$(foreach sample,$(CPP_SAMPLES),$(eval $(call cpp-sample-target,$(sample))))
# Examples
define cpp-example-target =
$(TEMP_CPP_DIR)/$1: | $(TEMP_CPP_DIR)
-$(MKDIR) $(TEMP_CPP_DIR)$S$1
$(TEMP_CPP_DIR)/$1/%: \
$(SRC_DIR)/examples/$1/%.cc \
| $(TEMP_CPP_DIR)/$1
-$(MKDIR) $(TEMP_CPP_DIR)$S$1$S$$*
$(TEMP_CPP_DIR)/$1/%/CMakeLists.txt: \
$(SRC_DIR)/examples/$1/%.cc \
${SRC_DIR}/ortools/cpp/CMakeLists.txt.in \
| $(TEMP_CPP_DIR)/$1/%
$(COPY) ortools$Scpp$SCMakeLists.txt.in $(TEMP_CPP_DIR)$S$1$S$$*$SCMakeLists.txt
$(SED) -i -e 's/@CPP_NAME@/$$*/' \
$(TEMP_CPP_DIR)$S$1$S$$*$SCMakeLists.txt
$(SED) -i -e 's/@CPP_FILE_NAME@/$$*.cc/' \
$(TEMP_CPP_DIR)$S$1$S$$*$SCMakeLists.txt
$(SED) -i -e 's/@TEST_ARGS@//' \
$(TEMP_CPP_DIR)$S$1$S$$*$SCMakeLists.txt
$(TEMP_CPP_DIR)/$1/%/%.cc: \
$(SRC_DIR)/examples/$1/%.cc \
| $(TEMP_CPP_DIR)/$1/%
$(MKDIR_P) $(TEMP_CPP_DIR)$S$1$S$$*
$(COPY) $(SRC_DIR)$Sexamples$S$1$S$$*.cc \
$(TEMP_CPP_DIR)$S$1$S$$*
rcpp_%: \
cpp \
$(SRC_DIR)/examples/$1/%.cc \
$(TEMP_CPP_DIR)/$1/%/CMakeLists.txt \
$(TEMP_CPP_DIR)/$1/%/%.cc \
FORCE
cd $(TEMP_CPP_DIR)$S$1$S$$* &&\
cmake -S. -Bbuild \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_PREFIX_PATH=$(OR_ROOT_FULL)/$(INSTALL_DIR) \
-DCMAKE_INSTALL_PREFIX=install \
$(CMAKE_ARGS) \
-G $(GENERATOR)
ifneq ($(PLATFORM),WIN64)
cd $(TEMP_CPP_DIR)$S$1$S$$* && cmake --build build --config $(BUILD_TYPE) --target all -v
cd $(TEMP_CPP_DIR)$S$1$S$$* && cmake --build build --config $(BUILD_TYPE) --target test -v
else
cd $(TEMP_CPP_DIR)$S$1$S$$* && cmake --build build --config $(BUILD_TYPE) --target ALL_BUILD -v
cd $(TEMP_CPP_DIR)$S$1$S$$* && cmake --build build --config $(BUILD_TYPE) --target RUN_TESTS -v
endif
endef
CPP_EXAMPLES := contrib cpp
$(foreach example,$(CPP_EXAMPLES),$(eval $(call cpp-example-target,$(example))))
# Tests
CPP_TESTS := tests
$(TEMP_CPP_DIR)/tests: | $(TEMP_CPP_DIR)
-$(MKDIR) $(TEMP_CPP_DIR)$Stests
$(TEMP_CPP_DIR)/tests/%: \
$(SRC_DIR)/examples/tests/%.cc \
| $(TEMP_CPP_DIR)/tests
-$(MKDIR) $(TEMP_CPP_DIR)$Stests$S$*
$(TEMP_CPP_DIR)/tests/%/CMakeLists.txt: ${SRC_DIR}/ortools/cpp/CMakeLists.txt.in | $(TEMP_CPP_DIR)/tests/%
$(COPY) ortools$Scpp$SCMakeLists.txt.in $(TEMP_CPP_DIR)$Stests$S$*$SCMakeLists.txt
$(SED) -i -e 's/@CPP_NAME@/$*/' \
$(TEMP_CPP_DIR)$Stests$S$*$SCMakeLists.txt
$(SED) -i -e 's/@CPP_FILE_NAME@/$*.cc/' \
$(TEMP_CPP_DIR)$Stests$S$*$SCMakeLists.txt
$(SED) -i -e 's/@TEST_ARGS@//' \
$(TEMP_CPP_DIR)$Stests$S$*$SCMakeLists.txt
$(TEMP_CPP_DIR)/tests/%/%.cc: \
$(SRC_DIR)/examples/tests/%.cc \
| $(TEMP_CPP_DIR)/tests/%
$(MKDIR_P) $(TEMP_CPP_DIR)$Stests$S$*
$(COPY) $(SRC_DIR)$Sexamples$Stests$S$*.cc \
$(TEMP_CPP_DIR)$Stests$S$*
rcpp_%: \
cpp \
$(SRC_DIR)/examples/tests/%.cc \
$(TEMP_CPP_DIR)/tests/%/CMakeLists.txt \
$(TEMP_CPP_DIR)/tests/%/%.cc \
FORCE
cd $(TEMP_CPP_DIR)$Stests$S$* && \
cmake -S. -Bbuild \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_PREFIX_PATH=$(OR_ROOT_FULL)/$(INSTALL_DIR) \
-DCMAKE_INSTALL_PREFIX=install \
$(CMAKE_ARGS) \
-G $(GENERATOR)
ifneq ($(PLATFORM),WIN64)
cd $(TEMP_CPP_DIR)$Stests$S$* && cmake --build build --config $(BUILD_TYPE) --target all -v
cd $(TEMP_CPP_DIR)$Stests$S$* && cmake --build build --config $(BUILD_TYPE) --target test -v
else
cd $(TEMP_CPP_DIR)$Stests$S$* && cmake --build build --config $(BUILD_TYPE) --target ALL_BUILD -v
cd $(TEMP_CPP_DIR)$Stests$S$* && cmake --build build --config $(BUILD_TYPE) --target RUN_TESTS -v
endif
##################################
## Course scheduling example ##
##################################
# TODO(user) Port it to CMake
# examples/cpp/course_scheduling.proto: ;
#
# $(SRC_DIR)/examples/cpp/course_scheduling.pb.cc: \
# $(SRC_DIR)/examples/cpp/course_scheduling.proto | $(TEMP_CPP_DIR)/examples/cpp
# $(PROTOC) \
# --proto_path=$(INSTALL_DIR)/include \
# $(PROTOBUF_PROTOC_INC) \
# --cpp_out=. \
# $(SRC_DIR)/examples/cpp/course_scheduling.proto
#
# $(SRC_DIR)/examples/cpp/course_scheduling.pb.h: $(SRC_DIR)/examples/cpp/course_scheduling.pb.cc
# $(TOUCH) examples$Scpp$Scourse_scheduling.pb.h
#
# bin/course_scheduling$E: \
# $(SRC_DIR)/examples/cpp/course_scheduling.h \
# $(SRC_DIR)/examples/cpp/course_scheduling.cc \
# $(SRC_DIR)/examples/cpp/course_scheduling.pb.h \
# $(SRC_DIR)/examples/cpp/course_scheduling.pb.cc \
# $(SRC_DIR)/examples/cpp/course_scheduling_run.cc \
# cpp \
# | bin
# cmake build to generate bin$Scourse_scheduling$E
#
# rcpp_course_scheduling: bin/course_scheduling$E FORCE
# bin$S$*$E $(ARGS)
####################
## Test targets ##
####################
.PHONY: test_cpp_algorithms_samples # Build and Run all C++ Algorithms Samples (located in ortools/algorithms/samples)
test_cpp_algorithms_samples: \
rcpp_knapsack \
rcpp_simple_knapsack_program
.PHONY: test_cpp_graph_samples # Build and Run all C++ Graph Samples (located in ortools/graph/samples)
test_cpp_graph_samples: \
rcpp_simple_max_flow_program \
rcpp_simple_min_cost_flow_program
.PHONY: test_cpp_constraint_solver_samples # Build and Run all C++ CP Samples (located in ortools/constraint_solver/samples)
test_cpp_constraint_solver_samples: \
rcpp_minimal_jobshop_cp \
rcpp_nurses_cp \
rcpp_rabbits_and_pheasants_cp \
rcpp_simple_ls_program \
rcpp_simple_cp_program \
rcpp_simple_routing_program \
rcpp_tsp \
rcpp_tsp_cities \
rcpp_tsp_circuit_board \
rcpp_tsp_distance_matrix \
rcpp_vrp \
rcpp_vrp_breaks \
rcpp_vrp_capacity \
rcpp_vrp_drop_nodes \
rcpp_vrp_global_span \
rcpp_vrp_initial_routes \
rcpp_vrp_pickup_delivery \
rcpp_vrp_pickup_delivery_fifo \
rcpp_vrp_pickup_delivery_lifo \
rcpp_vrp_resources \
rcpp_vrp_solution_callback \
rcpp_vrp_starts_ends \
rcpp_vrp_time_windows \
rcpp_vrp_with_time_limit
.PHONY: test_cpp_linear_solver_samples # Build and Run all C++ LP Samples (located in ortools/linear_solver/samples)
test_cpp_linear_solver_samples: \
rcpp_assignment_mip \
rcpp_basic_example \
rcpp_bin_packing_mip \
rcpp_integer_programming_example \
rcpp_linear_programming_example \
rcpp_mip_var_array \
rcpp_multiple_knapsack_mip \
rcpp_simple_lp_program \
rcpp_simple_mip_program \
rcpp_stigler_diet
.PHONY: test_cpp_model_builder_samples # Build and Run all C++ CP Samples (located in ortools/model_builder/samples)
test_cpp_model_builder_samples: \
.PHONY: test_cpp_pdlp_samples # Build and Run all C++ CP Samples (located in ortools/model_builder/samples)
test_cpp_pdlp_samples: \
rcpp_simple_pdlp_program
.PHONY: test_cpp_sat_samples # Build and Run all C++ Sat Samples (located in ortools/sat/samples)
test_cpp_sat_samples: \
rcpp_assignment_groups_sat \
rcpp_assignment_sat \
rcpp_assignment_task_sizes_sat \
rcpp_assignment_teams_sat \
rcpp_assumptions_sample_sat \
rcpp_binpacking_problem_sat \
rcpp_bool_or_sample_sat \
rcpp_channeling_sample_sat \
rcpp_copy_model_sample_sat \
rcpp_cp_is_fun_sat \
rcpp_cp_sat_example \
rcpp_earliness_tardiness_cost_sample_sat \
rcpp_interval_sample_sat \
rcpp_literal_sample_sat \
rcpp_minimal_jobshop_sat \
rcpp_multiple_knapsack_sat \
rcpp_non_linear_sat \
rcpp_no_overlap_sample_sat \
rcpp_nqueens_sat \
rcpp_nurses_sat \
rcpp_optional_interval_sample_sat \
rcpp_rabbits_and_pheasants_sat \
rcpp_ranking_sample_sat \
rcpp_reified_sample_sat \
rcpp_schedule_requests_sat \
rcpp_search_for_all_solutions_sample_sat \
rcpp_simple_sat_program \
rcpp_solution_hinting_sample_sat \
rcpp_solve_and_print_intermediate_solutions_sample_sat \
rcpp_solve_with_time_limit_sample_sat \
rcpp_step_function_sample_sat \
rcpp_stop_after_n_solutions_sample_sat
.PHONY: check_cpp_pimpl
check_cpp_pimpl: \
test_cpp_algorithms_samples \
test_cpp_graph_samples \
test_cpp_constraint_solver_samples \
test_cpp_linear_solver_samples \
test_cpp_model_builder_samples \
test_cpp_pdlp_samples \
test_cpp_sat_samples \
\
rcpp_linear_programming \
rcpp_constraint_programming_cp \
rcpp_integer_programming \
rcpp_knapsack \
rcpp_max_flow \
rcpp_min_cost_flow
.PHONY: test_cc_tests # Build and Run all C++ Tests (located in examples/tests)
test_cc_tests: \
rcpp_lp_test \
rcpp_bug_fz1 \
rcpp_cpp11_test \
rcpp_forbidden_intervals_test \
rcpp_issue57 \
rcpp_min_max_test
# $(MAKE) rcpp_issue173 # error: too long
.PHONY: test_cc_contrib # Build and Run all C++ Contrib (located in examples/contrib)
test_cc_contrib:
.PHONY: test_cc_cpp # Build and Run all C++ Examples (located in examples/cpp)
test_cc_cpp: \
rcpp_costas_array_sat \
rcpp_cryptarithm_sat \
rcpp_flow_api \
rcpp_linear_assignment_api \
rcpp_linear_solver_protocol_buffers \
rcpp_magic_sequence_sat \
rcpp_magic_square_sat \
rcpp_nqueens \
rcpp_random_tsp \
rcpp_slitherlink_sat \
rcpp_strawberry_fields_with_column_generation \
rcpp_uncapacitated_facility_location \
# rcpp_weighted_tardiness_sat # need input file
# TODO(user) how to build cvrptwlib and depends on it
# rcpp_cvrp_disjoint_tw \
# rcpp_cvrptw \
# rcpp_cvrptw_with_breaks \
# rcpp_cvrptw_with_refueling \
# rcpp_cvrptw_with_resources \
# rcpp_cvrptw_with_stop_times_and_resources
# $(MAKE) run \
SOURCE=examples/cpp/dimacs_assignment.cc \
ARGS=examples/cpp/dimacs.asn
$(MAKE) run \
SOURCE=examples/cpp/dobble_ls.cc \
ARGS="--time_limit_in_ms=10000"
$(MAKE) run \
SOURCE=examples/cpp/golomb_sat.cc \
ARGS="--size=5"
$(MAKE) run \
SOURCE=examples/cpp/jobshop_sat.cc \
ARGS="--input=$(subst $S,/,$(OR_ROOT_FULL))/examples/cpp/jobshop"
$(MAKE) run \
SOURCE=examples/cpp/mps_driver.cc \
ARGS="--input=$(subst $S,/,$(OR_ROOT_FULL))/examples/cpp/test.mps"
$(MAKE) run \
SOURCE=examples/cpp/network_routing_sat.cc \
ARGS="--clients=10 --backbones=5 --demands=10 --traffic_min=5 --traffic_max=10 --min_client_degree=2 --max_client_degree=5 --min_backbone_degree=3 --max_backbone_degree=5 --max_capacity=20 --fixed_charge_cost=10"
$(MAKE) run \
SOURCE=examples/cpp/sports_scheduling_sat.cc \
ARGS="--params max_time_in_seconds:10.0"
# $(MAKE) run SOURCE=examples/cpp/frequency_assignment_problem.cc # Need data file
# $(MAKE) run SOURCE=examples/cpp/pdptw.cc \
ARGS="--pdp_file examples/cpp/pdptw.txt" # Fails on windows...
# $(MAKE) run \
SOURCE=examples/cpp/shift_minimization_sat.cc \
ARGS="--input=$(subst $S,/,$(OR_ROOT_FULL))/examples/cpp/shift_minimization.dat"
rfz_%: cpp
$(INSTALL_DIR)$Sbin$Sfzn-ortools$E $(OR_ROOT_FULL)/examples/flatzinc/$*.fzn
###############
## Archive ##
###############
archive_cpp: $(INSTALL_CPP_NAME)$(ARCHIVE_EXT)
$(INSTALL_CPP_NAME):
$(MKDIR) $(INSTALL_CPP_NAME)
$(INSTALL_CPP_NAME)/examples: | $(INSTALL_CPP_NAME)
$(MKDIR) $(INSTALL_CPP_NAME)$Sexamples
define cpp-sample-archive =
$(INSTALL_CPP_NAME)/examples/%/CMakeLists.txt: \
$(TEMP_CPP_DIR)/$1/%/CMakeLists.txt \
$(SRC_DIR)/ortools/$1/samples/%.cc \
| $(INSTALL_CPP_NAME)/examples
-$(MKDIR_P) $(INSTALL_CPP_NAME)$Sexamples$S$$*
$(COPY) $(SRC_DIR)$Sortools$S$1$Ssamples$S$$*.cc $(INSTALL_CPP_NAME)$Sexamples$S$$*
$(COPY) $(TEMP_CPP_DIR)$S$1$S$$*$SCMakeLists.txt $(INSTALL_CPP_NAME)$Sexamples$S$$*
endef
$(foreach sample,$(CPP_SAMPLES),$(eval $(call cpp-sample-archive,$(sample))))
define cpp-example-archive =
$(INSTALL_CPP_NAME)/examples/%/CMakeLists.txt: \
$(TEMP_CPP_DIR)/$1/%/CMakeLists.txt \
$(SRC_DIR)/examples/$1/%.cc \
| $(INSTALL_CPP_NAME)/examples
-$(MKDIR_P) $(INSTALL_CPP_NAME)$Sexamples$S$$*
$(COPY) $(SRC_DIR)$Sexamples$S$1$S$$*.cc $(INSTALL_CPP_NAME)$Sexamples$S$$*
$(COPY) $(TEMP_CPP_DIR)$S$1$S$$*$SCMakeLists.txt $(INSTALL_CPP_NAME)$Sexamples$S$$*
endef
$(foreach example,$(CPP_EXAMPLES),$(eval $(call cpp-example-archive,$(example))))
SAMPLE_CPP_FILES = \
$(addsuffix /CMakeLists.txt,$(addprefix $(INSTALL_CPP_NAME)/examples/,$(basename $(notdir $(wildcard ortools/*/samples/*.cc)))))
EXAMPLE_CPP_FILES = \
$(addsuffix /CMakeLists.txt,$(addprefix $(INSTALL_CPP_NAME)/examples/,$(basename $(notdir $(wildcard examples/contrib/*.cc))))) \
$(addsuffix /CMakeLists.txt,$(addprefix $(INSTALL_CPP_NAME)/examples/,$(basename $(notdir $(wildcard examples/cpp/*.cc)))))
$(INSTALL_CPP_NAME)$(ARCHIVE_EXT): \
$(SAMPLE_CPP_FILES) \
$(EXAMPLE_CPP_FILES) \
tools/README.cpp.md tools/Makefile.cpp.mk
$(MAKE) third_party BUILD_DOTNET=OFF BUILD_JAVA=OFF BUILD_PYTHON=OFF INSTALL_DIR=$(OR_ROOT)$(INSTALL_CPP_NAME)
cmake --build $(BUILD_DIR) --target install --config $(BUILD_TYPE) -j $(JOBS) -v
$(COPY) tools$SREADME.cpp.md $(INSTALL_CPP_NAME)$SREADME.md
$(COPY) tools$SMakefile.cpp.mk $(INSTALL_CPP_NAME)$SMakefile
$(SED) -i -e 's/@PROJECT_VERSION@/$(OR_TOOLS_VERSION)/' $(INSTALL_CPP_NAME)$SMakefile
ifeq ($(PLATFORM),WIN64)
$(ZIP) -r $(INSTALL_CPP_NAME)$(ARCHIVE_EXT) $(INSTALL_CPP_NAME)
else
$(TAR) --no-same-owner -czvf $(INSTALL_CPP_NAME)$(ARCHIVE_EXT) $(INSTALL_CPP_NAME)
endif
# Test archive
TEMP_CPP_TEST_DIR := temp_cpp_test
.PHONY: test_archive_cpp # Test C++ OR-Tools archive is OK.
test_archive_cpp: $(INSTALL_CPP_NAME)$(ARCHIVE_EXT)
-$(DELREC) $(TEMP_CPP_TEST_DIR)
-$(MKDIR) $(TEMP_CPP_TEST_DIR)
ifeq ($(PLATFORM),WIN64)
$(UNZIP) $< -d $(TEMP_CPP_TEST_DIR)
else
$(TAR) -xvf $< -C $(TEMP_CPP_TEST_DIR)
endif
cd $(TEMP_CPP_TEST_DIR)$S$(INSTALL_CPP_NAME) \
&& $(MAKE) MAKEFLAGS= \
&& $(MAKE) MAKEFLAGS= test
################
## Cleaning ##
################
clean_cpp:
-$(DELREC) $(BUILD_DIR)
-$(DELREC) $(INSTALL_DIR)
-$(DELREC) $(TEMP_CPP_DIR)
-$(DELREC) $(INSTALL_CPP_NAME)
-$(DELREC) or-tools_cpp_*
-$(DELREC) $(TEMP_CPP_TEST_DIR)
-$(DEL) *.deb
#############
## DEBUG ##
#############
detect_cpp:
@echo Relevant info for the C++ build:
@echo SRC_DIR = $(SRC_DIR)
@echo BUILD_DIR = $(BUILD_DIR)
@echo INSTALL_DIR = $(INSTALL_DIR)
@echo prefix = $(prefix)
@echo BUILD_TYPE = $(BUILD_TYPE)
@echo USE_GLOP = ON
@echo USE_PDLP = ON
@echo USE_COINOR = $(USE_COINOR)
@echo USE_SCIP = $(USE_SCIP)
@echo USE_GLPK = $(USE_GLPK)
@echo USE_CPLEX = $(USE_CPLEX)
ifdef GLPK_ROOT
@echo GLPK_ROOT = $(GLPK_ROOT)
endif
ifdef CPLEX_ROOT
@echo CPLEX_ROOT = $(CPLEX_ROOT)
endif
ifdef XPRESS_ROOT
@echo XPRESS_ROOT = $(XPRESS_ROOT)
endif
@echo INSTALL_CPP_NAME = $(INSTALL_CPP_NAME)
ifeq ($(PLATFORM),WIN64)
@echo off & echo(
else
@echo
endif