MantisBT - CMake
View Issue Details
0013171CMakeCMakepublic2012-04-26 14:152012-09-03 16:02
bungeman 
Brad King 
normalminoralways
closednot fixable 
LinuxUbuntu12.04
CMake 2.8.8 
 
0013171: Default target LINKER_LANGUAGE un-gettable.
This was first reported on the mailing list here

http://www.cmake.org/pipermail/cmake/2009-May/029570.html [^]

but apparently it never made it to the bug tracker as was suggested in the reply. However, I recently ran into this issue. The basic problem is that the defaults of many properties cannot be retrieved. CMake obviously knows what the values are, but will not expose them.
Put something like the following into a CMakeLists.txt

add_executable(target
  target.c
)
get_target_property(TARGET_LINKER_LANGUAGE target LINKER_LANGUAGE)
message("TARGET_LINKER_LANGUAGE = ${TARGET_LINKER_LANGUAGE}")
if(${TARGET_LINKER_LANGUAGE} EQUAL "CXX")
set_property(TARGET target APPEND PROPERTIES COMPILE_FLAGS "-fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -Wno-deprecated ")
endif()
unset(TARGET_LINKER_LANGUAGE)

The output looks like

TARGET_LINKER_LANGUAGE = TARGET_LINKER_LANGUAGE-NOTFOUND

and of course the 'if' will never evaluate to true.
No tags attached.
Issue History
2012-04-26 14:15bungemanNew Issue
2012-04-26 14:21Brad KingNote Added: 0029350
2012-04-26 14:21Brad KingStatusnew => resolved
2012-04-26 14:21Brad KingResolutionopen => not fixable
2012-04-26 14:21Brad KingAssigned To => Brad King
2012-09-03 16:02David ColeNote Added: 0030897
2012-09-03 16:02David ColeStatusresolved => closed

Notes
(0029350)
Brad King   
2012-04-26 14:21   
The properties do not document that they can be retrieved. They document that the project can SET them explicitly. Most of the time the default is NOT known while the CMakeLists.txt files are being processed. The value is not computed until the *generate* step. In this case especially there is not sufficient information available until the generate step to compute the final default value.

Your project will have to keep track by itself whether it adds C++ sources or not. Alternatively it can just put the flags in CMAKE_CXX_FLAGS and they will be used for compiling C++ sources but not C. Ask for more detail on the mailing list if you need further help.
(0030897)
David Cole   
2012-09-03 16:02   
Closing resolved issues that have not been updated in more than 4 months.