Skip to content

Commit

Permalink
Fix compiling with a cleaner solution
Browse files Browse the repository at this point in the history
As stated
[here](https://docs.python.org/3/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build),
starting from Python 3.8 `python3-config` has to be called with
`--embed` in order to link to python itself.
To be backwards compatible it should always be tried with `--embed` and
when it fails retrying without.
This is the logic implemented.
  • Loading branch information
jandamm committed Jul 29, 2020
1 parent 53dd5e7 commit 7e777fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ find_package(Boost REQUIRED COMPONENTS program_options)
include_directories(${Boost_INCLUDE_DIRS})

if(PY3)
set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4 3.3)
set(Python_ADDITIONAL_VERSIONS 3.8 3.7 3.6 3.5 3.4 3.3)
find_package(PythonInterp 3 REQUIRED)
else()
set(Python_ADDITIONAL_VERSIONS 2.7 2.6)
Expand All @@ -46,7 +46,7 @@ set_target_properties(cpsm_core PROPERTIES COMPILE_FLAGS "-fPIC")
add_library(cpsm_py SHARED src/ctrlp_util.cc src/python_extension.cc)
target_link_libraries(cpsm_py cpsm_core)
set_target_properties(cpsm_py PROPERTIES COMPILE_FLAGS ${PYTHON_COMPILE_FLAGS})
set_target_properties(cpsm_py PROPERTIES LINK_FLAGS "${PYTHON_LINK_FLAGS} -lpython3.8")
set_target_properties(cpsm_py PROPERTIES LINK_FLAGS ${PYTHON_LINK_FLAGS})
set_target_properties(cpsm_py PROPERTIES PREFIX "")
if(APPLE)
set_target_properties(cpsm_py PROPERTIES SUFFIX ".so")
Expand Down
6 changes: 5 additions & 1 deletion cmake/FindPythonConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ find_package(PythonInterp)
if(PYTHONINTERP_FOUND)
set(_Python_config "${PYTHON_EXECUTABLE}-config")
execute_process(COMMAND ${_Python_config} "--includes" OUTPUT_VARIABLE PYTHON_COMPILE_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${_Python_config} "--ldflags" OUTPUT_VARIABLE PYTHON_LINK_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${_Python_config} "--ldflags" "--embed" OUTPUT_VARIABLE PYTHON_LINK_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_VARIABLE PYTHON_EMBED_FAILED)
if(PYTHON_EMBED_FAILED)
message(STATUS "PythonConfig could not embed Python. (Fine for < Python 3.8)")
execute_process(COMMAND ${_Python_config} "--ldflags" OUTPUT_VARIABLE PYTHON_LINK_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
endif(PYTHON_EMBED_FAILED)
set(_Python_config_message "${PYTHON_COMPILE_FLAGS}; ${PYTHON_LINK_FLAGS}")
unset(_Python_config)
else(PYTHONINTERP_FOUND)
Expand Down

0 comments on commit 7e777fb

Please sign in to comment.