[CMake] Elegant solution for preprocessing a linker script?

Williams, Norman K norman-k-williams at uiowa.edu
Thu Nov 7 14:56:29 EST 2013


Why doesn't this work?

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/api.lds
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/api.lds.S
COMMAND ${CMAKE_C_COMPILER} -E ${CMAKE_CURRENT_SOURCE_DIR}/api.lds.S
        -P -o ${CMAKE_CURRENT_BINARY_DIR}/api.lds.S)

The actual target that needs the linker script needs to depend on api.lds,
or the custom command will never be run, because it lives outside the
dependency chain of the build system.

In other words, if nothing depends on api.lds, it will never get built.

add_dependencies(target_that_actually_depends_on_api_lds
        ${CMAKE_CURRENT_BINARY_DIR}/api.lds)



On 11/6/13 9:01 AM, "Michael Weise" <michael.weise at ek-team.de> wrote:

>Hello,
>
>I'm looking for a way to preprocess a linker script.
>
>After (unsuccessfully) trying add_custom_command() I found this
>explanation and a workaround:
>http://www.mail-archive.com/cmake@cmake.org/msg16496.html
>
>
>It uses an intermediate dependency "dummy.c" in the source list of
>the executable, which forces the custom command to be executed:
>
>----
>add_executable(cmake_test ${CMAKE_CURRENT_BINARY_DIR}/dummy.c)
>
>add_custom_command(
>  OUTPUT  ${CMAKE_CURRENT_BINARY_DIR}/dummy.c
>  COMMAND ${CMAKE_C_COMPILER} -E ${CMAKE_CURRENT_SOURCE_DIR}/api.lds.S
>                              -P -o ${CMAKE_CURRENT_BINARY_DIR}/api.lds
>  COMMAND echo "/* this file is (almost) empty */"
>               > ${CMAKE_CURRENT_BINARY_DIR}/dummy.c
>  MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/api.lds.S )
>
>set(CMAKE_EXE_LINKER_FLAGS "-T api.lds")
>----
>
>While this is actually working, I find the approach somehow "dirty".
>Is there a more elegant solution without the dummy.c file?
>
>Best Regards
>Michael
>
>--
>
>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://www.cmake.org/mailman/listinfo/cmake



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
________________________________


More information about the CMake mailing list