[CMake] Different CMAKE_CXX_FLAGS for different executables
Michael Hertling
mhertling at online.de
Fri Mar 25 00:25:15 EDT 2011
On 03/24/2011 11:39 PM, David Doria wrote:
> On Thu, Mar 24, 2011 at 11:31 AM, Yuri Timenkov <yuri at timenkov.ru> wrote:
>> Use COMPILE_FLAGS target property. Like this:
>>
>> set_target_properties(Exec2 PROPERTIES COMPILE_FLAGS "/flag1 /flag2")
>>
>> You can see full list of properties in CMake documentation. Note that
>> compiler flags may be also set for particular source file with
>> set_source_files_properties command.
>
> Hi Yuri,
>
> I tried a CMakeLists.txt file like this:
>
> cmake_minimum_required(VERSION 2.6)
> PROJECT(SetTargetProperties)
> ADD_EXECUTABLE(SetTargetProperties SetTargetProperties.cxx)
> set_target_properties(SetTargetProperties PROPERTIES COMPILE_FLAGS "-DUNIX")
>
> Then I ran:
>
> make VERBOSE=1
>
> and I don't see anything in the output that indicates that this flag
> was passed, but I also don't see the call to g++ at all. How would I
> check that this worked correctly?
Could you post the output of "make VERBOSE=1"?
On *nix, the following CMakeLists.txt works as expected:
cmake_minimum_required(VERSION 2.6)
PROJECT(SetTargetProperties)
FILE(WRITE ${CMAKE_BINARY_DIR}/SetTargetProperties.cxx
"int main(){return 0;}\n")
ADD_EXECUTABLE(SetTargetProperties SetTargetProperties.cxx)
set_target_properties(SetTargetProperties PROPERTIES COMPILE_FLAGS "-DUNIX")
The output of "make VERBOSE=1" contains:
> .../c++ -DUNIX -o .../SetTargetProperties.cxx.o -c .../SetTargetProperties.cxx
BTW, preprocessor definitions like "-DUNIX" should be set via the
COMPILE_DEFINITIONS properties instead of the COMPILE_FLAGS ones.
Regards,
Michael
More information about the CMake
mailing list