While not directly answering your question, it seems you may be trying to deal with symbol visibility. Are you aware of CMake's symbol visibility features? A good place to start would be the GenerateExportHeader module, the documentation for which <https://cmake.org/cmake/help/latest/module/GenerateExportHeader.html> does a reasonable job of showing how to use the visibility features CMake provides.
Dealing with your question more directly, you may want to look at the TARGET form of add_custom_command() and in particular, the PRE_LINK keyword. See the Build Events section near the bottom of the page for the add_custom_command() docs <https://cmake.org/cmake/help/latest/command/add_custom_command.html#build-events> . On Sun, Jan 15, 2017 at 10:46 AM, Paul Smith <[email protected]> wrote: > I'm really stuck: maybe someone can provide a hint. > > I'm trying to create a shared library from a bunch of object files, and > use a linker script to mark almost all the symbols as local. The tricky > thing is I'm auto-generating the linker script via a shell script that > examines the object files for my library (using readelf) to find global > symbols. > > I basically need a process like this: > > 1. Start with source files and a linker map generator shell script > 2. Compile all the code into object files > 3. If any file was recompiled (or the generator script) is modified, re- > run the generator script to recreate the linker script > 4. If any file was recompiled or the linker script was recreated, > rebuild the shared library, using the linker script. > > In "make-ese" it would be trivial: something like: > > libmy.so: $(OBJECTS) link.script ; <link .so> ... > > link.script: $(OBJECTS) genlinkscript ; <generate script> ... > > I simply can't figure out how to create something like this in CMake. > > I have a custom command to create the linker script: > > add_custom_command(OUTPUT out.script > COMMAND genlinkscript ${CMAKE_CURRENT_BINARY_DIR} > DEPENDS <<SOMETHING GOES HERE>> > VERBATIM) > > And I have an add_library command to create the shared library: > > add_library(mylib SHARED foo.cpp foo.h out.script) > > set_property(TARGET mylib APPEND_STRING PROPERTY > LINK_FLAGS " -Wl,--version-script=out.script") > > But what can my custom_command depend on, so that it's run AFTER all the > object files are created, but BEFORE the shared library is created? > > I tried to do this using an OBJECT library, but see my previous post > that adding OBJECT libraries as dependencies of custom commands doesn't > work. > > What can I do? I'm happy with a solution that works only on Linux (I > can use if()/endif() to turn it off on my other platforms, which don't > use these linker scripts anyway). > -- > > 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: > http://public.kitware.com/mailman/listinfo/cmake -- Craig Scott Melbourne, Australia https://crascit.com
-- 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: http://public.kitware.com/mailman/listinfo/cmake
