Cannot forward all compiler and linker options to custom command (for building a Python extension module)
I have a large project with many libraries and executables, and one target that must be built by an external build system (specifically, a Python extension module, where setuptools
invokes the compiler). The extension module's shared library depends on many CMake targets from the surrounding project, with various compiler options, definitions, includes, linker args, link libraries, etc, in addition to those options CMake itself would pass. The external tool can be invoked via add_custom_command
, but it's impossible to pass it the correct options.
Using $<TARGET_PROPERTY>
for COMPILE_DEFINITIONS
/ COMPILE_OPTIONS
/ INCLUDE_DIRECTORIES
/ LINK_DIRECTORIES
/ LINK_LIBRARIES
/ LINK_OPTIONS
is not enough. First, LINK_LIBRARIES
does not resolve target names to libraries: things like Python::Python
are passed to an external tool. Second, this misses options CMake would pass, like debug and optimization flags. Third, as noted here, these properties are "not sufficient" to reproduce the compile and link lines.
It seems to be impossible to achieve such a simple task. CMake knows what the final lines are; after all, CMake literally generates them for targets it compiles. But it's impossible to generate these values for an external tool, like setup.py
.