Michael Hertling wrote:

> SET_SOURCE_FILES_PROPERTIES(${CMAKE_BINARY_DIR}/c89.c
>     PROPERTIES COMPILE_FLAGS ${CMAKE_C_DIALECT_C89})
> SET_SOURCE_FILES_PROPERTIES(${CMAKE_BINARY_DIR}/c99.c
>     PROPERTIES COMPILE_FLAGS ${CMAKE_C_DIALECT_C99})
> ADD_LIBRARY(c89 c89.c)
> ADD_LIBRARY(c99 c99.c)
> 
> It issues the supported C dialects and the contents of the associated
> dialect variables, and the c89.c and c99.c source files are compiled
> with the correct flags. Of course, the CMAKE_C_DIALECT_<DIALECT>
> variables can also be appended to the CMAKE_C_FLAGS[_<CONFIG>]
> variables instead of the COMPILE_FLAGS source file property.

With a bit of thinking I would suggest a slightly different way. Don't add 
specific compiler flags for that source file. Tell CMake that this sourcefile 
uses 
a specific language dialect:

SET_SOURCE_FILES_PROPERTIES(${CMAKE_BINARY_DIR}/c89.c
     PROPERTIES LANGUAGE_DIALECT C89)

Then let CMake internally do the fiddling with the compile flags. This would 
have a few benefits:

-if e.g. the language flags need to be passed first to the compiler CMake can 
assure this
-colliding flags can be detected by the underlying implementation
-if we ever get support for e.g. 2 different C compilers things like the Sun 
(was it Sun? Too lazy to look up) compilers can be supported as CMake would 
just call the right compiler binary
-this can easily change in any direction later if someone decides the 
underlying implementation needs a change

Well, basically all points target in the same direction, no? It seperates the 
switch logic from the user and allow greater flexibility in the implementation. 
With the expense that probably some C++ code of CMake needs to be touched.

Eike

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to