FindPython: Python_USE_STATIC_LIBS swallowed without warning on Windows
When using the Find_Python modules on Windows, the Python_USE_STATIC_LIBS is actively swallowed. This appears to be based on magic knowledge that the python project is currently unable to produce static libraries on Windows. (If only they used CMake :(
While this is actually a hint flag, quietly encoding magic knowledge can be surprising to end-users who, elsewhere, who may not have fully cognized that it is actively supressed by CMake on Windows:
Find_Python/Support.cmake:
unset (_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES)
if (DEFINED ${_PYTHON_PREFIX}_USE_STATIC_LIBS AND NOT WIN32)
set(_${_PYTHON_PREFIX}_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(${_PYTHON_PREFIX}_USE_STATIC_LIBS)
set (CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
list (REMOVE_ITEM CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
endif()
Sample CMake:
CMAKE_MINIMUM_REQUIRED(VERSION 3.18)
PROJECT(Test)
SET(Python_USE_STATIC_LIBS ON)
FIND_PACKAGE(Python REQUIRED COMPONENTS Development.embed)
IF (_Python_LIBRARY_TYPE STREQUAL "SHARED")
MESSAGE(FATAL_ERROR "shared python selected.") # Fails on windows
ENDIF()
Discussion thread: https://discourse.cmake.org/t/static-python-on-windows-find-python/4427/2
Edited by Brad King