38 lines
1.2 KiB
CMake
Raw Normal View History

2024-07-09 14:46:46 +02:00
cmake_minimum_required(VERSION 3.15)
2020-08-30 11:54:41 +02:00
2021-09-14 00:13:48 +02:00
project(TestPython2Module LANGUAGES C)
2020-08-30 11:54:41 +02:00
include(CTest)
find_package(Python2 REQUIRED COMPONENTS Interpreter Development.Module)
if (NOT Python2_FOUND)
2021-09-14 00:13:48 +02:00
message (FATAL_ERROR "Failed to find Python 2")
2020-08-30 11:54:41 +02:00
endif()
if (Python2_Development_FOUND)
message (FATAL_ERROR "Python 2, COMPONENT 'Development' unexpectedly found")
endif()
if (Python2_Development.Embed_FOUND)
message (FATAL_ERROR "Python 2, COMPONENT 'Development.Embed' unexpectedly found")
endif()
if (NOT Python2_Development.Module_FOUND)
message (FATAL_ERROR "Python 2, COMPONENT 'Development.Module' not found")
endif()
if(NOT TARGET Python2::Interpreter)
message(SEND_ERROR "Python2::Interpreter not found")
endif()
if(TARGET Python2::Python)
message(SEND_ERROR "Python2::Python unexpectedly found")
endif()
if(NOT TARGET Python2::Module)
message(SEND_ERROR "Python2::Module not found")
endif()
Python2_add_library (spam2 MODULE ../spam.c)
target_compile_definitions (spam2 PRIVATE PYTHON2)
add_test (NAME python2_spam2
COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:spam2>"
2024-07-09 14:46:46 +02:00
"${Python2_INTERPRETER}" -c "import spam2; spam2.system(\"cd\")")