I need help concerning injecting a macro into all files for the libs.
I pushed my current code into my fork branch. The last commit there shows my approach.
For every plugin it works and ELEKTRA_MODULE_NAME gets correctly replaced.
The libs modules though do not. If you run ctest -R test_opts you can see that nothing changes (ignore the test errors, they are not fixed yet).
Does anybody has experience with that? I seriously do not know what else I could do.
@petermax2 : Can you help me why this is not working yet? You achieved this for all plugins
Hm, it's just a guess but have you tried to set COMPILE_DEFINITIONS before the first invocation of target_link_libraries?
Before this block:
Otherwise you have been taking over the pattern I have used to accomplish the propagation of ELEKTRA_PLUGIN_NAME and ELEKTRA_PLUGIN_NAME_C symbols.
I tried this in https://github.com/ElektraInitiative/libelektra/pull/2589/commits/75d7f1ba0e14579f192c870827d02ebc08f719f2 without any success unfortunately :/
I'm confused too. Maybe add_plugin messes up the setup of add_lib in some way, but I'm not sure. I've tried several things on your branch but without success.
Thank you very much @petermax2 for your help!
@markus2330 : Maybe we add the macro in every lib now separately? Or do you have another idea?
The properties seem to be set properly from within CMake. If I add the following debugging code:
index 658b5b783..a24f54303 100644
--- a/cmake/Modules/LibAddLib.cmake
+++ b/cmake/Modules/LibAddLib.cmake
@@ -37,14 +37,16 @@ function (add_lib name)
PROPERTY "elektra-extension_LIBRARIES"
elektra-${name})
- set_additional_compile_definitions(${name})
-
+ set_additional_lib_compile_definitions(${name})
set_property (TARGET elektra-${name}
APPEND
PROPERTY COMPILE_DEFINITIONS
- ${ADDITIONAL_COMPILE_DEFINITIONS}
+ ${ADDITIONAL_LIB_COMPILE_DEFINITIONS}
)
+ get_property(LIB_PROPS TARGET elektra-${name} PROPERTY COMPILE_DEFINITIONS)
+ message(STATUS "===============> elektra-${name} COMPILE_DEFINITIONS=${LIB_PROPS}")
+
if (BUILD_SHARED)
target_link_libraries (elektra-${name} ${ARG_LINK_LIBRARIES})
I get the following (seemingly correct) CMake output:
-- ===============> elektra-ease COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=ease
-- ===============> elektra-globbing COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=globbing
-- ===============> elektra-proposal COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=proposal
-- ===============> elektra-meta COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=meta
-- ===============> elektra-plugin COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=plugin
-- ===============> elektra-pluginprocess COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=pluginprocess
-- ===============> elektra-utility COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=utility
-- ===============> elektra-io COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=io
-- ===============> elektra-invoke COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=invoke
-- ===============> elektra-notification COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=notification
-- ===============> elektra-highlevel COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=highlevel
-- ===============> elektra-opts COMPILE_DEFINITIONS=ELEKTRA_MODULE_NAME=opts
I don't know why ELEKTRA_MODULE_NAME is not available in opts.c.
@kodebach do you have an idea here?
I did not yet have time to look at this, but you may want to try target_compile_definitions.
Interestingly target_compile_definitions (elektra-${name} PUBLIC ELEKTRA_MODULE_NAME=test) works but doing the same with PRIVATE does not work at all. But you cannot use PUBLIC because only the last compiled lib will set it for all libs.
Possible you have to use a separate object library like plugins do. I think this is necessary anyway for non-shared builds.
Can someone assist me in these regards? Cmake & C/C++ are not really my home base, this would probably take very long otherwise.
I am afraid it would take long for everyone to understand how to do it.
Possible you have to use a separate object library like plugins do. I think this is necessary anyway for non-shared builds.
I quickly implemented this solution in https://github.com/kodebach/libelektra/commit/261d62059daf965533e37009575ad40a5e6b3557. It seems to work. At least a dirty printf("%s", ELEKTRA_MODULE_NAME) in test_opts prints opts as expected.
Thank you very much @kodebach.
Interestingly now I get the compile error
libelektra/src/bindings/io/glib/io_glib.c:11:18: fatal error: glib.h: No such file or directory
compilation terminated.
src/bindings/io/glib/CMakeFiles/elektra-io-glib-objects.dir/build.make:62: recipe for target 'src/bindings/io/glib/CMakeFiles/elektra-io-glib-objects.dir/io_glib.c.o' failed
make[2]: *** [src/bindings/io/glib/CMakeFiles/elektra-io-glib-objects.dir/io_glib.c.o] Error 1
CMakeFiles/Makefile2:20181: recipe for target 'src/bindings/io/glib/CMakeFiles/elektra-io-glib-objects.dir/all' failed
make[1]: *** [src/bindings/io/glib/CMakeFiles/elektra-io-glib-objects.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
does it relate to this change?
I mark this issue stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping the issue by writing a message here or create a new issue with the remainder of this issue.
Thank you for your contributions :sparkling_heart:
I closed this issue now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue.
Thank you for your contributions :sparkling_heart:
Most helpful comment
I am afraid it would take long for everyone to understand how to do it.