<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">Le jeu. 23 août 2018 à 18:31, 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">Thank you for the precise pointers, I added to the same CMakeLists.txt:<br>
<br>
get_property(mysrcs TARGET mylib PROPERTY SOURCES)<br>
<br>
foreach(x IN LISTS mysrcs)<br>
message("at ${x}")<br>
set_property(SOURCE x APPEND PROPERTY COMPILE_DEFINITIONS "TEST1;TEST2;")<br>
# set_source_files_properties(x PROPERTIES COMPILE_DEFINITIONS "TEST1;TEST2;") # also not working<br>
endforeach(x)<br>
<br>
However, whatever I write into 'set_property()' - no APPEND, single entry, not quoted - does not end up <br>
on the compiler command line. Is there a type mismatch which is silently ignored?<br></blockquote><div><br></div><div>Or you are doing this in a directory which is not the one where the target is defined and from the doc:</div><div>$ cmake --help-command set_property<br></div><div><br></div><div>...</div><div><div>``SOURCE``</div><div> Scope may name zero or more source files. Note that source</div><div> file properties are visible only to targets added in the same</div><div> directory (CMakeLists.txt).</div></div><div><br></div><div>...</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
As to __FILE__ or similar, the define is used as a variable, i.e. the .c suffix would have to be removed <br>
via the c processor. The current directory is also used. I think replacing .c and appending the name of <br>
the current directory will be easier in cmake.<br>
<br>
<br>
> Le jeu. 23 août 2018 à 13:02, George PF <george.p.f at <a href="http://mail.com" rel="noreferrer" target="_blank">mail.com</a>> a écrit :<br>
> <br>
> > Hello,<br>
> ><br>
> > following "modern cmake" conventions I want to create a library where<br>
> > every single file is compiled with an individual define (-D_fileX_,<br>
> > 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<br>
> > 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>
> ><br>
> <br>
> You can retrieve the sources associated with a target using SOURCES<br>
> properties.<br>
> <a href="https://cmake.org/cmake/help/latest/prop_tgt/SOURCES.html" rel="noreferrer" target="_blank">https://cmake.org/cmake/help/latest/prop_tgt/SOURCES.html</a><br>
> <br>
> then<br>
> <a href="https://cmake.org/cmake/help/latest/command/foreach.html" rel="noreferrer" target="_blank">https://cmake.org/cmake/help/latest/command/foreach.html</a><br>
> with<br>
> <a href="https://cmake.org/cmake/help/latest/command/set_property.html" rel="noreferrer" target="_blank">https://cmake.org/cmake/help/latest/command/set_property.html</a><br>
> or<br>
> <a href="https://cmake.org/cmake/help/latest/command/set_source_files_properties.html" rel="noreferrer" target="_blank">https://cmake.org/cmake/help/latest/command/set_source_files_properties.html</a><br>
> <br>
> for setting property:<br>
> <a href="https://cmake.org/cmake/help/latest/prop_sf/COMPILE_DEFINITIONS.html" rel="noreferrer" target="_blank">https://cmake.org/cmake/help/latest/prop_sf/COMPILE_DEFINITIONS.html</a><br>
> <br>
> on each source file.<br>
> <br>
> not sure why you want to do that you know that compiler already defined<br>
> many "standard" macro for you, like __FILE__<br>
> <a href="https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros" rel="noreferrer" target="_blank">https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros</a><br>
> ?<br>
> <br>
> -- <br>
> Eric<br>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Eric<br></div></div></div></div></div></div>