[CMake] Compiler varience?

Brad King brad.king at kitware.com
Tue Sep 9 15:08:54 EDT 2008


Bill Hoffman wrote:
> Preston A. Elder wrote:
>> That does help a lot, but I think does not go quite far enough.
>>
>> As I said, there are other things that need to be done such as:
>> - Adjusting warning levels (CMAKE_WARN_LEVEL=(None|Full|Standard) )
>> - Forcing a 32-bit or 64-bit compile
>> - Allowing for platform-specific builds if possible (ie. don't maintain
>> i386 compatibility, compile specifically for i686).
>>
>> Most of these can be done in all supported compilers, but the flags for
>> doing so are different per-compiler.  Since the Platform directory
>> exists (thanks for pointing it out, I didn't see it before), is there
>> any thoughts on an effort to expand this to more than just optimization
>> and debug flags?
>>
> 
> I can not seem to find the bug entry, but there is a long term goal of
> having a more feature based set of options.  Things like
> CMAKE_WARN_LEVEL.  Brad King might want to comment more on this, but the
> short answer is yes, but it is a ways off.

I've been wanting to implement something like this for years, but
haven't had the time to actually do it.  The feature would work in terms
of directory, target, and source file properties.  It would be similar
to the COMPILE_DEFINITIONS properties:

http://www.cmake.org/Wiki/CMake_2.6_Notes#Preprocessor_Definitions
http://www.cmake.org/HTML/cmake-2.6.html#prop_dir:COMPILE_DEFINITIONS
http://www.cmake.org/HTML/cmake-2.6.html#prop_tgt:COMPILE_DEFINITIONS
http://www.cmake.org/HTML/cmake-2.6.html#prop_sf:COMPILE_DEFINITIONS

and their per-configuration equivalents.  Such a property might accept
one out of an enumerated list of pre-defined possible values.  Each
value would map to the appropriate flag for the native tool.

It might look something like this:

# Apply to all targets in this directory and below.
set_directory_properties(PROPERTIES
  OPTIMIZATION_LEVEL_DEBUG none  # no optimizations for Debug
  OPTIMIZATION_LEVEL_RELEASE max # max optimizations for Release
  OPTIMIZATION_LEVEL default     # compiler default for other configs
  WARNING_LEVEL none # disable all warnings in all configurations
  )
# apply to 'tiny' executable, overriding directory default
set_property(TARGET tiny PROPERTY
  OPTIMIZATION_LEVEL size # optimize for size in all configurations
  )

Of course we could create commands or macros to shorten the syntax for
common cases.

Please submit a feature request to the bug tracker.  I don't know when
we can get to it, but at least there will be a record of discussion.

-Brad


More information about the CMake mailing list