[PATCH] Expose LLVM build flags in LLVMConfig.cmake

Stephen Kelly steveire at gmail.com
Mon Jul 21 12:41:50 PDT 2014


On 07/21/2014 06:14 PM, Dan Liew wrote:
> On 21 July 2014 14:58, Stephen Kelly <steveire at gmail.com> wrote:
>> I don't know what you mean by 'persist'.
> Apologies. By persist I meant that when the target is exported that
> INTERFACE_COMPILE_OPTIONS and  INTERFACE_COMPILE_DEFINITIONS are kept
> as properties on the target so the properties still exist when a
> client imports the targets.

Ah, ok. The built-in INTERFACE_* properties are indeed persisted on export

> Ok. I think the documentation for INTERFACE_COMPILE_* are a little
> misleading because they say things like...
>
> ```
> Consuming targets can add entries to their own COMPILE_OPTIONS property
>        such as $<TARGET_PROPERTY:foo,INTERFACE_COMPILE_OPTIONS> to use
> the compile options specified in the interface of foo.
> ```
>
> which gives the impression that the client has to add the compile
> options/definitions manually rather than it happening automatically.

I think you are correct. I've made a note to clarify that

> That was an interesting read. The '::' looks interesting, is the '::'
> ignored in the name so ``Qt5::Widgets`` refers to the target
> ``Qt5Widgets``?

The '::' is in the name of the target. Look in your local copy of any
Qt5FooConfig.cmake and you will see

 add_library(Qt5::Foo SHARED IMPORTED)

As noted in the blog post, and in the corresponding slide, the '::' is
special in CMake 3.0 in that it is assumed to be an imported target. The
target_link_libraries command accepts libraries which the linker is
assumed to be able to find:

 target_link_libraries(myexe foobar)

and

 target_link_libraries(myexe -lfoobar)

are equivalent. If the parameter contains '::', CMake assumes the entry
is referring to an IMPORTED target, and if it can't find an imported
target with that name, it reports an error instead of blindly adding
-lQt5::Foo to the link line, which will fail. CMake extracts the
location of the library to link to from IMPORTED targets.

The following two snippets produce error diagnostics at CMake time:

# Missing find_package to use the IMPORTED target:
# find_package(Qt5Widgets 5.2 REQUIRED)
add_executable(myapp main.cpp)
target_link_libraries(myapp
  Qt5::Widgets # Error diagnostic
)

...

find_package(Qt5Widgets 5.2 REQUIRED)
add_executable(myapp main.cpp)
# Typo in target name:
target_link_libraries(myapp
  Qt5::Wydjits  # Error diagnostic
)

All examples of IMPORTED targets I use uses '::'.

 http://www.steveire.com/WhatWhyHowCMake.pdf

If the LLVM imported targets didn't already exist as 'LLVMSupport' etc,
I would recommend naming them 'LLVM::Support'.

>  I took a look at
> ``/usr/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake`` on my system and
> I guess it is part of the target name. The ability to set interface
> definitions flags based on the client's build type looks quite handy.
> I couldn't see anything that looked like it would do that in the file
> I mentioned. Am I missing something?

lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake contains

 set_property(TARGET Qt5::Core APPEND PROPERTY
    INTERFACE_COMPILE_DEFINITIONS
    $<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG>)

> I'm not sure LLVM can use it though given the version of CMake that is
> considered the minimum version.

Indeed, but presumably the minimum requirement will change over time,
and it's useful to know what you want to achieve by doing so.

Thanks,

Steve.




More information about the llvm-commits mailing list