blt
blt copied to clipboard
Language-based generator expressions
@mclarsen came across a problem with the openmp generator expressions that were introduced in #190.
In his BLT-based code (ascent), the main library was built with Fortran support (ENABLE_FORTRAN=ON
) and openmp support (ENABLE_OPENMP=ON
). He then has a C++
example application that uses the installed version of this library.
The example application pulls in the cmake install file for the library, which has Fortran generator expressions in its link flags, leading to a (non-terminal, but annoying) cmake error:
CMake Error at CMakeLists.txt:82 (target_link_libraries):
Error evaluating generator expression:
$<COMPILE_LANGUAGE:Fortran>
$<COMPILE_LANGUAGE:...> Unknown language.
Here is a sanitized version of the offending lines in the generated cmake install file from the library:
set_target_properties(ascent PROPERTIES
INTERFACE_COMPILE_OPTIONS "<some-compile-options>;\$<\$<NOT:\$<COMPILE_LANGUAGE:Fortran>>:-fopenmp>;\$<\$<COMPILE_LANGUAGE:Fortran>:-fopenmp>"
INTERFACE_INCLUDE_DIRECTORIES "<include-dirs>"
INTERFACE_LINK_LIBRARIES "<link-flags>"
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "<system-includes>"
)
Note: It seems that this warning has been removed from newer versions of cmake (i.e. versions greater than 3.12 -- see https://gitlab.kitware.com/cmake/cmake/merge_requests/2031).
Thoughts: @rblake-llnl (or others)
Cross referencing with #175. In that commit, @gzagaris has a library that has different OpenMP flags when using CXX and Fortran.
I'm not sure what the good answer here is. On the one hand, it's less than ideal if generator expressions leak out of the project that uses them because they might use different languages and cause the annoying error seen above for older cmake versions.
On the other hand, if CXX, CUDA, and Fortran do require different flags, shouldn't the calling code know that?
Does #206 fix the problem?
@mclarsen -- please check out PR #206 for the cmake error that you reported, when you get a chance.
Thanks @rblake-llnl!
This is a problem with CMake not being able to evaluate any generator expression with COMPILE_LANGUAGE:Fortran in it unless Fortran is enabled as a language. I hit this again today.