[CMake] Forcing /MDd using externalproject_add

Brad King brad.king at kitware.com
Wed Jan 22 12:09:37 EST 2014


On 01/22/2014 11:27 AM, Brian Davis wrote:
> http://cmake.org/gitweb?p=cmake.git;a=blob;f=Help/manual/cmake-language.7.rst;hb=1b395813#l393
> 
> This document does not state any persistence a variable should have
> when terms INTERNAL or FORCE are used.

It does link to the set() command documentation

 http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:set

which does explain INTERNAL and FORCE.  (The reason I posted a
link to the version control viewer instead of published docs is
because that cmake-languages.7 manual has not yet been in a
release so it is not published anywhere persistent yet.)

However, your problem has nothing to do with setting the cache
value, or FORCE, or INTERNAL.  See below.

On 01/17/2014 03:14 PM, Brian Davis wrote:
> finding the offending file and there the following lines are found:
>
>  # these settings never change even for C or C++
> SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")

This is the fundamental problem.  This is setting a normal variable
in the *directory scope* of the project.  The document I linked
explains how variable value lookup occurs, and that directory scope
bindings are preferred before cache entries.  Therefore this line
of code in the project *tells CMake to ignore the cache entry* so
it doesn't matter how you try to set it with ExternalProject_Add.

***This restriction is a bug in that project and not in CMake.***

> Then I think ok let's force it.  Where I think my options are:
>
> 1) patch

This would work but your arguments against it are valid.
Having "cmake -E patch" would be nice but it it non-trivial
to implement as discussed in

 http://thread.gmane.org/gmane.comp.programming.tools.cmake.user/48648

You could also write a .cmake script to edit the code using
file(READ), string(REPLACE), and file(WRITE) and run that script
as the ExternalProject patch step.

> 2) pass the following into ExternalProject_Add and hope that the
> documentation for cmake is correct (more on this later):
>  -DCMAKE_C_FLAGS_DEBUG:INTERNAL="/MDd /Z7 /Od"

The documentation is correct and this does set the cache entry, but
since *the project tells CMake to ignore the cache entry* it doesn't
matter how you set it.

> 3) use -C to cache string force the variables in as specified
> http://cmake.org/Wiki/CMake_FAQ#Make_Override_Files

Ditto #2.

> 4) Something I had not thought of. Recommendations welcome

Apply the patch manually and create a new tarball to publish at
a URL you control and give that to ExternalProject_Add.  Using
a URL you control also allows you to ensure that it persists
into the future as long as you need it.

-Brad



More information about the CMake mailing list