ENH: Better recursive make in AddExternalProject

This teaches AddExternalProject to run "$(MAKE)" for build and install
steps of CMake-based external projects when using a Makefile generator.
It allows the external project to participate in a parallel make invoked
on the superproject.
This commit is contained in:
Brad King 2009-03-04 11:45:42 -05:00
parent e7f16fcb1b
commit ba5cbf0fb1
2 changed files with 76 additions and 58 deletions

View File

@ -65,6 +65,55 @@ function(get_configure_command_id name cfg_cmd_id_var)
endif() endif()
endfunction(get_configure_command_id) endfunction(get_configure_command_id)
function(_aep_get_build_command name step cmd_var args_var)
# No default arguments if command is user-specified.
set(args)
set(cmd "${${cmd_var}}")
if(NOT cmd)
get_configure_command_id(${name} cfg_cmd_id)
if(cfg_cmd_id STREQUAL "cmake")
# CMake project. Select build command based on generator.
get_target_property(cmake_generator ${name} AEP_CMAKE_GENERATOR)
if("${cmake_generator}" MATCHES "Make" AND
"${cmake_generator}" STREQUAL "${CMAKE_GENERATOR}")
# The project uses the same Makefile generator. Use recursive make.
set(cmd "$(MAKE)")
if(step STREQUAL "INSTALL")
set(args install)
endif()
else()
# Drive the project with "cmake --build".
get_target_property(cfg_cmd ${name} AEP_CONFIGURE_COMMAND)
if(cfg_cmd)
set(cmd "${cfg_cmd}")
else()
set(cmd "${CMAKE_COMMAND}")
endif()
set(args --build ${working_dir} --config ${CMAKE_CFG_INTDIR})
if(step STREQUAL "INSTALL")
list(APPEND args --target install)
endif()
endif()
else() # if(cfg_cmd_id STREQUAL "configure")
# Non-CMake project. Guess "make" and "make install".
set(cmd "make")
if(step STREQUAL "INSTALL")
set(args install)
endif()
endif()
endif()
# Use user-specified build arguments, if any.
get_property(have_args TARGET ${name} PROPERTY AEP_${step}_ARGS SET)
if(have_args)
get_target_property(args ${name} AEP_${step}_ARGS)
endif()
# Return answers to caller.
set(${cmd_var} "${cmd}" PARENT_SCOPE)
set(${args_var} "${args}" PARENT_SCOPE)
endfunction(_aep_get_build_command)
function(mkdir d) function(mkdir d)
file(MAKE_DIRECTORY "${d}") file(MAKE_DIRECTORY "${d}")
@ -443,6 +492,14 @@ function(add_external_project_configure_command name)
separate_arguments(args) separate_arguments(args)
endif() endif()
get_target_property(cmake_generator ${name} AEP_CMAKE_GENERATOR)
if(cmake_generator)
get_configure_command_id(${name} cfg_cmd_id)
if(cfg_cmd_id STREQUAL "cmake")
list(APPEND args "-G${cmake_generator}" "${source_dir}/${name}")
endif()
endif()
add_custom_command( add_custom_command(
OUTPUT ${sentinels_dir}/${name}-configure OUTPUT ${sentinels_dir}/${name}-configure
COMMAND ${cmd} ${args} COMMAND ${cmd} ${args}
@ -471,29 +528,7 @@ function(add_external_project_build_command name)
DEPENDS ${sentinels_dir}/${name}-configure DEPENDS ${sentinels_dir}/${name}-configure
) )
else() else()
get_configure_command_id(${name} cfg_cmd_id) _aep_get_build_command(${name} BUILD cmd args)
if(NOT cmd)
set(cmd make)
if(cfg_cmd_id STREQUAL "cmake")
get_target_property(cfg_cmd ${name} AEP_CONFIGURE_COMMAND)
if(cfg_cmd)
set(cmd ${cfg_cmd})
else()
set(cmd ${CMAKE_COMMAND})
endif()
endif()
endif()
get_property(have_args TARGET ${name} PROPERTY AEP_BUILD_ARGS SET)
if(have_args)
get_target_property(args ${name} AEP_BUILD_ARGS)
else()
set(args)
if(cfg_cmd_id STREQUAL "cmake")
set(args --build ${working_dir} --config ${CMAKE_CFG_INTDIR})
endif()
endif()
add_custom_command( add_custom_command(
OUTPUT ${sentinels_dir}/${name}-build OUTPUT ${sentinels_dir}/${name}-build
@ -524,32 +559,7 @@ function(add_external_project_install_command name)
DEPENDS ${sentinels_dir}/${name}-build DEPENDS ${sentinels_dir}/${name}-build
) )
else() else()
get_configure_command_id(${name} cfg_cmd_id) _aep_get_build_command(${name} INSTALL cmd args)
if(NOT cmd)
set(cmd make)
if(cfg_cmd_id STREQUAL "cmake")
get_target_property(cfg_cmd ${name} AEP_CONFIGURE_COMMAND)
if(cfg_cmd)
set(cmd ${cfg_cmd})
else()
set(cmd ${CMAKE_COMMAND})
endif()
endif()
endif()
get_property(have_args TARGET ${name} PROPERTY AEP_INSTALL_ARGS SET)
if(have_args)
get_target_property(args ${name} AEP_INSTALL_ARGS)
else()
set(args)
if(cfg_cmd_id STREQUAL "cmake")
set(args --build ${working_dir} --config ${CMAKE_CFG_INTDIR} --target install)
endif()
if(cfg_cmd_id STREQUAL "configure")
set(args "install")
endif()
endif()
add_custom_command( add_custom_command(
OUTPUT ${sentinels_dir}/${name}-install OUTPUT ${sentinels_dir}/${name}-install
@ -607,7 +617,7 @@ endfunction(add_CMakeExternals_target)
function(is_known_aep_property_key key result_var) function(is_known_aep_property_key key result_var)
set(${result_var} 0 PARENT_SCOPE) set(${result_var} 0 PARENT_SCOPE)
if(key MATCHES "^BUILD_ARGS|BUILD_COMMAND|CONFIGURE_ARGS|CONFIGURE_COMMAND|CONFIGURE_DIR|CVS_REPOSITORY|CVS_MODULE|CVS_TAG|DEPENDS|DOWNLOAD_ARGS|DOWNLOAD_COMMAND|DIR|INSTALL_ARGS|INSTALL_COMMAND|SVN_REPOSITORY|SVN_TAG|TAR|TAR_URL|TGZ|TGZ_URL|UPDATE_ARGS|UPDATE_COMMAND$" if(key MATCHES "^BUILD_ARGS|BUILD_COMMAND|CMAKE_GENERATOR|CONFIGURE_ARGS|CONFIGURE_COMMAND|CONFIGURE_DIR|CVS_REPOSITORY|CVS_MODULE|CVS_TAG|DEPENDS|DOWNLOAD_ARGS|DOWNLOAD_COMMAND|DIR|INSTALL_ARGS|INSTALL_COMMAND|SVN_REPOSITORY|SVN_TAG|TAR|TAR_URL|TGZ|TGZ_URL|UPDATE_ARGS|UPDATE_COMMAND$"
) )
#message(STATUS "info: recognized via MATCHES - key='${key}'") #message(STATUS "info: recognized via MATCHES - key='${key}'")
set(${result_var} 1 PARENT_SCOPE) set(${result_var} 1 PARENT_SCOPE)

View File

@ -118,7 +118,8 @@ endif()
set(proj TutorialStep1-LocalTAR) set(proj TutorialStep1-LocalTAR)
add_external_project(${proj} add_external_project(${proj}
TAR "${CMAKE_CURRENT_SOURCE_DIR}/Step1.tar" TAR "${CMAKE_CURRENT_SOURCE_DIR}/Step1.tar"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\" -G \"${CMAKE_GENERATOR}\" \"${source_dir}/${proj}\"" CMAKE_GENERATOR "${CMAKE_GENERATOR}"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\""
INSTALL_COMMAND "" INSTALL_COMMAND ""
) )
@ -142,7 +143,8 @@ add_external_project(${proj}
set(proj TutorialStep1-LocalNoDirTGZ) set(proj TutorialStep1-LocalNoDirTGZ)
add_external_project(${proj} add_external_project(${proj}
TGZ "${CMAKE_CURRENT_SOURCE_DIR}/Step1NoDir.tgz" TGZ "${CMAKE_CURRENT_SOURCE_DIR}/Step1NoDir.tgz"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\" -G \"${CMAKE_GENERATOR}\" \"${source_dir}/${proj}\"" CMAKE_GENERATOR "${CMAKE_GENERATOR}"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\""
INSTALL_COMMAND "" INSTALL_COMMAND ""
) )
@ -167,7 +169,8 @@ if(can_use_cvs)
CVS_REPOSITORY ":pserver:anonymous:cmake@www.cmake.org:/cvsroot/CMake" CVS_REPOSITORY ":pserver:anonymous:cmake@www.cmake.org:/cvsroot/CMake"
CVS_MODULE "CMake/Tests/Tutorial/Step1" CVS_MODULE "CMake/Tests/Tutorial/Step1"
CVS_TAG "-D\;2008-12-01 01:00:00 UTC" CVS_TAG "-D\;2008-12-01 01:00:00 UTC"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\" -G \"${CMAKE_GENERATOR}\" \"${source_dir}/${proj}\"" CMAKE_GENERATOR "${CMAKE_GENERATOR}"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\""
INSTALL_COMMAND "" INSTALL_COMMAND ""
) )
@ -178,7 +181,8 @@ if(can_use_cvs)
CVS_REPOSITORY ":pserver:anonymous:cmake@www.cmake.org:/cvsroot/CMake" CVS_REPOSITORY ":pserver:anonymous:cmake@www.cmake.org:/cvsroot/CMake"
CVS_MODULE "CMake/Source/kwsys" CVS_MODULE "CMake/Source/kwsys"
CVS_TAG "-r\;CMake-2-6-2" CVS_TAG "-r\;CMake-2-6-2"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\" -G \"${CMAKE_GENERATOR}\" \"${source_dir}/${proj}\"" CMAKE_GENERATOR "${CMAKE_GENERATOR}"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\""
INSTALL_COMMAND "" INSTALL_COMMAND ""
) )
@ -189,7 +193,8 @@ if(can_use_cvs)
add_external_project(${proj} add_external_project(${proj}
CVS_REPOSITORY ":pserver:anoncvs@public.kitware.com:/cvsroot/KWStyle" CVS_REPOSITORY ":pserver:anoncvs@public.kitware.com:/cvsroot/KWStyle"
CVS_MODULE "KWStyle" CVS_MODULE "KWStyle"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\" -G \"${CMAKE_GENERATOR}\" \"${source_dir}/${proj}\"" CMAKE_GENERATOR "${CMAKE_GENERATOR}"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\""
DEPENDS "EmptyNoOpProject" DEPENDS "EmptyNoOpProject"
DEPENDS "TutorialStep1-LocalTAR" DEPENDS "TutorialStep1-LocalTAR"
DEPENDS "TutorialStep1-LocalNoDirTAR" DEPENDS "TutorialStep1-LocalNoDirTAR"
@ -211,7 +216,8 @@ if(can_use_svn)
add_external_project(${proj} add_external_project(${proj}
SVN_REPOSITORY "http://gdcm.svn.sourceforge.net/svnroot/gdcm/trunk/Utilities/gdcmmd5" SVN_REPOSITORY "http://gdcm.svn.sourceforge.net/svnroot/gdcm/trunk/Utilities/gdcmmd5"
SVN_TAG "-r\;{2008-12-04 01:00:00 +0000}" SVN_TAG "-r\;{2008-12-04 01:00:00 +0000}"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\" -G \"${CMAKE_GENERATOR}\" \"${source_dir}/${proj}\"" CMAKE_GENERATOR "${CMAKE_GENERATOR}"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\""
) )
# SVN by revision number: # SVN by revision number:
@ -220,7 +226,8 @@ if(can_use_svn)
add_external_project(${proj} add_external_project(${proj}
SVN_REPOSITORY "http://gdcm.svn.sourceforge.net/svnroot/gdcm/trunk/Utilities/gdcmmd5" SVN_REPOSITORY "http://gdcm.svn.sourceforge.net/svnroot/gdcm/trunk/Utilities/gdcmmd5"
SVN_TAG "-r\;4824" SVN_TAG "-r\;4824"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\" -G \"${CMAKE_GENERATOR}\" \"${source_dir}/${proj}\"" CMAKE_GENERATOR "${CMAKE_GENERATOR}"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\""
INSTALL_COMMAND "" INSTALL_COMMAND ""
) )
@ -229,7 +236,8 @@ if(can_use_svn)
set(proj gdcm-md5-SVNtrunk) set(proj gdcm-md5-SVNtrunk)
add_external_project(${proj} add_external_project(${proj}
SVN_REPOSITORY "http://gdcm.svn.sourceforge.net/svnroot/gdcm/trunk/Utilities/gdcmmd5" SVN_REPOSITORY "http://gdcm.svn.sourceforge.net/svnroot/gdcm/trunk/Utilities/gdcmmd5"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\" -G \"${CMAKE_GENERATOR}\" \"${source_dir}/${proj}\"" CMAKE_GENERATOR "${CMAKE_GENERATOR}"
CONFIGURE_ARGS "\"-DCMAKE_INSTALL_PREFIX:PATH=${prefix}\""
INSTALL_COMMAND "" INSTALL_COMMAND ""
) )
endif() endif()