CMakeLists.txt 2.12 KB
Newer Older
Marc Chevrier's avatar
Marc Chevrier committed
1 2 3 4 5
cmake_minimum_required(VERSION 3.1)

project(TestMultiplePython CXX)

include(CTest)
6 7 8 9

find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})

10 11
find_package(Python2 REQUIRED COMPONENTS Interpreter Development)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
12

13 14 15 16 17 18 19
# Path separator
if (WIN32)
  set (PS "$<SEMICOLON>")
else()
  set (PS ":")
endif()

20
set(UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
21 22
unset(CMAKE_SWIG_FLAGS)

Marc Chevrier's avatar
Marc Chevrier committed
23 24
set_property(SOURCE "../example.i" PROPERTY CPLUSPLUS ON)
set_property(SOURCE "../example.i" PROPERTY COMPILE_OPTIONS -includeall)
25

Marc Chevrier's avatar
Marc Chevrier committed
26 27
set_property(SOURCE "../example.i"
  PROPERTY GENERATED_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/..")
28 29 30 31

swig_add_library(example1
                 LANGUAGE python
                 OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python2"
Marc Chevrier's avatar
Marc Chevrier committed
32
                 SOURCES ../example.i ../example.cxx)
33 34 35 36 37
set_target_properties (example1 PROPERTIES
  OUTPUT_NAME example
  LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2"
  ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2"
  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2")
38 39 40 41 42 43
target_link_libraries(example1 PRIVATE Python2::Python)

# re-use sample interface file for another plugin
swig_add_library(example2
                 LANGUAGE python
                 OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python3"
Marc Chevrier's avatar
Marc Chevrier committed
44
                 SOURCES ../example.i ../example.cxx)
45 46 47 48 49
set_target_properties (example2 PROPERTIES
  OUTPUT_NAME example
  LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3"
  ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3"
  RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3")
50
target_link_libraries(example2 PRIVATE Python3::Python)
51 52 53 54



add_test (NAME MultiplePython.example1
55
  COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/Python2${PS}$<TARGET_FILE_DIR:example1>"
56 57 58
  "${Python2_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py")

add_test (NAME MultiplePython.example2
59
  COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/Python3${PS}$<TARGET_FILE_DIR:example2>"
60
  "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py")