Get complete compile flags for a target

I have a number of legacy Makefiles I am using through add_custom_command to produce libraries and executables as we slowly port to CMake. One issue I’m having is dealing with the CXX and CUDA target compile flags propagated through depenendent interface libraries that have been ported to CMake.

What I was hoping I can do to stage things is add a proxy CMake target that acts as a placeholder for the eventual library once it’s build can be ported to CMake by doing something like …

add_library(my_lib_proxy STATIC IMPORTED)
target_link_libraries(my_lib_proxy PRIVATE some_other_lib)
target_compile_definitions(my_lib_proxy PRIVATE FOO=1)

  OUTPUT ./my_lib.a

The goal would be to pass the command-line arguments that CMake would pass to the compiler to my Makefile instead. Is there a way to extract the expanded flags from a target somehow?

Currently, a such genex do not exist but I suggest to you to have a look at target property <LANG>_COMPILER_LAUNCHER.

Thanks for the tip. Did you have a trick in mind to use this to accomplish getting the compile flags to pass to an external Makefile?

Not really.

Another approach, may be more user-friendly is to use ExternalProject. This module enables to integrate external build systems as part of a CMake project.