[cmake-developers] Introducing the ${Foo_TARGETS} variable (IntroduceTARGETSVariable branch)

Stephen Kelly steveire at gmail.com
Sun Aug 4 08:40:46 EDT 2013


Alexander Neundorf wrote:

> On Monday 29 July 2013, Stephen Kelly wrote:
>> Alexander Neundorf wrote:
>> > So it can be used in tll() calls to link against the library (package).
>> > What makes it differ from Foo_LIBRARIES, is that CMake checks that each
>> > of the items listed in this variable
>> > * is an existing target
>> > 
>> > * has the INTERFACE_INCLUDE_DIRS property set.
>> 
>> Are you really certain it is always an error for a target to not set
>> this?
> 
> I think so.
> If I want to use symbols from a library, I should include its headers, and
> for that the include dirs need to be known.
> 
> For header-only libraries even more.
> 
> Are there cases where this is not the case ?

There will/can be in the future.

 add_library(picon INTERFACE)
 set_property(TARGET picon INTERFACE_POSITION_INDEPENDENT_CODE ON)

 add_library(picoff INTERFACE)
 set_property(TARGET picoff INTERFACE_POSITION_INDEPENDENT_CODE ON)

 ...

 # Use linking to psuedo targets to enable compiler options:
 add_executable(foo main.cpp)
 target_link_libraries(foo PRIVATE picon)

 add_executable(bar main.cpp)
 target_link_libraries(bar PRIVATE picoff)

Or:

 add_library(cxx11features INTERFACE)
 set_property(TARGET cxx11features 
   INTERFACE_COMPILE_OPTIONS 
     $<$<CXX_COMPILER_ID:GNU>:-std=c++0x>
     $<$<CXX_COMPILER_ID:Clang>:-std=c++11>
 )
 set(IS_GNU $<CXX_COMPILER_ID:GNU>)
 set(IS_46 $<VERSION_GREATER:$<CXX_COMPILER_VERSION>,4.6>)
 set_property(TARGET cxx11features 
   INTERFACE_COMPILE_DEFINITIONS
     $<$<AND:${IS_GNU},${IS_46}>:CXXFEATURES_NULLPTR_FOUND>
 )

 # Possibly also specify libcxx compiler option if using 
 # recent clang on apple.

 ...

 add_executable(foo main.cpp)
 target_link_libraries(foo cxx11features)



Thanks,

Steve.





More information about the cmake-developers mailing list