When building a plugin against an installed LLVM toolchain using add_llvm_loadable_module (in the documented manner) doesn't work as nothing sets the *_OUTPUT_INTDIR variables causing an error when set_output_directory is called. Making those arguments optional (causing the default output directory to be used) fixes this.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
cmake/modules/AddLLVM.cmake | ||
---|---|---|
206 ↗ | (On Diff #35877) | I think that a better way to do this would be to use cmake_parse_arguments and make output and bind directory be single value options. Then if one isn't specified it is ignored. I also think it would be cleaner if set_target_properties were only called if the corresponding value is set. |
LGTM, as a step.
That said, I think set_output_directory may be rewritten.
It may be dedicated to set outdir along LLVM_*_OUTPUT_INTDIR, or reset outdir.
cmake/modules/AddLLVM.cmake | ||
---|---|---|
206 ↗ | (On Diff #35877) | I had thought of using cmake_parse_arguments, but decided against it as it would involve changing how set_output_directory is called. It's only called in three places though, so actually that won't be too much trouble. I'll give it a go. |
I've gone with the suggestion of using cmake_parse_arguments. I haven't gone for calling set_target_properties is the argument is set, instead of the check at the start, mainly as I'm not sure how moddir would be handled if that were done.
I think all you need to do for handling unset values is something like this:
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 993bc35..63047e6 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -211,17 +211,33 @@ function(set_output_directory target) if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") foreach(build_mode ${CMAKE_CONFIGURATION_TYPES}) string(TOUPPER "${build_mode}" CONFIG_SUFFIX) - string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${ARG_BINDIR}) - string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${ARG_LIBDIR}) - string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${moddir}) - set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi}) - set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li}) - set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi}) + if(ARG_BINDIR) + string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${ARG_BINDIR}) + set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi}) + endif() + + if(ARG_LIBDIR) + string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${ARG_LIBDIR}) + set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li}) + endif() + + if(moddir) + string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${moddir}) + set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi}) + endif() endforeach() else() - set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ARG_BINDIR}) - set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${ARG_LIBDIR}) - set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${moddir}) + if(ARG_BINDIR) + set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ARG_BINDIR}) + endif() + + if(ARG_LIBDIR) + set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${ARG_LIBDIR}) + endif() + + if(moddir) + set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${moddir}) + endif() endif() endfunction()
I have one other comment below.
Thanks,
-Chris
cmake/modules/AddLLVM.cmake | ||
---|---|---|
197 ↗ | (On Diff #35980) | Two things here.
|