MantisBT - CMake
View Issue Details
0014646CMakeCMakepublic2013-12-12 23:292014-06-02 08:37
Richard Shaw 
Brad King 
normaltextalways
closedfixed 
Linux 64-bitFedora19
CMake 2.8.12 
CMake 3.0CMake 3.0 
0014646: Clarify if(TARGET) documentation
I believe this is a regression from 2.8.11. I had this working although there have been changes to the cmake configuration so it's impossible to be sure.

I have a project that uses wxWidgets. Because wxWidgets uses a custom script to generate linker and include flags it must be built before my project can even be configured. I worked around this by adding a bootstrap option that will download and build static libraries of wxWidgets, then cmake/make is run again after the needed configuration script is available.

Ever since updating to 2.8.12 (currently 2.8.12.1), cmake skips the configuration and build of wxWidgets.
Here is a summarized version of the logic in my cmake configuration but also includes some debug info I added to verify the problem:
if(BOOTSTRAP_WXWIDGETS)
    message(STATUS "Adding wxWidgets build target...")
    include(cmake/BuildWxWidgets.cmake)
    if(TARGET wxWidgets)
        message(STATUS "wxWidgets target exists.")
    endif()
endif(BOOTSTRAP_WXWIDGETS)

The externalproject target is added in BuildWxWidgets.cmake. Per the documentation "if(TARGET wxWidgets)" should only test TRUE once the target is built but the cmake output includes output indicating it's testing TRUE once the target is added.

For reference, here is the contents of BuildWxWidgets.cmake:
set(WXWIDGETS_TARBALL "wxWidgets-2.9.4")

include(ExternalProject)
ExternalProject_Add(wxWidgets
    URL http://downloads.sourceforge.net/wxwindows/${WXWIDGETS_TARBALL}.tar.bz2 [^]
    BUILD_IN_SOURCE 1
    INSTALL_DIR external/dist
    CONFIGURE_COMMAND ./configure --disable-shared --prefix=${CMAKE_BINARY_DIR}/external/dist
    BUILD_COMMAND $(MAKE)
    INSTALL_COMMAND $(MAKE) install
)
set(WXCONFIG "${CMAKE_BINARY_DIR}/external/dist/bin/wx-config")
set(WXRC "${CMAKE_BINARY_DIR}/external/dist/bin/wxrc")
No tags attached.
Issue History
2013-12-12 23:29Richard ShawNew Issue
2013-12-18 11:20Brad KingNote Added: 0034787
2013-12-18 11:41Richard ShawNote Added: 0034791
2013-12-18 15:06Brad KingNote Added: 0034798
2013-12-18 15:06Brad KingAssigned To => Brad King
2013-12-18 15:06Brad KingSeveritymajor => text
2013-12-18 15:06Brad KingStatusnew => resolved
2013-12-18 15:06Brad KingResolutionopen => fixed
2013-12-18 15:06Brad KingFixed in Version => CMake 3.0
2013-12-18 15:06Brad KingTarget Version => CMake 3.0
2013-12-18 15:06Brad KingSummaryTest for TARGET return TRUE if it exists rather than if it has been built or imported. => Clarify if(TARGET) documentation
2014-06-02 08:37Robert MaynardNote Added: 0036057
2014-06-02 08:37Robert MaynardStatusresolved => closed

Notes
(0034787)
Brad King   
2013-12-18 11:20   
The meaning of if(TARGET) has always been whether the target exists. The documentation wording as of 2.8.12:

http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:if [^]
" if(TARGET target-name)

True if the given name is an existing target, built or imported."

The ", built or imported" part is trying to say that "existing" does not distinguish between targets declared to be built by the current project or imported from elsewhere. It has nothing to do with whether the files actually exist on disk.

Perhaps better wording is:

 True if the given name is an existing logical target name such as those created by the add_executable, add_library, or add_custom_target commands.
(0034791)
Richard Shaw   
2013-12-18 11:41   
Ok, that would be good to clairify... I have already updated my config to check for the existence of wx-config in ${install_dir}.
(0034798)
Brad King   
2013-12-18 15:06   
Okay, I've updated the docs:

 Help: Clarify if(TARGET) behavior
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6b8662e6 [^]
(0036057)
Robert Maynard   
2014-06-02 08:37   
Closing resolved issues that have not been updated in more than 4 months.