Skip to content

Commit

Permalink
Fixup #3200
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Apr 4, 2022
1 parent 9cc1942 commit 5a5b0be
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 31 deletions.
18 changes: 11 additions & 7 deletions Makefile
Expand Up @@ -82,7 +82,7 @@ include $(OR_ROOT)makefiles/Makefile.cpp.mk
include $(OR_ROOT)makefiles/Makefile.python.mk
include $(OR_ROOT)makefiles/Makefile.java.mk
include $(OR_ROOT)makefiles/Makefile.dotnet.mk
include $(OR_ROOT)makefiles/Makefile.archive.mk
#include $(OR_ROOT)makefiles/Makefile.archive.mk
ifneq ($(PLATFORM),WIN64)
include $(OR_ROOT)makefiles/Makefile.doc.mk
else
Expand All @@ -107,7 +107,7 @@ else
endif

.PHONY: help_all
help_all: help_usage help_cc help_python help_java help_dotnet help_archive help_doc
help_all: help_usage help_cc help_dotnet help_java help_python help_doc #help_archive

# Commands to build/clean all languages.
.PHONY: compile
Expand All @@ -116,24 +116,28 @@ compile:

.PHONY: build_all
build_all:
$(MAKE) third_party BUILD_PYTHON=ON BUILD_JAVA=ON BUILD_DOTNET=ON
$(MAKE) third_party BUILD_DOTNET=ON BUILD_JAVA=ON BUILD_PYTHON=ON
cmake --build $(BUILD_DIR) --target install --config $(BUILD_TYPE) -j $(JOBS) -v
@echo Or-tools has been built for "$(BUILT_LANGUAGES)"

.PHONY: check_all
check_all: check_cpp check_python check_java check_dotnet
check_all: check_cpp check_dotnet check_java check_python
@echo Or-tools has been built and checked for "$(BUILT_LANGUAGES)"

.PHONY: test_all
test_all: test_cpp test_python test_java test_dotnet
test_all: test_cpp test_dotnet test_java test_python
@echo Or-tools have been built and tested for "$(BUILT_LANGUAGES)"

.PHONY: archive_all
archive_all: archive_cpp archive_dotnet archive_java archive_python
@echo Or-tools has been built and archived for "$(BUILT_LANGUAGES)"

.PHONY: clean_all
clean_all: clean_cpp clean_python clean_java clean_dotnet clean_archive
clean_all: clean_cpp clean_dotnet clean_java clean_python #clean_archive
@echo Or-Tools has been cleaned for "$(BUILT_LANGUAGES)"

.PHONY: detect_all
detect_all: detect_port detect_cpp detect_python detect_java detect_dotnet detect_archive
detect_all: detect_port detect_cpp detect_dotnet detect_java detect_python #detect_archive
@echo SOURCE = $(SOURCE)
@echo SOURCE_PATH = $(SOURCE_PATH)
@echo SOURCE_NAME = $(SOURCE_NAME)
Expand Down
9 changes: 6 additions & 3 deletions makefiles/Makefile.cpp.mk
Expand Up @@ -215,7 +215,7 @@ else
endif
endef

CPP_SAMPLES := algorithms graph glop constraint_solver linear_solver model_builder routing sat
CPP_SAMPLES := algorithms graph glop constraint_solver linear_solver math_opt model_builder routing sat
$(foreach sample,$(CPP_SAMPLES),$(eval $(call cpp-sample-target,$(sample))))

# Examples
Expand Down Expand Up @@ -535,8 +535,8 @@ endef
$(foreach sample,$(CPP_SAMPLES),$(eval $(call cpp-sample-archive,$(sample))))

define cpp-example-archive =
$(TEMP_ARCHIVE_DIR)/$(INSTALL_DIR)/examples/%/CMakeLists.txt: \
$(TEMP_CPP_DIR)/$1/%/CMakeLists.xml \
$(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$$*
Expand All @@ -558,6 +558,9 @@ $(INSTALL_CPP_NAME)$(ARCHIVE_EXT): \
$(EXAMPLE_CPP_FILES)
$(MAKE) third_party BUILD_PYTHON=OFF BUILD_JAVA=OFF BUILD_DOTNET=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 $(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
Expand Down
3 changes: 3 additions & 0 deletions makefiles/Makefile.dotnet.mk
Expand Up @@ -512,6 +512,9 @@ $(INSTALL_DOTNET_NAME)$(ARCHIVE_EXT): dotnet \
$(EXAMPLE_DOTNET_FILES)
$(COPY) $(BUILD_DIR)$Sdotnet$Spackages$S*.nupkg $(INSTALL_DOTNET_NAME)
$(COPY) LICENSE $(INSTALL_JAVA_NAME)
$(COPY) tools$SREADME.dotnet.md $(INSTALL_CPP_NAME)$SREADME.md
$(COPY) tools$SMakefile.dotnet $(INSTALL_CPP_NAME)$SMakefile
$(SED) -i -e 's/@PROJECT_VERSION@/$(OR_TOOLS_VERSION)/' $(INSTALL_CPP_NAME)$SMakefile
ifeq ($(PLATFORM),WIN64)
$(ZIP) -r $(INSTALL_DOTNET_NAME)$(ARCHIVE_EXT) $(INSTALL_DOTNET_NAME)
else
Expand Down
5 changes: 4 additions & 1 deletion makefiles/Makefile.java.mk
Expand Up @@ -302,7 +302,7 @@ test_java_linear_solver_samples: \
test_java_model_builder_samples: \
rjava_SimpleLpProgramMb \
rjava_SimpleMipProgramMb

.PHONY: test_java_sat_samples # Build and Run all Java SAT Samples (located in ortools/sat/samples)
test_java_sat_samples: \
rjava_AssignmentSat \
Expand Down Expand Up @@ -461,6 +461,9 @@ $(INSTALL_JAVA_NAME)$(ARCHIVE_EXT): java \
$(EXAMPLE_JAVA_FILES)
$(COPY) $(BUILD_DIR)$Sjava$Spackages$S*.nupkg $(INSTALL_JAVA_NAME)
$(COPY) LICENSE $(INSTALL_JAVA_NAME)
$(COPY) tools$SREADME.java.md $(INSTALL_CPP_NAME)$SREADME.md
$(COPY) tools$SMakefile.java $(INSTALL_CPP_NAME)$SMakefile
$(SED) -i -e 's/@PROJECT_VERSION@/$(OR_TOOLS_VERSION)/' $(INSTALL_CPP_NAME)$SMakefile
ifeq ($(PLATFORM),WIN64)
$(ZIP) -r $(INSTALL_JAVA_NAME)$(ARCHIVE_EXT) $(INSTALL_JAVA_NAME)
else
Expand Down
129 changes: 129 additions & 0 deletions tools/Makefile.cpp
@@ -0,0 +1,129 @@
VERSION := @PROJECT_VERSION@
# Let's discover something about where we run
ifeq ($(OS),Windows_NT)
OS = Windows
endif
ifeq ($(OS),Windows)
SYSTEM = win
else
SYSTEM = unix
endif
.SECONDARY:
# Useful directories.
EX_DIR = examples
EX_PATH = $(subst /,$S,$(EX_DIR))
# Unix specific part.
ifeq ($(SYSTEM),unix)
OS = $(shell uname -s)
# C++
ifeq ($(OS),Linux)
endif # ifeq($(OS),Linux)
ifeq ($(OS),Darwin) # Assume Mac Os X
endif # ifeq($(OS),Darwin)
# Makefile
S = /
DEL = rm -f
DEL_REC = rm -rf
MKDIR = mkdir
endif # SYSTEM == unix
# Windows specific part.
ifeq ($(SYSTEM),win)
# Makefile
S = \\
DEL = del
DEL_REC = rd /S /Q
MKDIR = md
endif # SYSTEM == win
BUILD_TYPE ?= Release
.PHONY: all
all: detect
.PHONY: detect
detect:
@echo VERSION = $(VERSION)
@echo SHELL = $(SHELL)
@echo SYSTEM = $(SYSTEM)
@echo PORT = $(PORT)
@echo OS = $(OS)
@echo CC = $(CC)
@echo CC_BIN = $(CC_BIN)
@echo CXX = $(CXX)
@echo CXX_BIN = $(CXX_BIN)
@echo CXXFLAGS = $(CXXFLAGS)
@echo LDFLAGS = $(LDFLAGS)
@echo OR_TOOLS_LNK = $(OR_TOOLS_LNK)
@echo SOURCE = $(SOURCE)
@echo SOURCE_PATH = $(SOURCE_PATH)
@echo SOURCE_NAME = $(SOURCE_NAME)
@echo SOURCE_SUFFIX = $(SOURCE_SUFFIX)
ifeq ($(SYSTEM),win)
@echo off & echo(
else
@echo
endif
##############
## SOURCE ##
##############
.PHONY: build # Build a C++ program.
.PHONY: run # Run a C++ program.
# Check SOURCE argument
SOURCE_SUFFIX = $(suffix $(SOURCE))
# will contain “/any/path/foo.cc” on unix and “\\any\\path\\foo.cc” on windows
SOURCE_PATH = $(subst /,$S,$(SOURCE))
SOURCE_NAME = $(basename $(notdir $(SOURCE)))
ifeq ($(SOURCE),) # Those rules will be used if SOURCE is empty
build run:
$(error no source file provided, the "$@" target must be used like so: \
make $@ SOURCE=relative/path/to/filename.extension)
else #ifeq SOURCE
ifeq (,$(wildcard $(SOURCE)))
$(error File "$(SOURCE)" does not exist !)
endif #ifeq SOURCE exist
build: $(SOURCE) example/$(SOURCE_NAME)/CMakeLists.txt
cd examples$S$(SOURCE_NAME) && cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
cd examples$S$(SOURCE_NAME) && cmake --build build --config $(BUILD_TYPE) -v
run: build
ifeq ($(SYSTEM),win)
cd examples$S$(SOURCE_NAME) && cmake --build build --config $(BUILD_TYPE) --target RUN_TESTS -v
else #ifeq win
cd examples$S$(SOURCE_NAME) && cmake --build build --config $(BUILD_TYPE) --target test -v
endif #ifeq Swin
endif #ifeq SOURCE
#############
## Tests ##
#############
.PHONY: test
test:
$(MAKE) run SOURCE=examples/basic_example/basic_example.cc
$(MAKE) run SOURCE=examples/linear_programming/linear_programming.cc
$(MAKE) run SOURCE=examples/integer_programming/integer_programming.cc
$(MAKE) run SOURCE=examples/simple_knapsack_program/simple_knapsack_program.cc
$(MAKE) run SOURCE=examples/simple_max_flow_program/simple_max_flow_program.cc
$(MAKE) run SOURCE=examples/simple_min_cost_flow_program/simple_min_cost_flow_program.cc
$(MAKE) run SOURCE=examples/simple_lp_program/simple_lp_program.cc
$(MAKE) run SOURCE=examples/simple_mip_program/simple_mip_program.cc
$(MAKE) run SOURCE=examples/simple_sat_program/simple_sat_program.cc
$(MAKE) run SOURCE=examples/simple_ls_program/simple_ls_program.cc
$(MAKE) run SOURCE=examples/tsp/tsp.cc
$(MAKE) run SOURCE=examples/vrp/vrp.cc
$(MAKE) run SOURCE=examples/nurses_cp/nurses_cp.cc
$(MAKE) run SOURCE=examples/nurses_sat/nurses_sat.cc
$(MAKE) run SOURCE=examples/minimal_jobshop_cp/minimal_jobshop_cp.cc
############
## MISC ##
############
# Include user makefile
-include Makefile.user
print-% : ; @echo $* = $($*)
18 changes: 10 additions & 8 deletions tools/README.cc.java.dotnet
Expand Up @@ -17,8 +17,8 @@ Upon decompressing the archive, you will get the following structure:

```
or-tools/
LICENSE <- Apache 2.0 License
README.md <- This file
[LICENSE](LICENSE) <- Apache 2.0 License
[README.md](README.md) <- This file
Makefile <- Main Makefile for C++,Java and .Net
examples/ <- C++, Java and .Net examples
include/ <- all include files
Expand All @@ -40,24 +40,26 @@ We have provided a makefile target to help you.
Use Makefile:

```shell
make run SOURCE=examples/cpp/golomb.cc
make run SOURCE=examples/basic_example/basic_example.cc
```

**OR** this is equivalent to compiling and running
`examples/cpp/golomb.cc`.
`examples/basic_example/basic_example.cc`.

- on Unix:

```shell
make bin/golomb
./bin/golomb
cd examples/basic_example
cmake -S . -B build
cmake --build build
```

- on Windows:

```shell
make bin\\golomb.exe
bin\\golomb.exe
cd examples/basic_example
cmake -S . -B build
cmake --build build
```

# Java
Expand Down
59 changes: 47 additions & 12 deletions tools/README.cpp.md
@@ -1,28 +1,63 @@
# Introduction

This file describes how to use OR-Tools in C++ with the binary archives.
This file describes how to use OR-Tools in C++ with the binary archive.

OR-Tools online documentation is
[here](https://developers.google.com/optimization)
OR-Tools online documentation is located at https://developers.google.com/optimization

Full installation instructions are located
[here](https://developers.google.com/optimization/install/cpp/)
Full installation instructions are located at https://developers.google.com/optimization/install/cpp/

These modules have been tested under:

- CentOS 8 (64 bit).
- Debian 11 (64 bit).
- CentOS 7 LTS and Stream 8 (64 bit).
- Debian 10 and 11 (64 bit).
- Fedora 33 and up (64 bit).
- Ubuntu 18.04 LTS and up (64 bit).
- MacOS 12.2 Monterey (64 bit).
- Microsoft Windows with Visual Studio 2022 (64-bit)
- Microsoft Windows with Visual Studio 2019 and 2022 (64-bit)

Upon decompressing the archive, you will get the following structure:

```
or-tools/
[LICENSE](LICENSE) <- Apache License
or-tools_cpp/
[README.md](README.md) <- This file
[examples/data/](examples/data) <- Data for the examples
[examples/cpp](examples/cpp) <- C++ examples
[bin](bin) <- directory containing executable files
[include](include) <- directory containing headers files.
[lib](lib) <- directory containing libraries files.
[share](share) <- directory containing various files.
[examples](examples) <- C++ examples.
[Makefile](Makefile) <- Main Makefile for C++.
```

Warning: While OR-Tools ships with SCIP, please consult the SCIP license
to ensure that you are complying with it if you want to use this solver.

# C++

Running the examples will involve compiling them, then running them.
We have provided a makefile target to help you.

Use Makefile:

```shell
make run SOURCE=examples/basic_example/basic_example.cc
```

**OR** this is equivalent to compiling and running
`examples/basic_example/basic_example.cc`.

- on Unix:

```shell
cd examples/basic_example
cmake -S . -B build
cmake --build build
```

- on Windows:

```shell
cd examples/basic_example
cmake -S . -B build
cmake --build build
```

0 comments on commit 5a5b0be

Please sign in to comment.