MantisBT - CMake
View Issue Details
0011351CMakeCMakepublic2010-10-22 01:582011-04-04 12:00
Andreas Roth 
Bill Hoffman 
normalmajoralways
closedno change required 
CMake-2-8 
CMake 2.8.4 
0011351: trycompile does not work on MSVC_IDE with --debug-trycompile
I've written a small CMakeLists.txt (attached), which demonstrates the problem that the result of the second try_compile attempt (e.g. by CHECK_FUNCTION_EXISTS) has the same result as before and this causes try_compile to produce wrong results.
Since the CMake temporary project files are not deleted before the next try_compile command, the MSVC assume that the output file is still up-to-date. This could be workarounded if a additional dependency for the output file to the generated project file is introduced (don't know if this is possible.
try to run the attached CMakeLists.txt with the following command line:
cmake --debug-trycompile -G "Visual Studio 9 2008" .

Using CMake version 2.8.2
No tags attached.
txt CMakeLists.txt (353) 2010-10-22 01:58
https://public.kitware.com/Bug/file/3465/CMakeLists.txt
Issue History
2010-10-22 01:58Andreas RothNew Issue
2010-10-22 01:58Andreas RothFile Added: CMakeLists.txt
2010-10-22 02:05Andreas RothNote Added: 0022657
2010-10-22 11:05Bill HoffmanNote Added: 0022661
2010-12-15 12:06David ColeAssigned To => Bill Hoffman
2010-12-15 12:06David ColeStatusnew => assigned
2010-12-15 12:07David ColeNote Added: 0024171
2010-12-15 12:07David ColeStatusassigned => resolved
2010-12-15 12:07David ColeFixed in Version => CMake 2.8.4
2010-12-15 12:07David ColeResolutionopen => no change required
2011-04-04 12:00David ColeNote Added: 0026065
2011-04-04 12:00David ColeStatusresolved => closed

Notes
(0022657)
Andreas Roth   
2010-10-22 02:05   
The attached CMakeLists.txt produced the following results:
-- 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
-- Check for working CXX compiler using: Visual Studio 9 2008
-- Check for working CXX compiler using: Visual Studio 9 2008 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for printf
-- Looking for printf - found
-- Looking for non_existing_printf
-- Looking for non_existing_printf - found
-- Looking for fprintf
-- Looking for fprintf - found
CMake Error at CMakeLists.txt:10 (MESSAGE):
  Found non_existing_printf

And this is the Output in CMakeOutput.log:
1>------ Build started: Project: cmTryCompileExec, Configuration: Debug Win32 ------

1>Compiling...

1>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86

1>Copyright (C) Microsoft Corporation. All rights reserved.

1>cl /Od /D "WIN32" /D "_WINDOWS" /D "CHECK_FUNCTION_EXISTS=printf" /D "_DEBUG" /D "CMAKE_INTDIR=\"Debug\"" /D "_MBCS" /FD /RTC1 /MDd /Fo"cmTryCompileExec.dir\Debug\\" /Fd"C:\work\trac\test\check_function_exists\build-vs\CMakeFiles\CMakeTmp\Debug/cmTryCompileExec.pdb" /W3 /c /Zi /TC /Zm1000

1> "..\..\..\..\..\..\..\cmake\share\cmake-2.8\Modules\CheckFunctionExists.c"

1>CheckFunctionExists.c

1>Linking...

1>Embedding manifest...

1>Build log was saved at "file://c:\work\trac\test\check_function_exists\build-vs\CMakeFiles\CMakeTmp\cmTryCompileExec.dir\Debug\BuildLog.htm" [^]

1>cmTryCompileExec - 0 error(s), 0 warning(s)

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========



Determining if the function non_existing_printf exists passed with the following output:
Change Dir: C:/work/trac/test/check_function_exists/build-vs/CMakeFiles/CMakeTmp

Run Build Command:C:\PROGRA~2\MICROS~1.0\Common7\IDE\devenv.com CMAKE_TRY_COMPILE.sln /build Debug /project cmTryCompileExec


Microsoft (R) Visual Studio Version 9.0.30729.1.

Copyright (C) Microsoft Corp. All rights reserved.

========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========



Determining if the function fprintf exists passed with the following output:
Change Dir: C:/work/trac/test/check_function_exists/build-vs/CMakeFiles/CMakeTmp

Run Build Command:C:\PROGRA~2\MICROS~1.0\Common7\IDE\devenv.com CMAKE_TRY_COMPILE.sln /build Debug /project cmTryCompileExec


Microsoft (R) Visual Studio Version 9.0.30729.1.

Copyright (C) Microsoft Corp. All rights reserved.

========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

As you can see the result of the second and third CHECK_FUNCTION_EXISTS command is bogus, since MSVC thinks the output file is up-to-date.
(0022661)
Bill Hoffman   
2010-10-22 11:05   
--debug-trycompile is only useful as a debugging tool, and is know to break things. There is a reason we wipe the directory by default. The usually usage is to setup the project so it will just run one try-compile when you do --debug-trycompile. I usually run cmake once on the whole project. Then delete the cache entry for the try-compile I am debugging, then run cmake again with --debug-trycompile.

I don't think it is worth the time to make --debug-trycompile work all the time.
(0024171)
David Cole   
2010-12-15 12:07   
This is working as intended.

As Bill says in the note, --debug-trycompile is only useful as a debugging tool, and should be used only to debug one try_compile at a time...
(0026065)
David Cole   
2011-04-04 12:00   
Closing resolved issues that have not been updated in more than 3 months.