2025-01-10 11:35:44 +01:00
|
|
|
# Copyright 2010-2025 Google LLC
|
2022-06-17 14:23:05 +02:00
|
|
|
# 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.
|
|
|
|
|
|
2022-05-27 15:05:13 +02:00
|
|
|
function(get_patch_from_git VERSION_PATCH VERSION_MAJOR)
|
2018-10-10 15:44:07 +02:00
|
|
|
find_package(Git QUIET)
|
|
|
|
|
if(NOT GIT_FOUND)
|
2020-09-16 14:18:06 +02:00
|
|
|
message(STATUS "Did not find git package.")
|
|
|
|
|
set(PATCH 9999)
|
2018-10-10 15:44:07 +02:00
|
|
|
else()
|
2020-09-16 14:18:06 +02:00
|
|
|
# If no tags can be found, it is a git shallow clone
|
2018-10-10 15:44:07 +02:00
|
|
|
execute_process(COMMAND
|
2022-05-27 15:05:13 +02:00
|
|
|
${GIT_EXECUTABLE} rev-list --count v${VERSION_MAJOR}.0..HEAD
|
|
|
|
|
RESULT_VARIABLE RESULT_VAR
|
|
|
|
|
OUTPUT_VARIABLE PATCH
|
2018-10-10 15:44:07 +02:00
|
|
|
ERROR_QUIET
|
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
2022-05-27 15:05:13 +02:00
|
|
|
if(RESULT_VAR) # since 0 is success, need invert it
|
|
|
|
|
message(STATUS "Did not be able to compute patch from v${VERSION_MAJOR}.0.")
|
2020-09-16 14:18:06 +02:00
|
|
|
set(PATCH 9999)
|
2018-10-10 15:44:07 +02:00
|
|
|
endif()
|
2022-05-27 15:05:13 +02:00
|
|
|
STRING(STRIP PATCH ${PATCH})
|
|
|
|
|
STRING(REGEX REPLACE "\n$" "" PATCH ${PATCH})
|
|
|
|
|
STRING(REGEX REPLACE " " "" PATCH ${PATCH})
|
2018-10-10 15:44:07 +02:00
|
|
|
endif()
|
|
|
|
|
set(${VERSION_PATCH} ${PATCH} PARENT_SCOPE)
|
2017-12-11 09:20:43 +01:00
|
|
|
endfunction()
|
2017-07-03 15:21:31 +05:30
|
|
|
|
2017-12-11 09:20:43 +01:00
|
|
|
function(set_version VERSION)
|
2022-06-02 15:37:05 +02:00
|
|
|
if(DEFINED ENV{OR_TOOLS_MAJOR} AND DEFINED ENV{OR_TOOLS_MINOR})
|
|
|
|
|
set(MAJOR $ENV{OR_TOOLS_MAJOR})
|
|
|
|
|
set(MINOR $ENV{OR_TOOLS_MINOR})
|
|
|
|
|
else()
|
|
|
|
|
# Get Major and Minor from Version.txt
|
|
|
|
|
file(STRINGS "Version.txt" VERSION_STR)
|
|
|
|
|
foreach(STR ${VERSION_STR})
|
|
|
|
|
if(${STR} MATCHES "OR_TOOLS_MAJOR=(.*)")
|
|
|
|
|
set(MAJOR ${CMAKE_MATCH_1})
|
|
|
|
|
endif()
|
|
|
|
|
if(${STR} MATCHES "OR_TOOLS_MINOR=(.*)")
|
|
|
|
|
set(MINOR ${CMAKE_MATCH_1})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
endif()
|
2020-09-16 14:18:06 +02:00
|
|
|
|
2022-06-02 15:37:05 +02:00
|
|
|
if(DEFINED ENV{OR_TOOLS_PATCH})
|
|
|
|
|
set(PATCH $ENV{OR_TOOLS_PATCH})
|
2018-10-10 15:44:07 +02:00
|
|
|
else()
|
2022-06-02 15:37:05 +02:00
|
|
|
# Compute Patch if .git is present otherwise set it to 9999
|
|
|
|
|
get_filename_component(GIT_DIR ".git" ABSOLUTE)
|
|
|
|
|
if(EXISTS ${GIT_DIR})
|
|
|
|
|
get_patch_from_git(PATCH ${MAJOR})
|
|
|
|
|
else()
|
|
|
|
|
set(PATCH 9999)
|
|
|
|
|
endif()
|
2018-10-10 15:44:07 +02:00
|
|
|
endif()
|
|
|
|
|
set(${VERSION} "${MAJOR}.${MINOR}.${PATCH}" PARENT_SCOPE)
|
2017-12-11 09:20:43 +01:00
|
|
|
endfunction()
|
2017-07-03 15:21:31 +05:30
|
|
|
|
2019-04-03 17:26:27 +02:00
|
|
|
|
2020-07-16 09:42:31 +02:00
|
|
|
# fetch_git_dependency()
|
2019-04-03 17:26:27 +02:00
|
|
|
#
|
|
|
|
|
# CMake function to download, build and install (in staging area) a dependency at configure
|
|
|
|
|
# time.
|
|
|
|
|
#
|
|
|
|
|
# Parameters:
|
|
|
|
|
# NAME: name of the dependency
|
|
|
|
|
# REPOSITORY: git url of the dependency
|
|
|
|
|
# TAG: tag of the dependency
|
2020-09-15 21:54:00 +02:00
|
|
|
# PATCH_COMMAND: apply patch
|
|
|
|
|
# SOURCE_SUBDIR: Path to source CMakeLists.txt relative to root dir
|
2019-04-03 17:26:27 +02:00
|
|
|
# CMAKE_ARGS: List of specific CMake args to add
|
|
|
|
|
#
|
2020-09-15 21:54:00 +02:00
|
|
|
# e.g.:
|
2020-07-16 09:42:31 +02:00
|
|
|
# fetch_git_dependency(
|
2019-04-03 17:26:27 +02:00
|
|
|
# NAME
|
|
|
|
|
# abseil-cpp
|
|
|
|
|
# URL
|
|
|
|
|
# https://github.com/abseil/abseil-cpp.git
|
|
|
|
|
# TAG
|
2022-05-16 11:27:36 +02:00
|
|
|
# main
|
2020-09-15 21:54:00 +02:00
|
|
|
# PATCH_COMMAND
|
2020-07-16 09:42:31 +02:00
|
|
|
# "git apply ${CMAKE_SOURCE_DIR}/patches/abseil-cpp.patch"
|
2019-04-03 17:26:27 +02:00
|
|
|
# )
|
2020-07-16 09:42:31 +02:00
|
|
|
function(fetch_git_dependency)
|
2019-04-03 17:26:27 +02:00
|
|
|
set(options "")
|
2020-07-16 09:42:31 +02:00
|
|
|
set(oneValueArgs NAME REPOSITORY TAG PATCH_COMMAND SOURCE_SUBDIR)
|
2019-04-03 17:26:27 +02:00
|
|
|
set(multiValueArgs CMAKE_ARGS)
|
|
|
|
|
cmake_parse_arguments(GIT_DEP
|
|
|
|
|
"${options}"
|
|
|
|
|
"${oneValueArgs}"
|
|
|
|
|
"${multiValueArgs}"
|
|
|
|
|
${ARGN}
|
|
|
|
|
)
|
|
|
|
|
message(STATUS "Building ${GIT_DEP_NAME}: ...")
|
2020-07-16 09:42:31 +02:00
|
|
|
string(TOLOWER ${GIT_DEP_NAME} NAME_LOWER)
|
2019-04-03 17:26:27 +02:00
|
|
|
|
2020-07-16 09:42:31 +02:00
|
|
|
if(GIT_DEP_PATCH_COMMAND)
|
|
|
|
|
set(PATCH_CMD "${GIT_DEP_PATCH_COMMAND}")
|
2019-04-03 17:26:27 +02:00
|
|
|
else()
|
2020-07-16 09:42:31 +02:00
|
|
|
set(PATCH_CMD "")
|
2019-04-03 17:26:27 +02:00
|
|
|
endif()
|
|
|
|
|
configure_file(
|
2020-07-16 09:42:31 +02:00
|
|
|
${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in
|
|
|
|
|
${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-subbuild/CMakeLists.txt @ONLY)
|
2019-04-03 17:26:27 +02:00
|
|
|
|
|
|
|
|
execute_process(
|
2020-07-16 09:42:31 +02:00
|
|
|
COMMAND ${CMAKE_COMMAND} -S. -Bproject_build -G "${CMAKE_GENERATOR}"
|
2019-04-03 17:26:27 +02:00
|
|
|
RESULT_VARIABLE result
|
2020-07-16 09:42:31 +02:00
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-subbuild)
|
2019-04-03 17:26:27 +02:00
|
|
|
if(result)
|
|
|
|
|
message(FATAL_ERROR "CMake step for ${GIT_DEP_NAME} failed: ${result}")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} --build project_build --config ${CMAKE_BUILD_TYPE}
|
|
|
|
|
RESULT_VARIABLE result
|
2020-07-16 09:42:31 +02:00
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-subbuild)
|
2019-04-03 17:26:27 +02:00
|
|
|
if(result)
|
|
|
|
|
message(FATAL_ERROR "Build step for ${GIT_DEP_NAME} failed: ${result}")
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-07-16 09:42:31 +02:00
|
|
|
if(GIT_DEP_SOURCE_SUBDIR)
|
|
|
|
|
add_subdirectory(
|
|
|
|
|
${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-src/${GIT_DEP_SOURCE_SUBDIR}
|
|
|
|
|
${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-build)
|
|
|
|
|
else()
|
|
|
|
|
add_subdirectory(
|
|
|
|
|
${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-src
|
|
|
|
|
${CMAKE_BINARY_DIR}/_deps/${NAME_LOWER}-build)
|
|
|
|
|
endif()
|
|
|
|
|
|
2019-04-03 17:26:27 +02:00
|
|
|
message(STATUS "Building ${GIT_DEP_NAME}: ...DONE")
|
|
|
|
|
endfunction()
|