Hi,

I'd like to compile different source files with slightly different
flags, calculating the flags dependent on source file properties.

The easiest example would be different warning flags for all generated
sources, as I have little influence over this code.

The only way I can think of doing this would be to remove the global
warning flag definitions from the toplevel CMakeLists.txt, and instead
have that define two different variables for the positive and negative
forms of a particular warning flag, dependent on compiler, and then
define the flag explicitly as source properties in each directory:

if(GCC or CLANG)
    # determine if it actually supports -Wshadow ...
    set(WARN_SHADOW_ON "-Wshadow")
    set(WARN_SHADOW_OFF "-Wno-shadow")
endif()

and later on

    set(TARGET1_NON_GENERATED_FILES ... )
    set(TARGET1_GENERATED_FILES ...)

    add_executable(target1
        ${TARGET1_GENERATED_FILES}
        ${TARGET1_NON_GENERATED_FILES})

    set_property(
        SOURCE ${TARGET1_NON_GENERATED_FILES}
        APPEND_STRING
        PROPERTY COMPILE_FLAGS
            "${WARN_SHADOW_ON} ")
    set_property(
        SOURCE ${TARGET1_GENERATED_FILES}
        APPEND_STRING
        PROPERTY COMPILE_FLAGS
            "${WARN_SHADOW_OFF} ")

All of this is rather ugly, and escalates even more as there are more
different classes of source files.

What I'd like to see is something like a generator expression that is
evaluated once per source file, that would allow me to have a global
definition

    string(APPEND CMAKE_CXX_FLAGS
"$<IF:$<SOURCE_PROPERTY:GENERATED>,${WARN_SHADOW_OFF},${WARN_SHADOW_ON}> ")

Since there is already a mechanism to carry the per-source COMPILE_FLAGS
property into the compile flags for the source file, I wonder if that
could be extended to a generic mechanism to derive source specific
compile flags from source properties?

   Simon

Attachment: signature.asc
Description: OpenPGP digital signature

-- 

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake-developers

Reply via email to