[CMake] ADD_CUSTOM_COMMAND and Visual Studio 2010

Michael Wild themiwi at gmail.com
Wed Mar 31 08:52:17 EDT 2010


Well, it seems then that this is a bug in CMake and I haven't seen anything in the recent commit logs indicating that this has been fixed.

If you have the time, I think the CMake-developers would be glad if you created a bug-report (http://public.kitware.com/Bug) detailing the problem and your analysis of it together with a small test case showing the problem as an attachment.

Michael

On 31. Mar, 2010, at 14:47 , elizabeta petreska wrote:

> I am using cmake 2.8.1.
> But you are right, Visual studio 2010 is not relased yet. So I guess I can
> not except everything to works well. I will wait  till Visual Studio 2010 is
> released and maybe some more time after that :)
> 
> On Wed, Mar 31, 2010 at 2:40 PM, Michael Wild <themiwi at gmail.com> wrote:
> 
>> Well, VS-2010 isn't even released so far... Which exact version of CMake
>> are you using by the way? 2.8 or 2.8.1? If I remember correctly, there were
>> some improvements in 2.8.1 w.r.t. VS-2010.
>> 
>> Michael
>> 
>> 
>> On 31. Mar, 2010, at 14:28 , elizabeta petreska wrote:
>> 
>>> If I use Visual Studio 2005 generator everything works well.
>>> 
>>> But, it seems that Visual Studio 2005 does not require the input file (
>> in
>>> this case foo.txt.rule ) to Custom Build Step to exist on disk. So the
>>> Visual Studio 2005 generator never makes foo.txt.rule to the disk, but
>> the
>>> whole thing still works.
>>> 
>>> While in Visual Studio 2010 it seems that the input file to custom build
>>> step must exist on disk.
>>> 
>>> I tested this with defining Custom Build Steps directly through The
>> Visual
>>> Studio 2005 and Visual studio 2010 IDE.
>>> 
>>> So , someone can say is this a bug in the Visual Studio 2010 generator?
>>> 
>>> thank you
>>> 
>>> 
>>> On Wed, Mar 31, 2010 at 2:09 PM, Michael Wild <themiwi at gmail.com> wrote:
>>> 
>>>> CC-ing back to the mailing list...
>>>> 
>>>> Sorry, I don't know why this fails and I don't have VS-2010 around. What
>>>> happens if you use a different generator?
>>>> 
>>>> Michael
>>>> 
>>>> On 31. Mar, 2010, at 14:05 , elizabeta petreska wrote:
>>>> 
>>>>> Hello
>>>>> 
>>>>> Thank you for the reply.
>>>>> I test your suggestion.
>>>>> It still generates foo.txt every time I build the solution.
>>>>> 
>>>>> I think that this behavior is because foo.txt.rule file is not
>> generated
>>>> i.e
>>>>> doesnot exist on disk. Here is the relevant part in the generated
>>>> .vcxproj
>>>>> project file :
>>>>> 
>>>>> 
>>>>> <CustomBuild Include="$(Configuration)\Foo.txt.rule"> // Foo.txt.rule
>>>>> doesnot exist
>>>>> 
>>>>>    <Message
>>>>> Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Generating
>>>>> $(Configuration)/Foo.txt</Message>
>>>>> 
>>>>>   <Command
>>>> Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">echo
>>>>> Foo &gt;
>> C:/project2/build_cmake_vs10/$(Configuration)/Foo.txt</Command>
>>>>> 
>>>>>    <AdditionalInputs
>>>>> 
>>>> 
>> Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">C:project2/build_cmake_vs10/$(Configuration)/Foo.txt.rule;C:project2\myfile.txt;%(AdditionalInputs)</AdditionalInputs>
>>>>> 
>>>>>    <Outputs
>>>>> 
>>>> 
>> Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">C:\project2\build_cmake_vs10\$(Configuration)\Foo.txt;%(Outputs)</Outputs>
>>>>> 
>>>>> 
>>>>> If I change the add_custom_command to the following then foo.txt.rule
>> is
>>>>> made by cmake, and  it works :
>>>>> 
>>>>> set(outfile "Foo.txt")
>>>>> add_custom_command(OUTPUT "${outfile}"
>>>>> COMMAND echo Foo > "${outfile}"
>>>>> DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/myfile.txt"
>>>>> )
>>>>> add_custom_target(Foo DEPENDS "${outfile}")
>>>>> 
>>>>> In this case it works because foo.txt.rule is made by cmake on disk in
>>>> the
>>>>> folder ${CMAKE_CURRENT_BINARY_DIR} i.e C:\project2\build_cmake_vs10
>>>>> 
>>>>> Someone can say what is the difference if I use CMAKE_CFG_INTDIR  in
>> the
>>>>> outputs of add_custom_command.
>>>>> 
>>>>> Thanks
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> On Wed, Mar 31, 2010 at 1:27 PM, Michael Wild <themiwi at gmail.com>
>> wrote:
>>>>> 
>>>>>> 
>>>>>> 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