View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014705CMakeCMakepublic2014-01-17 15:022014-06-02 08:38
ReporterBrian J. Davis 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
PlatformVisualStudio 2012 x64OSWindows7 OS VersionWindows7
Product VersionCMake 2.8.12.1 
Target VersionFixed in Version 
Summary0014705: ExternalProject_Add seems to ingores meaning of INTERNAL when passed in as var in -D <var>:<type>=<value>
DescriptionExternalProject_Add seems to ingores meaning of INTERNAL when passed in as var in -D <var>:<type>=<value>

see:
http://www.cmake.org/cmake/help/v2.8.12/cmake.html#opt:-Dvar:typevalue [^]

where type is documented in set as one of:

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

<type> may be one of

  FILEPATH = File chooser dialog.
  PATH = Directory chooser dialog.
  STRING = Arbitrary string.
  BOOL = Boolean ON/OFF checkbox.
  INTERNAL = No GUI entry (used for persistent variables).

and

If <type> is INTERNAL, the cache variable is marked as internal, and will not be shown to the user in tools like cmake-gui. This is intended for values that should be persisted in the cache, but which users should not normally change. INTERNAL implies FORCE.

I was expecting variable spassed with -DVAR:INTERNAL="value" to be forced in sub project added by using externalproject_add, but it does not seem to.

Should it?

Is this expected behavior?

Is it a bug?

Steps To ReproduceSee attached zip file or:

Create a file with contents in a directory referred to here as TOP

# START
# ${TOP}/CMakeList.txt =======================================================

# check required version of CMake
CMAKE_MINIMUM_REQUIRED(VERSION 2.0)
#IF(CMAKE_BACKWARDS_COMPATIBILITY GREATER 2.0.6)
# SET(CMAKE_BACKWARDS_COMPATIBILITY 2.0.6 CACHE STRING "Latest version of CMake when this project was released." FORCE)
#ENDIF(CMAKE_BACKWARDS_COMPATIBILITY GREATER 2.0.6)

if(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

include( ExternalProject )

SET( TOP ${CMAKE_CURRENT_LIST_DIR} )
set( SOURCE_DIR ${TOP}/some_external_project )


      set( EXTERNAL_PROJECT_GLOBAL_COMPILER_FLAGS
        -DCMAKE_CXX_FLAGS_INIT:INTERNAL="${CMAKE_CXX_FLAGS_INIT}"
        -DCMAKE_CXX_FLAGS_DEBUG:INTERNAL="${CMAKE_CXX_FLAGS_DEBUG}"
        -DCMAKE_CXX_FLAGS_DEBUG_INIT:INTERNAL="${CMAKE_CXX_FLAGS_DEBUG_INIT}"
        -DCMAKE_C_FLAGS_DEBUG:INTERNAL="${CMAKE_C_FLAGS_DEBUG}"
        -DCMAKE_C_FLAGS_DEBUG_INIT:INTERNAL="${CMAKE_C_FLAGS_DEBUG_INIT}"
        CACHE STRING "" FORCE
        )


set( CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_LIST_DIR}/install CACHE STRING "" FORCE )
set( INSTALL_PREFIX CACHE STRING "" FORCE )

message( "EXTERNAL_PROJECT_GLOBAL_COMPILER_FLAGS ${EXTERNAL_PROJECT_GLOBAL_COMPILER_FLAGS}" )

add_custom_target(
    bob
    ALL
    echo "HELLO WORLD ====================================================================================================="
    )


      ExternalProject_Add(
          some_proj
# [DEPENDS projects...]
# PREFIX ${SOURCE_DIR}
# [LIST_SEPARATOR sep]
# [TMP_DIR dir]
# [STAMP_DIR dir]
       #--Download step--------------
       DOWNLOAD_COMMAND ""
# GIT_REPOSITORY ${URI}
# GIT_TAG ${GIT_TAG}
       #--Update/Patch step----------
# UPDATE_COMMAND ""
# PATCH_COMMAND ""
       #--Configure step-------------
        SOURCE_DIR ${SOURCE_DIR}
# CONFIGURE_COMMAND ""
# [CMAKE_COMMAND /.../cmake]
# CMAKE_GENERATOR ${CMAKE_GENERATOR}
# CMAKE_GENERATOR_TOOLSET ${CMAKE_GENERATOR_TOOLSET}
        CMAKE_ARGS
            -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}
               -DINSTALL_PREFIX=${INSTALL_PREFIX}
        ${EXTERNAL_PROJECT_GLOBAL_COMPILER_FLAGS}
# [CMAKE_CACHE_ARGS args...]
       #--Build step-----------------
# BINARY_DIR ${BUILD_DIR}
# BUILD_COMMAND ""
# [BUILD_IN_SOURCE 1]
       #--Install step---------------
# INSTALL_DIR ${INSTALL_PREFIX}
    INSTALL_COMMAND ""
       #--Test step------------------
# [TEST_BEFORE_INSTALL 1]
# [TEST_AFTER_INSTALL 1]
# [TEST_COMMAND cmd...]
       #--Output logging-------------
# [LOG_DOWNLOAD 1]
# [LOG_UPDATE 1]
# [LOG_CONFIGURE 1]
# [LOG_BUILD 1]
# [LOG_TEST 1]
# [LOG_INSTALL 1]
       #--Custom targets-------------
# [STEP_TARGETS st1 st2 ...]
# STEP_TARGETS bob bob bob bob bob
        )
        
        
# ${TOP}/CMakeList.txt =======================================================
# END


Also create the Following CMakeLists.txt file in ${TOP}/some_external_project
direcotry

# START
# ${TOP}/some_external_project/CMakeList.txt ===================
# check required version of CMake
CMAKE_MINIMUM_REQUIRED(VERSION 2.0)
#IF(CMAKE_BACKWARDS_COMPATIBILITY GREATER 2.0.6)
# SET(CMAKE_BACKWARDS_COMPATIBILITY 2.0.6 CACHE STRING "Latest version of CMake when this project was released." FORCE)
#ENDIF(CMAKE_BACKWARDS_COMPATIBILITY GREATER 2.0.6)

if(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)



    # these settings never change even for C or C++
    SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
    SET(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /MT /O2")
    SET(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /MT /O2")
    SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /MTd /Z7 /Od")
    SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
    SET(CMAKE_CXX_FLAGS_RELEASE "/DNDEBUG /MT /O2")
    SET(CMAKE_CXX_FLAGS_MINSIZEREL "/DNDEBUG /MT /O2")
    SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/DNDEBUG /MTd /Z7 /Od")


message( "CMAKE_CXX_FLAGS_INIT:INTERNAL=${CMAKE_CXX_FLAGS_INIT}" )
message( "CMAKE_CXX_FLAGS_DEBUG:INTERNAL=${CMAKE_CXX_FLAGS_DEBUG" )
message( "CMAKE_CXX_FLAGS_DEBUG_INIT:INTERNAL=${CMAKE_CXX_FLAGS_DEBUG_INIT}" )
message( "CMAKE_C_FLAGS_DEBUG:INTERNAL=${CMAKE_C_FLAGS_DEBUG}" )
message( "CMAKE_C_FLAGS_DEBUG_INIT:INTERNAL=${CMAKE_C_FLAGS_DEBUG_INIT}" )
    




set( CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_LIST_DIR}/install CACHE STRING "" FORCE )


set( CMD echo "CMAKE_C_FLAGS_DEBUG = ${CMAKE_C_FLAGS_DEBUG}" )


add_custom_target(
    pete
    ALL
    ${CMD}
    )



# ${TOP}/some_external_project/CMakeList.txt ===================
# END


The following ouput should be seen in VS output window regarding output pete where last line CMAKE_C_FLAGS_DEBUG is not as expected (/MTd option specified):

3> 2> Creating "x64\Debug\pete\pete.unsuccessfulbuild" because "AlwaysCreate" was specified.
3>
3> 2>CustomBuild:
3>
3> 2> Building Custom Rule C:/projects/CMakeTesting/external_project_test/some_external_project/CMakeLists.txt
3>
3> 2> CMake does not need to re-run because C:\projects\CMakeTesting\external_project_test\build\some_proj-prefix\src\some_proj-build\CMakeFiles\generate.stamp is up-to-date.
3>
3> 2> "CMAKE_C_FLAGS_DEBUG = /MTd /Z7 /Od"



        
Additional InformationAttached is zipped version of above files. Any version of VS should do.
TagsNo tags attached.
Attached Fileszip file icon external_project_test.zip [^] (1,976 bytes) 2014-01-17 15:02

 Relationships

  Notes
(0034966)
Brad King (manager)
2014-01-20 09:17

Your inner project CMakeLists.txt file contains

# these settings never change even for C or C++
SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /MT /O2")
SET(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /MT /O2")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/DNDEBUG /MT /O2")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "/DNDEBUG /MT /O2")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/DNDEBUG /MTd /Z7 /Od")

which hard-codes these values and overrides anything in its cache.
(0034967)
Brad King (manager)
2014-01-20 09:19

If I add to EXTERNAL_PROJECT_GLOBAL_COMPILER_FLAGS the flag

  -DAN_INTERNAL_VAR:INTERNAL="an internal value"

and add a message in the inner project:

  message( "AN_INTERNAL_VAR:INTERNAL=${AN_INTERNAL_VAR}" )

then during build I see "an internal value" printed out in the inner project.

If I change the flag to

  -DAN_INTERNAL_VAR:INTERNAL="another internal value"

and build again then I see "another internal value" printed out.
(0034968)
Brad King (manager)
2014-01-20 09:22

Read the "Variables" section of the new "cmake-language.7" manual:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Help/manual/cmake-language.7.rst;hb=1b395813#l393 [^]

for an explanation of variable name binding and its relationship to cache variables.
(0034979)
Brian J. Davis (reporter)
2014-01-20 17:16

I want to first thank you for setting this to closed before I even have a chance to respond. Wow from 8:17am to 8:22am (CST) to closed. How is someone to respond? I think I know the answer to that.

Having done my home work as you suggest and reading:

http://cmake.org/gitweb?p=cmake.git;a=blob;f=Help/manual/cmake-language.7.rst;hb=1b395813#l393 [^]

I am not sure what I am to gain from this. Maybe I am missing the point or do not fully understand how CMake works (which I am sure is the case) and this may need to continue on Users list and not here so that I can learn what I am missing.

Of key importance in the document you referenced is the total lack of any discussion on the term FORCE or INTERNAL for that matter. Which relates directly to my question and the reason for the bug report.

However in response to :

http://www.cmake.org/Bug/view.php?id=14705#c34967 [^]

I do not doubt for a minute that what you have works. It (an example with any other variable other than the ones I am interested in) does work for me too. However it does not work for any of the CMAKE_[*]_FLAGS_[*]. Which is also pertaining directly to my question and this bug submission. I was expecting a certain behavior and did not experiencing it based on the CMake documentation.


1) What is meaning of FORCE? (I believe I know the answer to this - FORCE the variable in the CACHE - such as the text set( VAR 'value', CACHE STRING "" FORCE)

2) If INTERNAL is specified and implies FORCE then when ExternalProject_Add is called with -DCMAKE_CXX_FLAGS_MINSIZEREL:INTERNAL="/DNDEBUG /MD /O2" will sub project CMAKE_CXX_FLAGS_MINSIZEREL be overridden. If not why? If not should it based on documentation that I have referenced? Sub project is clearly not FORCEing variable in the CACHE and the parent project can not seem to force the CMAKE_[*]_FLAGS_[*] variables in the subproject

In the end I can read on how CMake is *documented* to work and I experience how it *does* work, but have no idea how it *should* work.
(0034981)
Brad King (manager)
2014-01-21 08:45

Re 0014705:0034979: I marked the issue as "resolved" which still allows you to re-open and comment as you did. After 4 months of inactivity resolved issues are later marked "closed".

FORCE tells set() to overwrite an existing non-INTERNAL cache entry and ignore whatever the user may have manually configured. An INTERNAL cache entry means it belongs to the project and should not be edited by the user manually.

The code in your ExternalProject_Add call correctly sets the cache entry values for the build tree of the inner project. However, as I explained in 0014705:0034966 the code in your inner-project's CMakeLists.txt hides those values by setting normal variables of the same name. Therefore the cache values are not visible and are ignored regardless of their type or value. This is explained in the documentation linked in 0014705:0034968.

A better place for questions and discussion is the mailing list:

 http://www.cmake.org/mailman/listinfo/cmake [^]
(0034987)
Brian J. Davis (reporter)
2014-01-22 11:35

Doing as you suggest and continuing on mailing list. GMANE link here:

http://cmake.3232098.n2.nabble.com/Forcing-MDd-using-externalproject-add-tp7586539.html [^]

I still don't get it so comments/clarifications welcome at mailing list.
(0036090)
Robert Maynard (manager)
2014-06-02 08:38

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2014-01-17 15:02 Brian J. Davis New Issue
2014-01-17 15:02 Brian J. Davis File Added: external_project_test.zip
2014-01-20 09:17 Brad King Note Added: 0034966
2014-01-20 09:19 Brad King Note Added: 0034967
2014-01-20 09:22 Brad King Note Added: 0034968
2014-01-20 09:22 Brad King Status new => resolved
2014-01-20 09:22 Brad King Resolution open => no change required
2014-01-20 09:22 Brad King Description Updated
2014-01-20 09:22 Brad King Additional Information Updated
2014-01-20 17:16 Brian J. Davis Note Added: 0034979
2014-01-20 17:16 Brian J. Davis Status resolved => feedback
2014-01-20 17:16 Brian J. Davis Resolution no change required => reopened
2014-01-21 08:45 Brad King Note Added: 0034981
2014-01-22 11:35 Brian J. Davis Note Added: 0034987
2014-01-22 11:35 Brian J. Davis Status feedback => new
2014-01-22 12:09 Brad King Status new => resolved
2014-01-22 12:09 Brad King Resolution reopened => no change required
2014-06-02 08:38 Robert Maynard Note Added: 0036090
2014-06-02 08:38 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team