[CMake] (no subject)
Michael Hertling
mhertling at online.de
Sun Jun 12 23:14:01 EDT 2011
On 06/06/2011 10:32 PM, dfurtney at cox.net wrote:
> Does CMake provide a way to get the list of objects going into a given target? I need such a list for a PRE_LINK custom command.
With the Makefile generators, you might use the RULE_LAUNCH_COMPILE
target property combined with a shell script to achieve your goal:
# CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(OBJECTS C)
SET(CMAKE_VERBOSE_MAKEFILE ON)
FILE(WRITE ${CMAKE_BINARY_DIR}/f.c "void f(void){}\n")
FILE(WRITE ${CMAKE_BINARY_DIR}/g.c "void g(void){}\n")
FILE(WRITE ${CMAKE_BINARY_DIR}/h.c "void h(void){}\n")
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "int main(void){return 0;}\n")
ADD_EXECUTABLE(main main.c f.c g.c h.c)
SET_TARGET_PROPERTIES(main PROPERTIES
RULE_LAUNCH_COMPILE "sh ${CMAKE_SOURCE_DIR}/objects.sh <OBJECT> --")
ADD_CUSTOM_COMMAND(TARGET main PRE_LINK
COMMAND @cat objects.txt COMMENT "Object files of target main:")
# objects.sh:
touch objects.txt
while [ "$1" != "--" ]; do
if ! grep -q "$1" objects.txt; then
echo $1 >> objects.txt
fi
shift
done
shift
exec "$@"
The objects.sh script collects all object files of the main target in
addition to compiling the respective source file, and the PRE_LINK
custom command may retrieve them from the objects.txt file later.
'hope that helps.
Regards,
Michael
PS: Please use a descriptive subject in your postings.
More information about the CMake
mailing list