@@ -39,8 +39,28 @@ include(CTest)
3939
4040# Options
4141option (DOWNLOAD_SOURCES "Automatically download the Python sources" ON )
42- option (BUILD_SHARED "Build a shared libpython library" OFF )
43- option (BUILD_STATIC "Build a static libpython library" ON )
42+ set (_build_libpython_shared_default 0)
43+ set (_build_libpython_shared_desc "Build libpython as a shared library" )
44+
45+ if (DEFINED BUILD_SHARED OR DEFINED BUILD_STATIC)
46+ message (AUTHOR_WARNING "Deprecated options `BUILD_SHARED` or `BUILD_STATIC` are set, "
47+ "please change configure options to use `BUILD_LIBPYTHON_SHARED` instead." )
48+ if (BUILD_SHARED AND BUILD_STATIC)
49+ message (AUTHOR_WARNING "Both BUILD_SHARED and BUILD_STATIC options are set to ON. Forcing BUILD_SHARED to OFF" )
50+ endif ()
51+ if (BUILD_STATIC)
52+ set (_build_libpython_shared_default 0)
53+ set (_build_libpython_shared_desc "Intialized from `BUILD_STATIC` (deprecated)" )
54+ elseif (BUILD_SHARED)
55+ set (_build_libpython_shared_default 1)
56+ set (_build_libpython_shared_desc "Intialized from `BUILD_SHARED` (deprecated)" )
57+ endif ()
58+ message (AUTHOR_WARNING "Unsetting cache variables BUILD_SHARED and BUILD_STATIC" )
59+ unset (BUILD_SHARED CACHE )
60+ unset (BUILD_STATIC CACHE )
61+ endif ()
62+
63+ option (BUILD_LIBPYTHON_SHARED ${_build_libpython_shared_desc} ${_build_libpython_shared_default} )
4464option (BUILD_EXTENSIONS_AS_BUILTIN "Default all modules as builtin to libpython" OFF )
4565option (USE_LIB64 "Search for dependencies and install to prefix/lib64 instead of prefix/lib" OFF )
4666if (WIN32 )
@@ -121,11 +141,8 @@ if(UNIX)
121141 set (BUILD_EXTENSIONS_AS_BUILTIN ON CACHE BOOL "Forced to ON${_reason} " FORCE )
122142 message (STATUS "Setting BUILD_EXTENSIONS_AS_BUILTIN to ON${_reason} " )
123143
124- set (BUILD_SHARED OFF CACHE BOOL "Forced to OFF${_reason} " FORCE )
125- message (STATUS "Setting BUILD_SHARED to OFF${_reason} " )
126-
127- set (BUILD_STATIC ON CACHE BOOL "Forced to ON${_reason} " FORCE )
128- message (STATUS "Setting BUILD_STATIC to ON${_reason} " )
144+ set (BUILD_LIBPYTHON_SHARED OFF CACHE BOOL "Forced to OFF${_reason} " FORCE )
145+ message (STATUS "Setting BUILD_LIBPYTHON_SHARED to OFF${_reason} " )
129146 endif ()
130147 endif ()
131148else ()
@@ -234,6 +251,14 @@ if(PY_VERSION_MAJOR VERSION_GREATER 2)
234251 set (IS_PY2 0)
235252endif ()
236253
254+ # Convenience boolean variables to easily test the type of python library being build
255+ set (BUILD_STATIC 1)
256+ set (BUILD_SHARED 0)
257+ if (BUILD_LIBPYTHON_SHARED)
258+ set (BUILD_STATIC 0)
259+ set (BUILD_SHARED 1)
260+ endif ()
261+
237262# Options depending of the python version
238263if (IS_PY2)
239264 option (Py_USING_UNICODE "Enable unicode support" ON )
0 commit comments