[CMake] Elegant solution for preprocessing a linker script?

Michael Weise michael.weise at ek-team.de
Mon Nov 11 03:22:15 EST 2013


Hi Robert,

thanks very much, with an additional add_custom_target() it's working!

Best Regards
Michael


PS: This is the complete CMakeLists.txt (for future reference):
----
project (cmake_test_custom_command)
cmake_minimum_required (VERSION 2.8)
set(CMAKE_MAKE_PROGRAM c:/devel/msys-gcc-m68k-elf/bin/make)

include_directories(inc)
set(CMAKE_EXE_LINKER_FLAGS "-T api.lds")

add_executable(cmake_test hello.c)

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
                   -I ${CMAKE_CURRENT_SOURCE_DIR}/inc
                   VERBATIM)

add_custom_target(linkerscript
                  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/api.lds
                  VERBATIM)

add_dependencies(cmake_test linkerscript)
----



On Fri, 8 Nov 2013 10:56:19 -0500
Robert Maynard <robert.maynard at kitware.com> wrote:

> add_dependencies works only on targets not files. You will need to use
> add_custom_target whose DEPENDS is set to
> ${CMAKE_CURRENT_BINARY_DIR}/api.lds. You can than specify that
> cmake_test depends on the custom target.
> 
> On Fri, Nov 8, 2013 at 5:15 AM, Michael Weise <michael.weise at ek-team.de> wrote:
> > On Thu, 7 Nov 2013 19:56:29 +0000
> > "Williams, Norman K" <norman-k-williams at uiowa.edu> wrote:
> >
> >> Why doesn't this work?
> >> add_custom_command(
> >> ...
> >
> > Good point, that's the core of my question.
> >
> > I did implement the "add_custom_command" as you suggested, including
> > "dependencies". Unfortunatly, the custom command is not executed.
> >


More information about the CMake mailing list