[CMake] Set different compilation flags for specific file

James Bigler bigler at cs.utah.edu
Tue Jun 12 15:26:45 EDT 2007


Hi, is there something I'm missing here?  I can't get the changed flags to be 
applied to the library (ADD_LIBRARY(expon "ExponSSE.cc")).

James

James Bigler wrote:
> I also tried making it its own library, but that didn't work:
> 
> ADD_LIBRARY(mylib ${source_files})
> 
> SET(CMAKE_CXX_FLAGS_RELEASE_SAVED ${CMAKE_CXX_FLAGS_RELEASE}  )
> SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -g3"  )
> ADD_LIBRARY(expon "ExponSSE.cc")
> SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE_SAVED}  )
> 
> TARGET_LINK_LIBRARIES(mylib expon)
> 
> OUTPUT of make VERBOSE=1 (which is wrong).
> 
> [  0%] Building CXX object CMakeFiles/expon.dir/ExponSSE.o
> /usr/bin/g++-4.0   -Dexpon_EXPORTS -msse -msse2 -DSCI_NOPERSISTENT 
> -march=pentium4 -mtune=pentium4  -msse -msse2 -msse3 -mfpmath=sse  -O3 
> -DNDEBUG -g3 -fgcse-sm -funroll-loops -fstrict-aliasing 
> -fsched-interblock -ffast-math -freorder-blocks -fPIC 
> -I/home/scinew/bigler/manta/rtsl/manta-test/opt 
> -I/home/scinew/bigler/manta/rtsl/manta-test 
> -I/home/sci/bigler/manta/trunk -I/home/sci/bigler/manta/trunk/SCIRun 
> -I/home/sci/bigler/manta/trunk/SCIRun/include 
> -I/home/sci/bigler/manta/trunk/opt-4.0.2/include   -o 
> CMakeFiles/expon.dir/ExponSSE.o -c 
> /home/scinew/bigler/manta/rtsl/manta-test/ExponSSE.cc
> 
> ===============================================
> I put MESSAGE statements around, and it looks like it is changing 
> CMAKE_CXX_FLAGS_RELEASE.  Is there something I'm missing?
> 
> James Bigler wrote:
>> So I can't set this for a single source file, but rather a library?
>>
>> Can I add additional sources to the library after I added the library:
>>
>> ADD_LIBRARY(mylib ${other_sources})
>> SET(CMAKE_CXX_FLAGS_RELEASE_SAVED ${CMAKE_CXX_FLAGS_RELEASE}  )
>> SET(CMAKE_CXX_FLAGS_RELEASE "/MT /Ox /Ob1 /DNDEBUG"  )
>> ADD_LIBRARY(mylib ${special_file})
>> SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE_SAVED}  )
>>
>> This didn't seem to work.
>>
>> James
>>
>> Rob Mathews wrote:
>>> Put it in that one file like this:
>>> SET(CMAKE_CXX_FLAGS_RELEASE_SAVED ${CMAKE_CXX_FLAGS_RELEASE}  )
>>> SET(CMAKE_CXX_FLAGS_RELEASE "/MT /Ox /Ob1 /DNDEBUG"  )
>>> .. add the library or target
>>> SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE_SAVED}  )
>>>
>>> -----Original Message-----
>>> From: James Bigler [mailto:bigler at cs.utah.edu] Sent: Tuesday, June 
>>> 12, 2007 1:38 PM
>>> To: Rob Mathews
>>> Cc: cmake at cmake.org
>>> Subject: Re: [CMake] Set different compilation flags for specific file
>>>
>>> Wouldn't that set it for all the source files in the project?  I just
>>> want to override 1 file amongst many others.
>>>
>>> Rob Mathews wrote:
>>>> Why wouldn't you simply do this:
>>>>
>>>> SET(CMAKE_CXX_FLAGS_RELEASE "/MT /Ox /Ob1 /DNDEBUG"  )
>>>>
>>>> (or whatever your particular flags are)
>>>> ?
>>>>
>>>> -----Original Message-----
>>>> From: cmake-bounces+rmathews=envoyww.com at cmake.org
>>>> [mailto:cmake-bounces+rmathews=envoyww.com at cmake.org] On Behalf Of
>>> James
>>>> Bigler
>>>> Sent: Tuesday, June 12, 2007 1:14 PM
>>>> To: cmake at cmake.org
>>>> Subject: [CMake] Set different compilation flags for specific file
>>>>
>>>> I have a file that doesn't compile properly with certain optimization
>>>> flags that I wish to use on the rest of my system.  I poked around 
>>>> the wiki and
>>> the
>>>> help file, but I can't find any information on how to do this.
>>>>
>>>> According to the documentation SET_SOURCE_FILES_PROPERTIES
>>> COMPILE_FLAGS
>>>> only appends new flags.  I want to override the values in 
>>>> CMAKE_CXX_FLAGS
>>> and
>>>> CMAKE_CXX_FLAGS_RELEASE.
>>>>
>>>> Thanks,
>>>> James
>>>> _______________________________________________
>>>> CMake mailing list
>>>> CMake at cmake.org
>>>> http://www.cmake.org/mailman/listinfo/cmake
>>>>
>>>>
>>>
>>>
>> _______________________________________________
>> CMake mailing list
>> CMake at cmake.org
>> http://www.cmake.org/mailman/listinfo/cmake
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list