MantisBT - CMake
View Issue Details
0015287CMakeCMakepublic2014-12-07 17:172015-11-02 09:13
Zachary Sims 
 
normalfeatureN/A
closedfixed 
 
CMake 3.3CMake 3.3 
0015287: ExternalProject commands do not support generator expressions
ExternalProject_* does not support generator expressions. For projects such as boost, "variant" can be set to debug or release. However, ${CONFIG} will be either Debug or Release (note case).


Example being:
ExternalProject_Add(
    boost
    DOWNLOAD_COMMAND snip
    SOURCE_DIR # snip
    BUILD_IN_SOURCE 1
    UPDATE_COMMAND ""
    PATCH_COMMAND ""
    CONFIGURE_COMMAND ${BOOST_BOOTSTRAP_COMMAND}
    BUILD_COMMAND
        b2 variant=$<LOWER_CASE:$<CONFIG>>
    INSTALL_COMMAND ""
    LOG_DOWNLOAD 1
    LOG_CONFIGURE 1
    LOG_BUILD 1
)

It's true the generator expressions might not always be sufficient, but would certainly help.
No tags attached.
Issue History
2014-12-07 17:17Zachary SimsNew Issue
2014-12-08 08:44Brad KingNote Added: 0037402
2014-12-08 16:59Zachary SimsNote Added: 0037420
2014-12-09 08:24Brad KingNote Added: 0037425
2015-04-21 11:02Brad KingNote Added: 0038573
2015-04-21 11:02Brad KingStatusnew => resolved
2015-04-21 11:02Brad KingResolutionopen => fixed
2015-04-21 11:02Brad KingFixed in Version => CMake 3.3
2015-04-21 11:02Brad KingTarget Version => CMake 3.3
2015-11-02 09:13Robert MaynardNote Added: 0039785
2015-11-02 09:13Robert MaynardStatusresolved => closed

Notes
(0037402)
Brad King   
2014-12-08 08:44   
The _COMMAND options just map to add_custom_command underneath, and that supports generator expressions. I just tried an example and it works for me.

Can you post a non-snipped example where it does not work?
(0037420)
Zachary Sims   
2014-12-08 16:59   
Forgive my somewhat rash jump to conclusions. Reading the source to ExternalProject.cmake I thought that it always wrote the build steps to a .cmake file.

However, upon further digging... generator expressions are not supported if LOG_BUILD is set, as externalproject will wrap the command in an execute_process to log the output.

A short, standalone way to reproduce the bug:

cmake_minimum_required(VERSION 3.0)

project(generator_expressions_ep)
include(ExternalProject)

externalproject_add(
    otherproject
    SOURCE_DIR .
    BUILD_IN_SOURCE 1
    BUILD_COMMAND ${CMAKE_COMMAND} -E echo $<LOWER_CASE:$<CONFIG>>
    INSTALL_COMMAND ""
    LOG_BUILD 1
)

Note that removing LOG_BUILD 1 means the generator expression will be evaluated, otherwise it's not.
(0037425)
Brad King   
2014-12-09 08:24   
Re 0015287:0037420: Good catch. This would have not been possible to solve at the time this infrastructure was first written, but now we have file(GENERATE) which may make this possible.

Please look at converting the file(WRITE) calls in _ep_write_log_script to file(GENERATE) calls. To work in multi-config generators a loop over CMAKE_CONFIGURATION_TYPES and a separate script per configuration will be needed. The custom command used to launch the script with cmake -P will also need a generator expression to determine which script to run based on $<CONFIG>.
(0038573)
Brad King   
2015-04-21 11:02   
Fixed and test case added:

 ExternalProject: Allow generator expressions with LOG_* options
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0273ef14 [^]
(0039785)
Robert Maynard   
2015-11-02 09:13   
Closing resolved issues that have not been updated in more than 4 months.