I found this letter that describes three possible ways to make the executable depend on the linker script. The author prefers like this:
CMakeLists.txt :
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) PROJECT(LINKERSCRIPT C) FILE(WRITE main.c "void main(){}") # dummy.c must exist: ADD_EXECUTABLE(EXE main.c dummy.c) # linkerscript must exist: SET_SOURCE_FILES_PROPERTIES( dummy.c PROPERTIES OBJECT_DEPENDS ${CMAKE_SOURCE_DIR}/linkerscript )
Here dummy.c is an empty file that is specified for the add_executable() command only for the make add_executable() executable, which depends on the linker script through the OBJECT_DEPENDS property.
source share