use cmake generate expression to simplify some jobs
WuTUT opened this issue · 1 comments
I think there is a simple way to implement these functions
- llvmir_extract_compile_defs_properties
- llvmir_extract_include_dirs_properties
- llvmir_extract_compile_flags
- llvmir_extract_compile_option_properties
if use cmake generate expressions , each function will be only one line.
set(CMD_ARGS "-emit-llvm" ${IN_STANDARD_FLAGS} ${IN_LANG_FLAGS})
add_custom_command(OUTPUT ${FULL_OUT_LLVMIR_FILE}
COMMAND ${LLVMIR_COMPILER} ${CMD_ARGS}
"$<JOIN:$<TARGET_PROPERTY:${DEPENDS_TRGT},COMPILE_OPTIONS>,;>"
"$<JOIN:$<TARGET_PROPERTY:${DEPENDS_TRGT},COMPILE_FLAGS>,;>"
"-D$<JOIN:$<TARGET_PROPERTY:${DEPENDS_TRGT},COMPILE_DEFINITIONS>,;-D>"
"-I$<JOIN:$<TARGET_PROPERTY:${DEPENDS_TRGT},INCLUDE_DIRECTORIES>,;-I>"
-c ${ABS_IN_FILE} -o ${FULL_OUT_LLVMIR_FILE}
DEPENDS ${ABS_IN_FILE}
IMPLICIT_DEPENDS ${LINKER_LANGUAGE} ${ABS_IN_FILE}
COMMENT "Generating LLVM bitcode ${OUT_LLVMIR_FILE}"
COMMAND_EXPAND_LISTS
VERBATIM)
In addition, there is an important benefit: there is no need to recursively fetch the include directories introduced by target_link_library. For instance, if a library is linked publicly, its interface headers will also be visible. I test in my complicated project and it finds all include paths correctly.
The drawback may be the dependency on a higher version of CMake. However, I haven't tested whether this code works on cmake-version 3.0.
Hi there, the support for generator expressions has evolved since before v3.0.
As far as I know, things like TARGET_PROPERTY
do not exist in version 3.0 and I'd like to keep this as widely available as possible.
Speed was never a concern.