How cmake links libpython*.so to paddle_trainer
Created by: wangkuiyi
I see that the executable paddle_trainer
is built by paddle/trainer/CMakeLists.txt
using
add_paddle_exe(paddle_trainer TrainerMain.cpp)
where add_paddle_exe
calls link_paddle_exe
defined in cmake/util.cmake
and specifies Python as a dependency:
if(WITH_PYTHON)
target_link_libraries(${TARGET_NAME}
${PYTHON_LIBRARIES})
endif()
I am wondering how cmake
knows the value of PYTHON_LIBRARIES
. After grep
-ing the whole source code repo, I noticed that it is defined in paddle/api/paddle_api_config.py.in
, and paddle_api_config.py
is imported by other Python modules. The importing sequence is as follows:
-
in
paddle/CMakeLists.txt
, cmake convertssetup.py.in
intosetup.py
and thenadd_subdirectory(api)
. Note thatpaddle/setup.py
is listed inpaddle/.gitignore
. -
paddle/setup.py.in
callsimport api.paddle_ld_flags
, wherepaddle/api/paddle_ld_flags.py
runsfrom paddle_api_config import *
-
where
paddle/api/paddle_api_config.py
is generated bypaddle/api/CMakeLists.txt
frompaddle/api/paddle_api_config.py.in
. -
In
paddle/api/paddle_api_config.py.in
, there isPYTHON_LIBRARIES="@PYTHON_LIBRARIES@"
. This implies thatcmake
should have known the value ofPYTHON_LIBRARIES
before it can execute the.in
template.
But how does cmake
knows the value of PYTHON_LIBRARIES
?!
I'd thought that it was set by cmake
standard macro FindPythonInterp
, but the document doesn't say so.