Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cmake generate expression to simplify some jobs #37

Open
WuTUT opened this issue Jun 9, 2024 · 1 comment
Open

use cmake generate expression to simplify some jobs #37

WuTUT opened this issue Jun 9, 2024 · 1 comment

Comments

@WuTUT
Copy link

WuTUT commented Jun 9, 2024

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.

@compor
Copy link
Owner

compor commented Jul 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants