summaryrefslogtreecommitdiffstats
path: root/Tests/UseSWIG/SwigSrcFileExtension/CMakeLists.txt
blob: f70ce491d427f80ed89cb623a4c360bdca2e3f40 (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
cmake_minimum_required(VERSION 3.1...3.14)

project(SwigSrcFileExtension C)

include(CTest)
find_package(SWIG REQUIRED)
find_package(Python COMPONENTS Interpreter Development REQUIRED)

include(${SWIG_USE_FILE})

# Use the newer target name preference
set(UseSWIG_TARGET_NAME_PREFERENCE "STANDARD")

# Set the custom source file extension to both .i and .swg
set(SWIG_SOURCE_FILE_EXTENSIONS ".i" ".swg")

# Generate a Python module out of `.i`
swig_add_library(my_add LANGUAGE python SOURCES my_add.i)
target_link_libraries(my_add Python::Module)

# Generate a Python module out of `.swg`
swig_add_library(my_sub LANGUAGE python SOURCES my_sub.swg)
target_link_libraries(my_sub Python::Module)

# Add a test
add_test(NAME SwigSrcFileExtension
  COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}"
  "${Python_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/runme.py")