Only add ortools as CMake subproject if target not found
Should fix error if a super build already has some
This commit is contained in:
@@ -33,7 +33,7 @@ project(ortools-meta NONE)
|
||||
|
||||
include(CTest)
|
||||
if(UNIX)
|
||||
# Needed to create python packagefrom the build directory
|
||||
# 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)
|
||||
@@ -54,7 +54,7 @@ message(STATUS "Build Python Binding: ${BUILD_PYTHON}")
|
||||
message(STATUS "Build Java Binding: ${BUILD_JAVA}")
|
||||
message(STATUS "Build CSharp Binding: ${BUILD_CSHARP}")
|
||||
|
||||
# Build Dependencies
|
||||
# Add OR Tools Dependencies as CMake subproject if missing
|
||||
add_subdirectory(cmake/external)
|
||||
|
||||
include(cpp)
|
||||
|
||||
@@ -52,12 +52,6 @@ add_definitions(-DUSE_GLOP -DUSE_BOP -DUSE_CBC -DUSE_CLP)
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
find_package(ZLIB REQUIRED)
|
||||
find_package(Protobuf REQUIRED)
|
||||
find_package(gflags REQUIRED)
|
||||
find_package(glog REQUIRED)
|
||||
find_package(Cbc REQUIRED)
|
||||
|
||||
# Main Target
|
||||
if(BUILD_SHARED_LIBS)
|
||||
add_library(${PROJECT_NAME} SHARED "")
|
||||
|
||||
243
cmake/external/CMakeLists.txt
vendored
243
cmake/external/CMakeLists.txt
vendored
@@ -1,7 +1,7 @@
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
# Force dependencies to be static
|
||||
# Force dependencies to be built as static
|
||||
set(BUILD_SHARED_BCKP ${BUILD_SHARED_LIBS})
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
|
||||
@@ -44,138 +44,153 @@ endif()
|
||||
##############
|
||||
## GFLAGS ##
|
||||
##############
|
||||
message(STATUS "Subproject: Gflag...")
|
||||
# Download and unpack gflags at configure time
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gflags.CMakeLists.txt
|
||||
${CMAKE_BINARY_DIR}/gflags-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gflags-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for gflags failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gflags-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for gflags failed: ${result}")
|
||||
endif()
|
||||
if(NOT TARGET gflags::gflags)
|
||||
message(STATUS "Target gflags::gflags not found.")
|
||||
message(STATUS "Adding CMake Subproject: Gflag...")
|
||||
# Download and unpack gflags at configure time
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/gflags.CMakeLists.txt
|
||||
${CMAKE_BINARY_DIR}/gflags-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gflags-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for gflags failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/gflags-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for gflags failed: ${result}")
|
||||
endif()
|
||||
|
||||
set(GFLAGS_NAMESPACE "gflags")
|
||||
set(GFLAGS_INSTALL_STATIC_LIBS ON)
|
||||
set(GFLAGS_INSTALL_HEADERS ON)
|
||||
#set(GFLAGS_IS_SUBPROJECT TRUE)
|
||||
add_subdirectory(
|
||||
${CMAKE_BINARY_DIR}/gflags-src
|
||||
${CMAKE_BINARY_DIR}/gflags-build)
|
||||
message(STATUS "Subproject: Gflag...DONE")
|
||||
set(GFLAGS_NAMESPACE "gflags")
|
||||
set(GFLAGS_INSTALL_STATIC_LIBS ON)
|
||||
set(GFLAGS_INSTALL_HEADERS ON)
|
||||
#set(GFLAGS_IS_SUBPROJECT TRUE)
|
||||
add_subdirectory(
|
||||
${CMAKE_BINARY_DIR}/gflags-src
|
||||
${CMAKE_BINARY_DIR}/gflags-build)
|
||||
message(STATUS "Adding CMake Subproject: Gflag...DONE")
|
||||
endif()
|
||||
|
||||
############
|
||||
## GLOG ##
|
||||
############
|
||||
message(STATUS "Subproject: Glog...")
|
||||
# Download and unpack glog at configure time
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/glog.CMakeLists.txt
|
||||
${CMAKE_BINARY_DIR}/glog-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/glog-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for glog failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/glog-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for glog failed: ${result}")
|
||||
endif()
|
||||
if(NOT TARGET glog::glog)
|
||||
message(STATUS "Target glog::glog not found.")
|
||||
message(STATUS "Adding CMake Subproject: Glog...")
|
||||
# Download and unpack glog at configure time
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/glog.CMakeLists.txt
|
||||
${CMAKE_BINARY_DIR}/glog-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/glog-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for glog failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/glog-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for glog failed: ${result}")
|
||||
endif()
|
||||
|
||||
set(gflags_NAMESPACE "gflags" CACHE INTERNAL "Namespace for gflags")
|
||||
add_subdirectory(
|
||||
${CMAKE_BINARY_DIR}/glog-src
|
||||
${CMAKE_BINARY_DIR}/glog-build)
|
||||
message(STATUS "Subproject: Glog...DONE")
|
||||
set(gflags_NAMESPACE "gflags" CACHE INTERNAL "Namespace for gflags")
|
||||
add_subdirectory(
|
||||
${CMAKE_BINARY_DIR}/glog-src
|
||||
${CMAKE_BINARY_DIR}/glog-build)
|
||||
message(STATUS "Adding CMake Subproject: Glog...DONE")
|
||||
endif()
|
||||
|
||||
############
|
||||
## ZLIB ##
|
||||
############
|
||||
message(STATUS "Subproject: ZLIB...")
|
||||
# Download and unpack zlib at configure time
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/zlib.CMakeLists.txt
|
||||
${CMAKE_BINARY_DIR}/zlib-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/zlib-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for zlib failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/zlib-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for zlib failed: ${result}")
|
||||
endif()
|
||||
if(NOT TARGET ZLIB::ZLIB)
|
||||
message(STATUS "Target ZLIB::ZLIB not found.")
|
||||
message(STATUS "Adding CMake Subproject: ZLIB...")
|
||||
# Download and unpack zlib at configure time
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/zlib.CMakeLists.txt
|
||||
${CMAKE_BINARY_DIR}/zlib-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/zlib-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for zlib failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/zlib-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for zlib failed: ${result}")
|
||||
endif()
|
||||
|
||||
add_subdirectory(
|
||||
${CMAKE_BINARY_DIR}/zlib-src
|
||||
${CMAKE_BINARY_DIR}/zlib-build)
|
||||
message(STATUS "Subproject: ZLIB...DONE")
|
||||
add_subdirectory(
|
||||
${CMAKE_BINARY_DIR}/zlib-src
|
||||
${CMAKE_BINARY_DIR}/zlib-build)
|
||||
message(STATUS "Adding CMake Subproject: ZLIB...DONE")
|
||||
endif()
|
||||
|
||||
################
|
||||
## PROTOBUF ##
|
||||
################
|
||||
message(STATUS "Subproject: Protobuf...")
|
||||
# Download and unpack protobuf at configure time
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/protobuf.CMakeLists.txt
|
||||
${CMAKE_BINARY_DIR}/protobuf-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/protobuf-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for protobuf failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/protobuf-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for protobuf failed: ${result}")
|
||||
if(NOT TARGET protobuf::libprotobuf OR NOT TARGET protobuf::protoc)
|
||||
message(STATUS "Target protobuf::libprotobuf or protobuf::protoc not found.")
|
||||
message(STATUS "Adding CMake Subproject: Protobuf...")
|
||||
# Download and unpack protobuf at configure time
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/protobuf.CMakeLists.txt
|
||||
${CMAKE_BINARY_DIR}/protobuf-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/protobuf-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for protobuf failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/protobuf-download )
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for protobuf failed: ${result}")
|
||||
endif()
|
||||
|
||||
set(protobuf_BUILD_TESTS OFF CACHE INTERNAL "Disable Protobuf tests")
|
||||
add_subdirectory(
|
||||
${CMAKE_BINARY_DIR}/protobuf-src/cmake
|
||||
${CMAKE_BINARY_DIR}/protobuf-build)
|
||||
message(STATUS "Adding CMake Subproject: Protobuf...DONE")
|
||||
endif()
|
||||
|
||||
set(protobuf_BUILD_TESTS OFF CACHE INTERNAL "Disable Protobuf tests")
|
||||
add_subdirectory(
|
||||
${CMAKE_BINARY_DIR}/protobuf-src/cmake
|
||||
${CMAKE_BINARY_DIR}/protobuf-build)
|
||||
message(STATUS "Subproject: Protobuf...DONE")
|
||||
###########
|
||||
## CBC ##
|
||||
###########
|
||||
if(NOT TARGET Cbc::CbcSolver OR NOT TARGET Cbc::ClpSolver)
|
||||
message(STATUS "Target Cbc::CbcSolver or Cbc::ClpSolver not found.")
|
||||
message(STATUS "Adding CMake Subproject: Cbc...")
|
||||
# Download and unpack cbc at configure time
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cbc.CMakeLists.txt
|
||||
${CMAKE_BINARY_DIR}/cbc-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/cbc-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for cbc failed: ${result}")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/cbc-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for cbc failed: ${result}")
|
||||
endif()
|
||||
|
||||
###################
|
||||
## COIN-OR:CBC ##
|
||||
###################
|
||||
message(STATUS "Subproject: COIN-OR:Cbc...")
|
||||
# Download and unpack cbc at configure time
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cbc.CMakeLists.txt
|
||||
${CMAKE_BINARY_DIR}/cbc-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/cbc-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for cbc failed: ${result}")
|
||||
add_subdirectory(
|
||||
${CMAKE_BINARY_DIR}/cbc-src
|
||||
${CMAKE_BINARY_DIR}/cbc-build)
|
||||
message(STATUS "Adding CMake Subproject: Cbc...DONE")
|
||||
endif()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/cbc-download)
|
||||
if(result)
|
||||
message(FATAL_ERROR "Build step for cbc failed: ${result}")
|
||||
endif()
|
||||
|
||||
add_subdirectory(
|
||||
${CMAKE_BINARY_DIR}/cbc-src
|
||||
${CMAKE_BINARY_DIR}/cbc-build)
|
||||
message(STATUS "Subproject: COIN-OR:Cbc...DONE")
|
||||
|
||||
# Reapply previous state
|
||||
set(BUILD_SHARED_LIBS ${BUILD_SHARED_BCKP})
|
||||
|
||||
Reference in New Issue
Block a user