2025-01-10 11:35:44 +01:00
|
|
|
# Copyright 2010-2025 Google LLC
|
2022-06-20 18:27:09 +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.
|
|
|
|
|
|
2025-07-23 15:07:49 +02:00
|
|
|
set_property(SOURCE routing.swig PROPERTY CPLUSPLUS ON)
|
|
|
|
|
set_property(SOURCE routing.swig PROPERTY SWIG_MODULE_NAME pywrapcp)
|
|
|
|
|
set_property(SOURCE routing.swig PROPERTY COMPILE_DEFINITIONS
|
2023-05-30 14:49:13 +02:00
|
|
|
${OR_TOOLS_COMPILE_DEFINITIONS} ABSL_MUST_USE_RESULT=)
|
2025-07-23 15:07:49 +02:00
|
|
|
set_property(SOURCE routing.swig PROPERTY COMPILE_OPTIONS -nofastunpack)
|
2020-02-24 17:26:17 +01:00
|
|
|
swig_add_library(pywrapcp
|
2022-04-28 15:50:56 +02:00
|
|
|
TYPE MODULE
|
2020-02-24 17:26:17 +01:00
|
|
|
LANGUAGE python
|
2021-12-02 23:34:51 +01:00
|
|
|
OUTPUT_DIR ${PYTHON_PROJECT_DIR}/constraint_solver
|
2025-07-23 15:07:49 +02:00
|
|
|
SOURCES routing.swig)
|
2017-12-11 09:20:43 +01:00
|
|
|
|
2021-09-08 00:02:29 +02:00
|
|
|
target_include_directories(pywrapcp PRIVATE ${Python3_INCLUDE_DIRS})
|
2020-02-24 17:26:17 +01:00
|
|
|
set_property(TARGET pywrapcp PROPERTY SWIG_USE_TARGET_INCLUDE_DIRECTORIES ON)
|
2021-09-08 00:02:29 +02:00
|
|
|
target_compile_definitions(pywrapcp PUBLIC "PY3")
|
2017-12-11 09:20:43 +01:00
|
|
|
|
2020-02-24 17:26:17 +01:00
|
|
|
# note: macOS is APPLE and also UNIX !
|
|
|
|
|
if(APPLE)
|
|
|
|
|
set_target_properties(pywrapcp PROPERTIES
|
|
|
|
|
SUFFIX ".so"
|
2024-12-16 08:50:23 +01:00
|
|
|
INSTALL_RPATH "@loader_path;@loader_path/../../${PROJECT_NAME}/.libs")
|
2024-12-13 17:00:53 +01:00
|
|
|
target_link_options(pywrapcp PRIVATE "LINKER:-undefined,dynamic_lookup")
|
2020-02-24 17:26:17 +01:00
|
|
|
elseif(UNIX)
|
|
|
|
|
set_target_properties(pywrapcp PROPERTIES
|
|
|
|
|
INSTALL_RPATH "$ORIGIN:$ORIGIN/../../${PROJECT_NAME}/.libs")
|
|
|
|
|
endif()
|
|
|
|
|
target_link_libraries(pywrapcp PRIVATE ortools::ortools)
|
|
|
|
|
|
|
|
|
|
# Variable PYTHON_LIBRARIES can contains keyword `optimized`
|
|
|
|
|
# which won't be interpreted inside a generator expression.
|
|
|
|
|
# i.e. we can't use: $<$<PLATFORM_ID:Windows>:${PYTHON_LIBRARIES}>
|
|
|
|
|
# see: https://cmake.org/cmake/help/git-stage/command/target_link_libraries.html#command:target_link_libraries
|
|
|
|
|
if(MSVC)
|
2021-09-08 00:02:29 +02:00
|
|
|
target_link_libraries(pywrapcp PRIVATE ${Python3_LIBRARIES})
|
2017-12-11 09:20:43 +01:00
|
|
|
endif()
|
2022-09-21 18:27:56 +02:00
|
|
|
|
2024-07-12 16:22:25 +02:00
|
|
|
# Test
|
2022-09-21 18:27:56 +02:00
|
|
|
if(BUILD_TESTING)
|
|
|
|
|
file(GLOB PYTHON_SRCS "*_test.py")
|
|
|
|
|
foreach(FILE_NAME IN LISTS PYTHON_SRCS)
|
2024-01-12 08:55:24 +01:00
|
|
|
add_python_test(FILE_NAME ${FILE_NAME})
|
2022-09-21 18:27:56 +02:00
|
|
|
endforeach()
|
|
|
|
|
endif()
|