Or-tools: Extend OR-Tools CMake Build Instructions

Created on 20 Jul 2019  Â·  6Comments  Â·  Source: google/or-tools

It took me quite a while to figure out how I can include OR-Tools to my c++ project using CMake.

Using the code below fixed my problem finally (described earlier here).

It might be worth to add a hint to the build instructions page, if this isn't considered a bug.

list(APPEND CMAKE_PREFIX_PATH "<>/or-tools/build/dependencies/install/")

set(GFLAGS_USE_TARGET_NAMESPACE TRUE)
find_package(ortools CONFIG REQUIRED)

add_executable(project main.cpp)
target_link_libraries(project ortools::ortools)
CMake

Most helpful comment

with BUILD_DEPS=ON the
cmake/ortools/ortoolsTargets.cmake created after the installation has the following entry:

set_target_properties(ortools::ortools PROPERTIES
  COMPATIBLE_INTERFACE_STRING "ortools_MAJOR_VERSION"
  INTERFACE_COMPILE_DEFINITIONS "USE_BOP;USE_GLOP;USE_CBC;USE_CLP"
  INTERFACE_COMPILE_FEATURES "cxx_std_11;cxx_std_11"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "ZLIB::ZLIB;absl::base;absl::random_random;absl::raw_hash_set;absl::hash;absl::memory;absl::meta;absl::str_format;absl::strings;absl::synchronization;absl::any;gflags::gflags_static;glog::glog;protobuf::libprotobuf;Coin::CbcSolver;Coin::OsiCbc;Coin::ClpSolver;Coin::OsiClp;Threads::Threads"
  INTERFACE_POSITION_INDEPENDENT_CODE "ON"
  INTERFACE_ortools_MAJOR_VERSION "7"
)

which means that there are dependencies to external cmake targets (absl::base, ... ). But those targets are not installed with the make install procedure!

All 6 comments

Not sure,

You can build or-tools using cmake and not make.
In that case, the dependencies will be built, but not in
dependencies/install/.
Laurent Perron | Operations Research | [email protected] | (33) 1 42 68 53
00

Le sam. 20 juil. 2019 à 07:34, Jeppy notifications@github.com a écrit :

It took me quite a while to figure out how I can include OR-Tools to my
c++ project using CMake.

Using the code below fixed my problem finally (described earlier here
https://github.com/google/or-tools/issues/1236#issuecomment-493370811).

It might be worth to add a hint to the build instructions page
https://github.com/google/or-tools/blob/stable/cmake/README.md, if this
isn't considered a bug.

list(APPEND CMAKE_PREFIX_PATH "<>/or-tools/build/dependencies/install/")

set(GFLAGS_USE_TARGET_NAMESPACE TRUE)
find_package(ortools CONFIG REQUIRED)

add_executable(project main.cpp)
target_link_libraries(project ortools::ortools)

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/or-tools/issues/1435?email_source=notifications&email_token=ACUPL3NAJXGWNXIAB5TOI6TQAMO75A5CNFSM4IFOY4YKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HAOAWUQ,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACUPL3ODGFNLTIPDBOUWSQ3QAMO75ANCNFSM4IFOY4YA
.

I had to build it with cmake -DBUILD_DEPS:BOOL=ON -H. -Bbuild -G "Unix Makefiles" and after that I found them in dependencies/install/

Only using cmake -H. -Bbuild -G "Unix Makefiles gave me missing dependency errors.

I am not the expert at all, but I believe you should do make install. This will package everything in one place.

I followed the build instruction page ending with cmake --build build --target install. I am still not able to find the dependencies anywhere in /usr/local. They only are in /dependencies/install/ and for some reason CMake is not able to find them there.

OK. Unfortunately, Corentin is unavailable until early September.
Laurent Perron | Operations Research | [email protected] | (33) 1 42 68 53
00

Le dim. 21 juil. 2019 à 07:38, Jeppy notifications@github.com a écrit :

I followed the build instruction page ending with cmake --build build
--target install. I am still not able to find the dependencies anywhere
in /usr/local. They only are in /dependencies/install/.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/google/or-tools/issues/1435?email_source=notifications&email_token=ACUPL3LG22CXOE6FU6KLG4TQARYHRA5CNFSM4IFOY4YKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2OE3RA#issuecomment-513560004,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACUPL3KXK3AIENWFMJCNZJ3QARYHRANCNFSM4IFOY4YA
.

with BUILD_DEPS=ON the
cmake/ortools/ortoolsTargets.cmake created after the installation has the following entry:

set_target_properties(ortools::ortools PROPERTIES
  COMPATIBLE_INTERFACE_STRING "ortools_MAJOR_VERSION"
  INTERFACE_COMPILE_DEFINITIONS "USE_BOP;USE_GLOP;USE_CBC;USE_CLP"
  INTERFACE_COMPILE_FEATURES "cxx_std_11;cxx_std_11"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "ZLIB::ZLIB;absl::base;absl::random_random;absl::raw_hash_set;absl::hash;absl::memory;absl::meta;absl::str_format;absl::strings;absl::synchronization;absl::any;gflags::gflags_static;glog::glog;protobuf::libprotobuf;Coin::CbcSolver;Coin::OsiCbc;Coin::ClpSolver;Coin::OsiClp;Threads::Threads"
  INTERFACE_POSITION_INDEPENDENT_CODE "ON"
  INTERFACE_ortools_MAJOR_VERSION "7"
)

which means that there are dependencies to external cmake targets (absl::base, ... ). But those targets are not installed with the make install procedure!

Was this page helpful?
0 / 5 - 0 ratings