[CMake] MSBuild and automatic project file regenation

Michael Hertling mhertling at online.de
Fri Jan 13 14:02:38 EST 2012


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


More information about the CMake mailing list