[CMake] Elegant solution for preprocessing a linker script?
Michael Weise
michael.weise at ek-team.de
Fri Nov 8 05:15:00 EST 2013
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.
What happens is:
----
$ rm -rf build-cmake/
$ mkdir build-cmake
$ cd build-cmake/
$ cmake -G "MSYS Makefiles" \
> -DCMAKE_TOOLCHAIN_FILE=../src/toolchain-m68k-elf.cmake \
> ../src
-- Configuring done
-- Generating done
-- Build files have been written to:
C:/devel/projekte/cmake_test_custom_command/build-cmake
$ make
Scanning dependencies of target cmake_test
[100%] Building C object CMakeFiles/cmake_test.dir/hello.c.obj
Linking C executable cmake_test
c:/devel/msys-gcc-m68k-elf/local/coldfire/bin/../lib/gcc/m68k-elf/4.7.3/../../../../m68k-elf/bin/ld.exe:
cannot open linker script file api.lds: No such file or directory
...
----
As you can see, the custom command is not executed.
File "CMakeLists.txt":
----
project (cmake_test_custom_command)
cmake_minimum_required (VERSION 2.8)
set(CMAKE_MAKE_PROGRAM c:/devel/msys-gcc-m68k-elf/bin/make)
add_executable(cmake_test hello.c)
include_directories(inc)
set(CMAKE_EXE_LINKER_FLAGS "-T api.lds")
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_dependencies(cmake_test ${CMAKE_CURRENT_BINARY_DIR}/api.lds)
----
> The actual target that needs the linker script needs to depend on api.lds ...
That's clear (I'm familiar with build systems in general).
Did I add the dependency (on cmake_test) correctly in my CMakeLists.txt?
If yes, why is the dependency "not working"?
Best Regards
Michael
File "toolchain-m68k-elf.cmake":
----
include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME Generic)
CMAKE_FORCE_C_COMPILER(m68k-elf-gcc GNU)
CMAKE_FORCE_CXX_COMPILER(m68k-elf-g++ GNU)
set(CMAKE_SYSTEM_PROCESSOR 5372)
----
More information about the CMake
mailing list