[CMake] MSBuild and automatic project file regenation
aaron.meadows at thomsonreuters.com
aaron.meadows at thomsonreuters.com
Thu Feb 9 10:58:48 EST 2012
I tried this out. The short story is that it works the way he states.
Changing the CMakeLists.txt cause CMake to rerun the ZERO_CHECK but the
executable generates a 0. Running the build again doesn't change
anything. Here is the transcript of the run:
-------------------------8<---------------------------------------------
---
c:\dev2\TestProgs\CMake_Rebuild\b3>cmake --version
cmake version 2.8.7
c:\dev2\TestProgs\CMake_Rebuild\b3>cat ..\CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(BUILD C)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "#include <stdio.h>
int main(void)
{
printf(\"%d\\n\",NUMBER);
return 0;
}
")
ADD_EXECUTABLE(main main.c)
SET_TARGET_PROPERTIES(main PROPERTIES COMPILE_DEFINITIONS NUMBER=0)
c:\dev2\TestProgs\CMake_Rebuild\b3>cmake -G "Visual Studio 9 2008" ..
-- Check for working C compiler using: Visual Studio 9 2008
-- Check for working C compiler using: Visual Studio 9 2008 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/dev2/TestProgs/CMake_Rebuild/b3
c:\dev2\TestProgs\CMake_Rebuild\b3>cat ..\CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(BUILD C)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "#include <stdio.h>
int main(void)
{
printf(\"%d\\n\",NUMBER);
return 0;
}
")
ADD_EXECUTABLE(main main.c)
SET_TARGET_PROPERTIES(main PROPERTIES COMPILE_DEFINITIONS NUMBER=1)
c:\dev2\TestProgs\CMake_Rebuild\b3>cmake --build .
Microsoft (R) Visual Studio Version 9.0.30729.1.
Copyright (C) Microsoft Corp. All rights reserved.
1>------ Build started: Project: ZERO_CHECK, Configuration: Debug Win32
------
1>Checking Build System
1>CMake is re-running because
C:/dev2/TestProgs/CMake_Rebuild/b3/CMakeFiles/generate.stamp is
out-of-date.
1> the file 'C:/dev2/TestProgs/CMake_Rebuild/CMakeLists.txt'
1> is newer than
'C:/dev2/TestProgs/CMake_Rebuild/b3/CMakeFiles/generate.stamp.depend'
1> result='-1'
1>-- Configuring done
1>-- Generating done
1>-- Build files have been written to:
C:/dev2/TestProgs/CMake_Rebuild/b3
1>Build log was saved at
"file://c:\dev2\TestProgs\CMake_Rebuild\b3\ZERO_CHECK.dir\Debug\BuildLog
.htm"
1>ZERO_CHECK - 0 error(s), 0 warning(s)
2>------ Build started: Project: main, Configuration: Debug Win32 ------
2>Compiling...
2>main.c
2>Compiling manifest to resources...
2>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
2>Copyright (C) Microsoft Corporation. All rights reserved.
2>Linking...
2>Embedding manifest...
2>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
2>Copyright (C) Microsoft Corporation. All rights reserved.
2>Build log was saved at
"file://c:\dev2\TestProgs\CMake_Rebuild\b3\main.dir\Debug\BuildLog.htm"
2>main - 0 error(s), 0 warning(s)
========== Build: 2 succeeded, 0 failed, 1 up-to-date, 0 skipped
==========
c:\dev2\TestProgs\CMake_Rebuild\b3>Debug\main.exe
0
c:\dev2\TestProgs\CMake_Rebuild\b3>cmake --build .
Microsoft (R) Visual Studio Version 9.0.30729.1.
Copyright (C) Microsoft Corp. All rights reserved.
========== Build: 0 succeeded, 0 failed, 3 up-to-date, 0 skipped
==========
c:\dev2\TestProgs\CMake_Rebuild\b3>Debug\main.exe
0
-------------------------8<---------------------------------------------
---
I tried this first with a 2.8.4 version I had installed on that box
(older dev box here at work that still had vs2008 on it had 2.8.4
installed). Here is its transcript:
-------------------------8<---------------------------------------------
---
c:\dev2\TestProgs\CMake_Rebuild\b>cmake --version
cmake version 2.8.4
c:\dev2\TestProgs\CMake_Rebuild\b>cat ..\CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(BUILD C)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "#include <stdio.h>
int main(void)
{
printf(\"%d\\n\",NUMBER);
return 0;
}
")
ADD_EXECUTABLE(main main.c)
SET_TARGET_PROPERTIES(main PROPERTIES COMPILE_DEFINITIONS NUMBER=0)
c:\dev2\TestProgs\CMake_Rebuild\b>cmake ..
-- Building for: NMake Makefiles
-- The C compiler identification is MSVC
-- Check for CL compiler version
-- Check for CL compiler version - 1500
-- Check if this is a free VC compiler
-- Check if this is a free VC compiler - no
-- Check for working C compiler: c:/Program Files (x86)/Microsoft Visual
Studio 9.0/VC/bin/cl.exe
-- Check for working C compiler: c:/Program Files (x86)/Microsoft Visual
Studio 9.0/VC/bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/dev2/TestProgs/CMake_Rebuild/b
c:\dev2\TestProgs\CMake_Rebuild\b>cat ..\CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(BUILD C)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "#include <stdio.h>
int main(void)
{
printf(\"%d\\n\",NUMBER);
return 0;
}
")
ADD_EXECUTABLE(main main.c)
SET_TARGET_PROPERTIES(main PROPERTIES COMPILE_DEFINITIONS NUMBER=1)
c:\dev2\TestProgs\CMake_Rebuild\b>cmake --build .
-- Configuring done
-- Generating done
-- Build files have been written to: C:/dev2/TestProgs/CMake_Rebuild/b
Scanning dependencies of target main
[100%] Building C object CMakeFiles/main.dir/main.c.obj
main.c
Linking C executable main.exe
[100%] Built target main
c:\dev2\TestProgs\CMake_Rebuild\b>main.exe
1
-------------------------8<---------------------------------------------
---
One interesting difference I noticed was that when I went to try this
with 2.8.7 from a vs 2008 command prompt, it configured with vs 2010. I
had to specify -G"Visual Studio 9 2008" to get the 2008 configuration.
Let me know if you want me to try anything else.
Aaron Meadows
-----Original Message-----
From: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] On Behalf
Of Michael Hertling
Sent: Thursday, February 09, 2012 8:52 AM
To: cmake at cmake.org
Subject: Re: [CMake] MSBuild and automatic project file regenation
On 01/13/2012 08:02 PM, Michael Hertling wrote:
> On 01/13/2012 03:42 PM, Bill Hoffman wrote:
>> On 1/13/2012 9:10 AM, Michael Hertling wrote:
>>
>>> With CMake 2.8.7 and VS 2008, I can report the following findings:
>>>
>>> (1) Starting out from within an empty build directory: "cmake .."
>>> followed by "cmake --build ." configures/builds as expected.
>>> (2) Tweaking CMakeLists.txt file only and leaving sources alone.
>>> (3) "cmake --build ." rebuilds the ZERO_CHECK target and, thus,
>>> updates the project file to reflect the changes from (2).
>>> However, the corresponding target is not rebuilt and,
>>> thus, does not reflect the changes from (2).
>>> (4) A further "cmake --build ." does *nothing* - definitely.
>>> (5) To get the concerned target rebuilt, I need to apply
>>> David's hint, i.e. "cmake .&& cmake --build .", or
>>> clean first, i.e. "cmake --build . --clean-first".
>>
>> Can you provide an example and how to reproduce this?
>>
>> I find it hard to believe that
>>
>> cmake --build .
>> cmake --build .
>>
>> will not build everything.
>>
>> I get that the ZERO_TARGET does not get things to reload, but I don't
>> see how the second build would not get things up to date. It has
>> nothing to do with the project files depending on the targets. I
>> assume something really changed and there really needs to be a
>> rebuild? What type of thing are you changing in the CMakeLists.txt?
>>
>> -Bill
>
> Look at the following exemplary project:
>
> CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) PROJECT(BUILD C)
> FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "#include <stdio.h> int
> main(void) {
> printf(\"%d\\n\",NUMBER); return 0; }
> ")
> ADD_EXECUTABLE(main main.c)
> SET_TARGET_PROPERTIES(main PROPERTIES
> COMPILE_DEFINITIONS NUMBER=0)
>
> Steps to reproduce with CMake 2.8.7 and VS 2008:
>
> (1) From within an empty build directory: "cmake <srcdir>" followed
> by "cmake --build ." configures/builds correctly; "Debug\main"
> yields "0" as expected.
> (2) At the end of CMakeLists.txt, change "NUMBER=0" to "NUMBER=1".
> (3) "cmake --build ." triggers the ZERO_CHECK target, regenerates
> main.vcproj but doesn't use the latter for rebuilding "main".
> Accordingly, "Debug\main" still yields "0".
> Assuming that MSBuild/devenv/<whatever> doesn't load the re-
> generated project file into the currently running instance,
> I can well understand this behavior, but:
> (4) A further "cmake --build ." does nothing; in particular, it
> does not rebuild "main", and "Debug\main" still yields "0".
> Here, I'd expect that the regenerated project file is
> loaded and the associated target rebuilt.
>
> (5) Rebuilding the "main" target can be achieved via David's hint
> "cmake . && cmake --build ." or by cleaning before, e.g. via
> "cmake --build . --clean-first". Afterwards, "Debug\main"
> finally yields "1".
>
> For additional information, if one modifies the main.vcproj file by
> hand, a subsequent "cmake --build ." also does nothing, as well as
> "msbuild BUILD.sln /t:main" or "msbuild main.vcproj".
>
> Regards,
>
> Michael
Any findings w.r.t. this issue? Can anyone reproduce it? Is it actually
faulty behavior, possibly worth a bug report? If so, can it be fixed in
some way? David Cole mentioned something like that. Although this isn't
really disastrous, it would be quite nice if everything is up-to-date
after a "cmake --build ." command, as one is used to with Makefiles.
Regards,
Michael
--
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
This email was sent to you by Thomson Reuters, the global news and information company. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters.
More information about the CMake
mailing list