[CMake] set_target_properties not setting COMPILE_DEFINITIONS?

Michael Hertling mhertling at online.de
Tue Mar 29 17:34:37 EDT 2011


On 03/29/2011 04:14 PM, David Doria wrote:
>> Most likely coming from here:
>> /home/doriad/src/CMake/Modules/UsewxWidgets.cmake(72): SET(CMAKE_CXX_FLAGS
>> ${CMAKE_CXX_FLAGS} ${wxWidgets_CXX_FLAGS} )
> 
> I added:
> message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
> 
> and the output is:
> 
> CMAKE_CXX_FLAGS:  -pthread  -ftemplate-depth-50 -Wall -Wno-deprecated
> 
>> Hmm, there is also this:
>>
>> /home/doriad/src/CMake/Modules/UsewxWidgets.cmake(60):
>> SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
>> ${wxWidgets_DEFINITIONS} )
>>
>>
>> I wonder if the directory properties are causing the trouble some how.
>>
>> If you add a message to print out CMAKE_CXX_FLAGS you should see that stuff.
>>  That should not affect the definitions...  But, the directory property
>> might be the problem.  You could try that in the small example.
> 
> I added the SET_PROPERTY line to the small example:
> 
> list(APPEND myvariable "UNIX")
> list(APPEND myvariable "DAVID")
> message("myvariable: ${myvariable}")
> message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
> SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
> ${wxWidgets_DEFINITIONS} )
> set_target_properties(CompilerFlags PROPERTIES COMPILE_DEFINITIONS
> ${myvariable})
> 
> and it still works correctly (the flags are passed to the compiler in
> the make VERBOSE=1 output).
> 
> I then added
> 
> find_package(wxWidgets COMPONENTS core base REQUIRED)
> include( ${wxWidgets_USE_FILE} )
> 
> so that ${wxWidgets_DEFINITIONS} was actually defined and the small
> example still worked correctly (make VERBOSE=1 shows:
> 
> /usr/lib/ccache/c++   -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES
> -D__WXGTK__ -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -DUNIX
> -DDAVID -pthread -g -isystem
> /usr/lib/wx/include/gtk2-unicode-release-2.8 -isystem
> /usr/include/wx-2.8    -o
> CMakeFiles/CompilerFlags.dir/CompilerFlags.cxx.o -c
> /media/portable/Examples/CMake/CompilerFlags/CompilerFlags.cxx
> 
> where it previously showed:
> 
> /usr/lib/ccache/c++   -DUNIX -DDAVID -g   -o
> CMakeFiles/CompilerFlags.dir/CompilerFlags.cxx.o -c
> /media/portable/Examples/CMake/CompilerFlags/CompilerFlags.cxx
> 
> Any more suggestions?

An inspection of your CMakeLists.txt file [1] and the outputs
of "make VERBOSE=1" [2,3] reveals the following goings-on:

In [2], the lines 13 and 16 generate the object files

CMakeFiles/Tech.dir/src/tech/Pch.cpp.o
CMakeFiles/Tech.dir/src/tech/tech/Atomic.cpp.o

and obviously, these are compiled for the target "Tech".
The same holds for [3] in line 13 with the object file

CMakeFiles/ImageCompleterLib.dir/src/image-completer-cmd/AppData.cpp.o

belonging to the target "ImageCompleterLib".

Now, in [1], you impose the COMPILE_DEFINITIONS property on the target
"ImageCompleter1f" only, and of course, these definitions don't appear
in compilation lines for targets other than the latter. So, impose the
COMPILE_DEFINITIONS property on the other targets as well, and you'll
probably see them appear in the compilation lines as desired.

Regards,

Michael

[1] http://pastebin.com/SWZgmJ33
[2] http://pastebin.com/zXaj9kWS
[3] http://pastebin.com/X0t0L4Jv


More information about the CMake mailing list