>>     foreach(x IN LISTS mysrcs)
>>         message("at ${x}")
>>         set_property(SOURCE x APPEND PROPERTY COMPILE_DEFINITIONS 
>> "TEST1;TEST2;")
>
> almost there but you forgot to take value of 'x'
>
> set_property(SOURCE ${x} APPEND PROPERTY COMPILE_DEFINITIONS "TEST1;TEST2;")
>
> works for me.

Thank you very much, now it indeed works.


FTR, extracted into a separate 'add_library_with_defs' function in the toplevel 
CMakeLists.txt


    function(add_library_with_defs libname libtype)
        math(EXPR endindex "${ARGC}-1")
        set(files)
        foreach(index RANGE 2 ${endindex})
            list(GET ARGV ${index} arg)
            list(APPEND files ${arg})
        endforeach()
    
        add_library("${libname}" "${libtype}" "${files}")
    
        get_property(mysrcs TARGET "${libname}" PROPERTY SOURCES)
        foreach(x IN LISTS mysrcs)
            # message("${libname}: at ${x}")
            set_property(SOURCE ${x} APPEND PROPERTY COMPILE_DEFINITIONS TEST1 
TEST2)
        endforeach()
    endfunction()


so now it is simplified to: add_library_with_defs(mylib SHARED file1.c file2.c)
-- 

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

Reply via email to