[CMake] Elegant solution for preprocessing a linker script?
Michael Weise
michael.weise at ek-team.de
Wed Nov 6 10:01:03 EST 2013
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
More information about the CMake
mailing list