cmake/Tests/FindPython/SOABI/CMakeLists.txt

42 lines
1.3 KiB
CMake
Raw Normal View History

2023-07-02 19:51:09 +02:00
cmake_minimum_required(VERSION 3.5)
2020-08-30 11:54:41 +02:00
2021-09-14 00:13:48 +02:00
project(TestSOABI LANGUAGES C)
2020-08-30 11:54:41 +02:00
2023-12-07 09:12:54 +01:00
if(CMake_TEST_FindPython3)
find_package(Python3 COMPONENTS ${CMake_TEST_FindPython_COMPONENT})
if (NOT Python3_FOUND)
message (FATAL_ERROR "Failed to find Python 3")
endif()
2020-08-30 11:54:41 +02:00
2023-12-07 09:12:54 +01:00
if(NOT DEFINED Python3_SOABI)
message(FATAL_ERROR "Python3_SOABI for ${CMake_TEST_FindPython_COMPONENT} not found")
endif()
2020-08-30 11:54:41 +02:00
2023-12-07 09:12:54 +01:00
if (Python3_Development_FOUND AND Python3_SOABI)
Python3_add_library (spam3 MODULE WITH_SOABI ../spam.c)
target_compile_definitions (spam3 PRIVATE PYTHON3)
2020-08-30 11:54:41 +02:00
2023-12-07 09:12:54 +01:00
get_property (suffix TARGET spam3 PROPERTY SUFFIX)
if (NOT suffix MATCHES "^.${Python3_SOABI}")
message(FATAL_ERROR "Module suffix do not include Python3_SOABI")
endif()
2020-08-30 11:54:41 +02:00
endif()
endif()
2023-12-07 09:12:54 +01:00
if(CMake_TEST_FindPython2)
find_package(Python2 COMPONENTS ${CMake_TEST_FindPython_COMPONENT})
if(NOT DEFINED Python2_SOABI)
message(FATAL_ERROR "Python2_SOABI for ${CMake_TEST_FindPython_COMPONENT} not found")
endif()
2020-08-30 11:54:41 +02:00
2023-12-07 09:12:54 +01:00
if (Python2_Development_FOUND AND Python2_SOABI)
Python2_add_library (spam2 MODULE WITH_SOABI ../spam.c)
target_compile_definitions (spam2 PRIVATE PYTHON2)
2020-08-30 11:54:41 +02:00
2023-12-07 09:12:54 +01:00
get_property (suffix TARGET spam2 PROPERTY SUFFIX)
if (NOT suffix MATCHES "^.${Python2_SOABI}")
message(FATAL_ERROR "Module suffix do not include Python2_SOABI")
endif()
2020-08-30 11:54:41 +02:00
endif()
endif()