<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">Le jeu. 23 août 2018 à 13:02, George PF <<a href="mailto:george.p.f@mail.com">george.p.f@mail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
following "modern cmake" conventions I want to create a library where every single file is compiled with an individual define (-D_fileX_, required for a macro which integrates code into every translation unit).<br>
<br>
So following this<br>
<br>
    add_library(mylib SHARED file1.c file2.c)<br>
    target_link_libraries(mylib PUBLIC otherlib)<br>
<br>
I'd like to iterate over all "mylib" source file targets and modify them so that the compiler is called like this:<br>
<br>
    cc -c -o file1.o file1.cc -D_file1_define_<br>
    cc -c -o file1.o file2.cc -D_file2_define_<br>
    etc.<br>
<br>
Is this possible?<br></blockquote><div><br></div><div>You can retrieve the sources associated with a target using SOURCES properties.</div><div><a href="https://cmake.org/cmake/help/latest/prop_tgt/SOURCES.html">https://cmake.org/cmake/help/latest/prop_tgt/SOURCES.html</a><br></div><div><br></div><div>then <br></div><div><a href="https://cmake.org/cmake/help/latest/command/foreach.html">https://cmake.org/cmake/help/latest/command/foreach.html</a><br></div><div>with</div><div><a href="https://cmake.org/cmake/help/latest/command/set_property.html">https://cmake.org/cmake/help/latest/command/set_property.html</a><br></div><div>or</div><div><a href="https://cmake.org/cmake/help/latest/command/set_source_files_properties.html">https://cmake.org/cmake/help/latest/command/set_source_files_properties.html</a><br></div><div><br></div><div>for setting property:</div><div><a href="https://cmake.org/cmake/help/latest/prop_sf/COMPILE_DEFINITIONS.html">https://cmake.org/cmake/help/latest/prop_sf/COMPILE_DEFINITIONS.html</a><br></div><div><br></div><div>on each source file.</div><div><br></div><div>not sure why you want to do that you know that compiler already defined many "standard" macro for you, like __FILE__</div><div><a href="https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros">https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros</a> ? </div><div><br></div></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Eric<br></div></div></div></div></div></div>