Trouble with variable expansion in target_link_library
Hi,
I have a trouble with cmake
3.11.4 under windows that I can't understand. The same lines of cmake
code do work on LiNuX with various previous versions.
I try to find the name of the Boost.Python
library, which may vary for one system to another. I try various naming scheme. The one that works for me is:
find_package(Boost 1.36.0 COMPONENTS
"python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}"
"numpy${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
if(Boost_PYTHON${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}_FOUND)
set(Boost_PYTHON_LIBRARY "${Boost_PYTHON${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}_LIBRARY}")
What is important here is that I set the Boost_PYTHON_LIBRARY
to the name of the library that matches the one found.
I use this varible as follows:
target_link_libraries(py_test
${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARIES})
message(STATUS "py_test: ${Boost_PYTHON_LIBRARY}")
The message command prints the correct output:
-- py_test: C:/codes/Boost/1.67/install/lib/boost_python36-vc141-mt-x64-1_67.lib
However, the variable expansion in the target_link_libraries
leads to a trouble and the link steps fails with the following message:
LINK : fatal error LNK1104: impossible d'ouvrir le fichier 'boost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-vc141-mt-x64
-1_67.lib'
As I said in the beginning of this post, everything works well with older version of cmake
on various LiNuX distributions. I attached to this post a minimal example exposing the trouble.
Can somebody tell me what I have done wrong ? If this is a cmake
bug, is there a workaround ?
With kind regards,
Thomas Helfer