-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework CMake dependencies management (Fix #1116)
- By default don't build dependencies simply call find_package() - By default only build C++ library - IF building Python, Java or .Net wrapper then force build dependencies - Build dependencies as STATIC - Build and Install (in CMAKE_BINARY_DIR) dependencies at configure time
- Loading branch information
Showing
30 changed files
with
728 additions
and
532 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,92 @@ | ||
# This file is just an orchestration | ||
cmake_minimum_required(VERSION 3.8.2) | ||
cmake_minimum_required(VERSION 3.5.2) | ||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
# Default Build Type to be Release | ||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING | ||
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel. (default: Release)" | ||
FORCE) | ||
endif(NOT CMAKE_BUILD_TYPE) | ||
|
||
# Use find_package everywhere, no-op if it's a subproject | ||
macro(find_package) | ||
if(NOT TARGET ${ARGV0} AND NOT TARGET ${ARGV0}::${ARGV0}) | ||
_find_package(${ARGV}) | ||
else() | ||
if(TARGET ${ARGV0}) | ||
get_target_property(TGT_VER ${ARGV0} VERSION) | ||
set(TGT ${ARGV0}) | ||
else() | ||
get_target_property(TGT_VER ${ARGV0}::${ARGV0} VERSION) | ||
set(TGT ${ARGV0}::${ARGV0}) | ||
endif() | ||
message(STATUS "Found ${ARGV0}: CMake Target ${TGT} (found version \"${TGT_VER}\")") | ||
set(${ARGV0}_FOUND TRUE) | ||
endif() | ||
endmacro() | ||
# Apple: Don't modify install_name when touching RPATH. | ||
if(POLICY CMP0068) | ||
cmake_policy(SET CMP0068 NEW) | ||
endif() | ||
|
||
project(ortools-meta NONE) | ||
include(utils) | ||
set_version(VERSION) | ||
|
||
project(ortools LANGUAGES CXX VERSION ${VERSION}) | ||
message(STATUS "version: ${PROJECT_VERSION}") | ||
|
||
# Default Build Type to be Release | ||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING | ||
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel. (default: Release)" | ||
FORCE) | ||
endif() | ||
|
||
include(CTest) | ||
if(UNIX) | ||
# Needed to create python package from the build directory | ||
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) | ||
option(BUILD_SHARED_LIBS "Build shared libraries(.so)." ON) | ||
elseif(MSVC) | ||
# Windows only support static build. | ||
set(BUILD_SHARED_LIBS OFF) | ||
endif() | ||
|
||
# When incorporating ortools in a CMake Project, then only C++ library will be built. | ||
# Consequently Python, Java and C# wrapper won't be built. | ||
if("^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$") | ||
set(ORTOOLS_IS_SUBPROJECT FALSE) | ||
else() | ||
set(ORTOOLS_IS_SUBPROJECT TRUE) | ||
endif() | ||
# By default only the ortools C++ library is built. | ||
option(BUILD_CXX "Build C++ library" ON) | ||
option(BUILD_PYTHON "Build Python Library" OFF) | ||
option(BUILD_JAVA "Build Java Library" OFF) | ||
option(BUILD_DOTNET "Build .NET Library" OFF) | ||
message(STATUS "Build C++ library: ${BUILD_CXX}") | ||
message(STATUS "Build Python: ${BUILD_PYTHON}") | ||
message(STATUS "Build Java: ${BUILD_JAVA}") | ||
message(STATUS "Build .Net: ${BUILD_DOTNET}") | ||
|
||
#option(BUILD_DOC "Build doxygen" OFF) | ||
#message(STATUS "Build doxygen: ${BUILD_DOC}") | ||
|
||
# By default all dependencies are NOT built (i.e. BUILD_DEPS=OFF). | ||
# IF building any wrapper THEN Force BUILD_DEPS=ON | ||
# IF BUILD_DEPS=ON THEN Force all BUILD_*=ON | ||
include(CMakeDependentOption) | ||
option(BUILD_DEPS "Force re-build of all dependencies" ON) | ||
option(BUILD_CXX "Build C++ library" ON) | ||
CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python Library" OFF | ||
"BUILD_CXX; NOT ORTOOLS_IS_SUBPROJECT" OFF) | ||
CMAKE_DEPENDENT_OPTION(BUILD_JAVA "Build Java Library" OFF | ||
"BUILD_CXX; NOT ORTOOLS_IS_SUBPROJECT" OFF) | ||
CMAKE_DEPENDENT_OPTION(BUILD_DOTNET "Build .NET Library" OFF | ||
"BUILD_CXX; NOT ORTOOLS_IS_SUBPROJECT" OFF) | ||
CMAKE_DEPENDENT_OPTION(BUILD_DEPS "Force re-build of all dependencies" OFF | ||
"NOT BUILD_PYTHON; NOT BUILD_JAVA; NOT BUILD_DOTNET" ON) | ||
CMAKE_DEPENDENT_OPTION(BUILD_ZLIB "Build the ZLIB dependency Library" OFF | ||
"NOT BUILD_DEPS" ON) | ||
CMAKE_DEPENDENT_OPTION(BUILD_absl "Build the abseil-cpp dependency Library" OFF | ||
"NOT BUILD_DEPS" ON) | ||
CMAKE_DEPENDENT_OPTION(BUILD_gflags "Build the gflags dependency Library" OFF | ||
"NOT BUILD_DEPS" ON) | ||
CMAKE_DEPENDENT_OPTION(BUILD_glog "Build the glog dependency Library" OFF | ||
"NOT BUILD_DEPS" ON) | ||
CMAKE_DEPENDENT_OPTION(BUILD_Protobuf "Build the Protobuf dependency Library" OFF | ||
"NOT BUILD_DEPS" ON) | ||
CMAKE_DEPENDENT_OPTION(BUILD_CoinUtils "Build the CoinUtils dependency Library" OFF | ||
"NOT BUILD_DEPS" ON) | ||
CMAKE_DEPENDENT_OPTION(BUILD_Osi "Build the Osi dependency Library" OFF | ||
"NOT BUILD_DEPS" ON) | ||
CMAKE_DEPENDENT_OPTION(BUILD_Clp "Build the Clp dependency Library" OFF | ||
"NOT BUILD_DEPS" ON) | ||
CMAKE_DEPENDENT_OPTION(BUILD_Cgl "Build the Cgl dependency Library" OFF | ||
"NOT BUILD_DEPS" ON) | ||
CMAKE_DEPENDENT_OPTION(BUILD_Cbc "Build the Cbc dependency Library" OFF | ||
"NOT BUILD_DEPS" ON) | ||
|
||
message(STATUS "Build all dependencies: ${BUILD_DEPS}") | ||
message(STATUS "Build CXX library: ${BUILD_CXX}") | ||
message(STATUS "Build Python Binding: ${BUILD_PYTHON}") | ||
message(STATUS "Build Java Binding: ${BUILD_JAVA}") | ||
message(STATUS "Build .Net Binding: ${BUILD_DOTNET}") | ||
|
||
# Add OR Tools Dependencies as CMake subproject if missing | ||
if(BUILD_DEPS) | ||
add_subdirectory(cmake/external external) | ||
endif() | ||
message(STATUS "Build ZLIB: ${BUILD_ZLIB}") | ||
message(STATUS "Build abseil-cpp: ${BUILD_absl}") | ||
message(STATUS "Build gflags: ${BUILD_gflags}") | ||
message(STATUS "Build glog: ${BUILD_glog}") | ||
message(STATUS "Build protobuf: ${BUILD_Protobuf}") | ||
message(STATUS "Build CoinUtils: ${BUILD_CoinUtils}") | ||
message(STATUS "Build Osi: ${BUILD_Osi}") | ||
message(STATUS "Build Clp: ${BUILD_Clp}") | ||
message(STATUS "Build Cgl: ${BUILD_Cgl}") | ||
message(STATUS "Build Cbc: ${BUILD_Cbc}") | ||
|
||
if(BUILD_CXX) | ||
include(cpp) | ||
if(BUILD_TESTING) | ||
add_subdirectory(examples/cpp) | ||
endif() | ||
endif() | ||
# Build Needed dependencies | ||
add_subdirectory(cmake/dependencies dependencies) | ||
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/dependencies/install) | ||
|
||
if(BUILD_PYTHON) | ||
include(python) | ||
if(BUILD_TESTING) | ||
add_subdirectory(examples/python) | ||
add_subdirectory(examples/notebook) | ||
endif() | ||
endif() | ||
include(CTest) | ||
|
||
if(BUILD_JAVA) | ||
include(java) | ||
if(BUILD_TESTING) | ||
add_subdirectory(examples/java) | ||
endif() | ||
endif() | ||
include(cpp) | ||
|
||
if(BUILD_DOTNET) | ||
include(dotnet) | ||
if(BUILD_TESTING) | ||
add_subdirectory(examples/dotnet) | ||
endif() | ||
endif() | ||
include(python) | ||
include(java) | ||
include(dotnet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.