summaryrefslogtreecommitdiffstats
path: root/Tests/UseSWIG/ModuleVersion2/CMakeLists.txt
blob: ded6b2324e1d60f5c3707a3ec5e1c9e0bb09e895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
cmake_minimum_required(VERSION 3.1...3.13)

project(TestModuleVersion2 CXX)

include(CTest)

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

if (WIN32)
  set (PS $<SEMICOLON>)
else()
  set (PS ":")
endif()

set (UseSWIG_MODULE_VERSION 2)
unset(CMAKE_SWIG_FLAGS)

set_property(SOURCE "../example.i" PROPERTY CPLUSPLUS ON)
set_property(SOURCE "../example.i" PROPERTY COMPILE_OPTIONS -includeall)

set_property(SOURCE "../example.i"
  PROPERTY GENERATED_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/..")

if(CMake_TEST_FindPython2)
  find_package(Python2 REQUIRED COMPONENTS Interpreter Development)

  swig_add_library(example1
                   LANGUAGE python
                   SOURCES ../example.i ../example.cxx)
  set_target_properties (example1 PROPERTIES
    OUTPUT_NAME example
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2-1"
    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2-1"
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2-1")
  target_link_libraries(example1 PRIVATE Python2::Module)

  add_test (NAME ModuleVersion2.example1
    COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_PROPERTY:example1,SWIG_SUPPORT_FILES_DIRECTORY>${PS}$<TARGET_FILE_DIR:example1>"
    "${Python2_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py")

  # reuse sample interface file for another plugin
  swig_add_library(example2
                   LANGUAGE python
                   SOURCES ../example.i ../example.cxx)
  set_target_properties (example2 PROPERTIES
    OUTPUT_NAME example
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2-2"
    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2-2"
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2-2")
  target_link_libraries(example2 PRIVATE Python2::Module)

  add_test (NAME ModuleVersion2.example2
    COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_PROPERTY:example2,SWIG_SUPPORT_FILES_DIRECTORY>${PS}$<TARGET_FILE_DIR:example2>"
    "${Python2_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py")
endif()

if(CMake_TEST_FindPython3)
  find_package(Python3 REQUIRED COMPONENTS Interpreter Development)

  swig_add_library(example3
                   LANGUAGE python
                   SOURCES ../example.i ../example.cxx)
  set_target_properties (example3 PROPERTIES
    OUTPUT_NAME example
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3-1"
    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3-1"
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3-1")
  target_link_libraries(example3 PRIVATE Python3::Module)

  add_test (NAME ModuleVersion2.example3
    COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_PROPERTY:example3,SWIG_SUPPORT_FILES_DIRECTORY>${PS}$<TARGET_FILE_DIR:example3>"
    "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py")


  # reuse sample interface file for another plugin
  swig_add_library(example4
                   LANGUAGE python
                   SOURCES ../example.i ../example.cxx)
  set_target_properties (example2 PROPERTIES
    OUTPUT_NAME example
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3-2"
    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3-2"
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3-2")
  target_link_libraries(example4 PRIVATE Python3::Module)

  add_test (NAME ModuleVersion2.example4
    COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_PROPERTY:example4,SWIG_SUPPORT_FILES_DIRECTORY>${PS}$<TARGET_FILE_DIR:example4>"
    "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py")
endif()