[CMake] ADD_CUSTOM_COMMAND and Visual Studio 2010
Michael Wild
themiwi at gmail.com
Wed Mar 31 07:27:37 EDT 2010
On 31. Mar, 2010, at 12:07 , elizabeta petreska wrote:
> Hello
>
> I am using cmake 2.8 to generate Visual Studio 2010 solution files.
>
> I have the following cmakelists.txt :
>
> set(PROJECT_NAME Test2)
> PROJECT(${PROJECT_NAME})
>
> FILE(GLOB Test_SRCS
> main.cpp
> )
>
>
> ADD_EXECUTABLE(${PROJECT_NAME}
> ${Test_SRCS}
> )
>
>
> ADD_CUSTOM_COMMAND (OUTPUT "$(ConfigurationName)/Foo.txt"
> COMMAND echo Foo > "$(ConfigurationName)/Foo.txt"
> DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/myfile.txt
> )
> ADD_CUSTOM_TARGET (Foo DEPENDS "$(ConfigurationName)/Foo.txt")
> ADD_DEPENDENCIES(${PROJECT_NAME} Foo)
>
> The problem is that Foo.txt is generated on every build on the solution
> although myfile.txt is not changed.
Use absolute paths in the OUTPUT and DEPENDS options. And you should also use the CMAKE_CFG_INTDIR variable instead of $(ConfigurationName)...
set(outfile "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/Foo.txt")
add_custom_command(OUTPUT "${outfile}"
COMMAND echo Foo > "${outfile}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/myfile.txt"
)
add_custom_target(Foo DEPENDS "${outfile}")
HTH
Michael
More information about the CMake
mailing list