2011-03-11 2 views
7

출력 파일 을 생성 된 메이크 파일의 대상으로 사용하여 add_custom_command과 같은 작업을 수행하고 싶습니다. 의 우아한 방법이 있나요?파일 이름을 대상으로하는 사용자 지정 명령을 추가하십시오.

내가 본 모든 예제 (예 : the cmake faq re: latex)는 add_custom_command을 사용하여 원하는 출력 파일을 생성하는 방법을 알려주고 add_custom_target을 사용하여 대상을 만듭니다. 예컨대는 :

add_executable (hello hello.c) 
add_custom_command(OUTPUT hello.bin 
        COMMAND objcopy --output-format=binary hello hello.bin 
        DEPENDS hello 
        COMMENT "objcopying hello to hello.bin") 
add_custom_target(bin ALL DEPENDS hello.bin) 

그러나 생성 된 메이크 파일의 대상 이름은 bin 오히려 hello.bin 이상이다. hello.bin 자체를 생성 된 makefile의 대상으로 만들 수있는 방법이 있습니까?

작동하지 않습니다 내가 해봤 일부 솔루션 : 메이크에서 순환 종속성에 add_custom_target(hello.bin ALL DEPENDS hello.bin) 결과 :

  • 로 변경.

답변

3

대상의 부작용으로 hello.bin을 생성하면됩니다. objcopy에서 hello.bin을 생성하는 대신 hello.tmp를 생성합니다. 그런 다음 부작용으로 hello.tmp를 hello.bin에 복사합니다. 마지막으로 hello.tmp에 종속 된 가짜 대상 hello.bin을 만듭니다. 코드에서 :

add_executable (hello hello.c) 
add_custom_command(OUTPUT hello.tmp 
        COMMAND objcopy --output-format=binary hello hello.tmp 
        COMMAND ${CMAKE_COMMAND} -E copy hello.tmp hello.bin 
        DEPENDS hello 
        COMMENT "objcopying hello to hello.bin") 
add_custom_target(hello.bin ALL DEPENDS hello.tmp) 

깨끗함을 실행할 때 hello.bin이 지워지지 않는 문제가 있습니다. 이를 작동 시키려면 다음을 추가하십시오 :

set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES hello.bin) 
관련 문제