Skip to content

Commit

Permalink
Merge pull request RobotLocomotion#3174 from mwoehlke-kitware/externa…
Browse files Browse the repository at this point in the history
…l-source-subdir

Add SOURCE_SUBDIR support to externals
  • Loading branch information
mwoehlke-kitware authored Aug 18, 2016
2 parents 6622062 + ca83edb commit 8d9f922
Show file tree
Hide file tree
Showing 7 changed files with 2,804 additions and 11 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,14 @@ drake_add_external(bot_core_lcmtypes PUBLIC CMAKE
DEPENDS lcm libbot) # Conflicts with libbot; ensure this is built after

# director
drake_add_external(director PUBLIC
BUILD_COMMAND_DIR distro/pods/drake-distro # FIXME: fix need for this
drake_add_external(director PUBLIC CMAKE
SOURCE_SUBDIR distro/superbuild
CMAKE_ARGS
-DUSE_LCM=ON # TODO: predicate on whether we have LCM enabled?
-DUSE_LCMGL=ON
-DUSE_SYSTEM_LCM=ON
-DUSE_EXTERNAL_INSTALL=ON
INSTALL_COMMAND :
DEPENDS bot_core_lcmtypes lcm libbot)

# signalscope
Expand Down
22 changes: 22 additions & 0 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ macro(drake_setup_java)
endif()
endmacro()

#------------------------------------------------------------------------------
# Add local CMake modules to CMake search path.
#------------------------------------------------------------------------------
function(drake_setup_cmake BASE_PATH)
file(GLOB _versions RELATIVE ${BASE_PATH} "${BASE_PATH}/*/")
foreach(_version ${_versions})
if(IS_DIRECTORY "${BASE_PATH}/${_version}")
if(CMAKE_VERSION VERSION_LESS ${_version})
list(INSERT CMAKE_MODULE_PATH 0 "${BASE_PATH}/${_version}")
endif()
endif()
endforeach()
list(INSERT CMAKE_MODULE_PATH 0 ${BASE_PATH})
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
endfunction()

#------------------------------------------------------------------------------
# Set up basic platform properties for building Drake.
#------------------------------------------------------------------------------
Expand Down Expand Up @@ -146,3 +162,9 @@ macro(drake_setup_superbuild)
endif()
message(STATUS CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})
endmacro()

###############################################################################

# Set up local module paths; this needs to be done immediately as other helper
# modules may need to include things from our local module set
drake_setup_cmake(${CMAKE_CURRENT_LIST_DIR}/modules)
15 changes: 6 additions & 9 deletions cmake/externals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ macro(drake_add_cmake_external PROJECT)
# Set up the external project build
ExternalProject_Add(${PROJECT}
LIST_SEPARATOR "${_ext_LIST_SEPARATOR}"
SOURCE_SUBDIR ${_ext_SOURCE_SUBDIR}
SOURCE_DIR ${_ext_SOURCE_DIR}
BINARY_DIR ${_ext_BINARY_DIR}
DOWNLOAD_DIR ${PROJECT_SOURCE_DIR}
Expand Down Expand Up @@ -187,14 +188,6 @@ macro(drake_add_foreign_external PROJECT)
${_ext_VERBOSE}
BUILD_PREFIX=${CMAKE_INSTALL_PREFIX}
BUILD_TYPE=$<CONFIGURATION>)
if(_ext_BUILD_COMMAND_DIR)
# FIXME: This is only needed for Director due to the unusual build setup
# used by the same. We should fix director to be a 'normal' CMake
# project, and remove this option
set(_ext_BUILD_COMMAND ${CMAKE_COMMAND}
-E chdir ${_ext_BUILD_COMMAND_DIR}
${_ext_BUILD_COMMAND})
endif()
endif()

if(NOT _ext_BUILD_COMMAND STREQUAL "")
Expand Down Expand Up @@ -236,6 +229,7 @@ endmacro()
# ensure correct build order. (Dependencies which are not enabled will be
# ignored.)
#
# SOURCE_SUBDIR <dir> - Specify SOURCE_SUBDIR for external
# SOURCE_DIR <dir> - Override default SOURCE_DIR for external
# BINARY_DIR <dir> - Override default BINARY_DIR for external
#
Expand Down Expand Up @@ -266,9 +260,9 @@ function(drake_add_external PROJECT)
INSTALL_COMMAND)
set(_ext_flags LOCAL PUBLIC CMAKE ALWAYS)
set(_ext_sv_args
SOURCE_SUBDIR
SOURCE_DIR
BINARY_DIR
BUILD_COMMAND_DIR # FIXME: fix director then remove this
)
set(_ext_mv_args
CMAKE_ARGS
Expand Down Expand Up @@ -327,6 +321,9 @@ function(drake_add_external PROJECT)
if(NOT DEFINED _ext_SOURCE_DIR)
set(_ext_SOURCE_DIR ${PROJECT_SOURCE_DIR}/externals/${PROJECT})
endif()
if(NOT DEFINED _ext_SOURCE_SUBDIR)
set(_ext_SOURCE_SUBDIR .)
endif()

# Compute project dependencies
drake_compute_dependencies(_ext_deps ${_ext_DEPENDS})
Expand Down
57 changes: 57 additions & 0 deletions cmake/modules/3.7/Copyright.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
CMake - Cross Platform Makefile Generator
Copyright 2000-2016 Kitware, Inc.
Copyright 2000-2011 Insight Software Consortium
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

* Neither the names of Kitware, Inc., the Insight Software Consortium,
nor the names of their contributors may be used to endorse or promote
products derived from this software without specific prior written
permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

------------------------------------------------------------------------------

The above copyright and license notice applies to distributions of
CMake in source and binary form. Some source files contain additional
notices of original copyright by their contributors; see each source
for details. Third-party software packages supplied with CMake under
compatible licenses provide their own copyright notices documented in
corresponding subdirectories.

------------------------------------------------------------------------------

CMake was initially developed by Kitware with the following sponsorship:

* National Library of Medicine at the National Institutes of Health
as part of the Insight Segmentation and Registration Toolkit (ITK).

* US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel
Visualization Initiative.

* National Alliance for Medical Image Computing (NAMIC) is funded by the
National Institutes of Health through the NIH Roadmap for Medical Research,
Grant U54 EB005149.

* Kitware, Inc.
161 changes: 161 additions & 0 deletions cmake/modules/3.7/ExternalProject-download.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#=============================================================================
# Copyright 2008-2013 Kitware, Inc.
# Copyright 2016 Ruslan Baratov
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)

cmake_minimum_required(VERSION 3.5)

function(check_file_hash has_hash hash_is_good)
if("${has_hash}" STREQUAL "")
message(FATAL_ERROR "has_hash Can't be empty")
endif()

if("${hash_is_good}" STREQUAL "")
message(FATAL_ERROR "hash_is_good Can't be empty")
endif()

if("@ALGO@" STREQUAL "")
# No check
set("${has_hash}" FALSE PARENT_SCOPE)
set("${hash_is_good}" FALSE PARENT_SCOPE)
return()
endif()

set("${has_hash}" TRUE PARENT_SCOPE)

message(STATUS "verifying file...
file='@LOCAL@'")

file("@ALGO@" "@LOCAL@" actual_value)

if(NOT "${actual_value}" STREQUAL "@EXPECT_VALUE@")
set("${hash_is_good}" FALSE PARENT_SCOPE)
message(STATUS "@ALGO@ hash of
@LOCAL@
does not match expected value
expected: '@EXPECT_VALUE@'
actual: '${actual_value}'")
else()
set("${hash_is_good}" TRUE PARENT_SCOPE)
endif()
endfunction()

function(sleep_before_download attempt)
if(attempt EQUAL 0)
return()
endif()

if(attempt EQUAL 1)
message(STATUS "Retrying...")
return()
endif()

set(sleep_seconds 0)

if(attempt EQUAL 2)
set(sleep_seconds 5)
elseif(attempt EQUAL 3)
set(sleep_seconds 5)
elseif(attempt EQUAL 4)
set(sleep_seconds 15)
elseif(attempt EQUAL 5)
set(sleep_seconds 60)
elseif(attempt EQUAL 6)
set(sleep_seconds 90)
elseif(attempt EQUAL 7)
set(sleep_seconds 300)
else()
set(sleep_seconds 1200)
endif()

message(STATUS "Retry after ${sleep_seconds} seconds (attempt #${attempt}) ...")

execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep "${sleep_seconds}")
endfunction()

if("@LOCAL@" STREQUAL "")
message(FATAL_ERROR "LOCAL can't be empty")
endif()

if("@REMOTE@" STREQUAL "")
message(FATAL_ERROR "REMOTE can't be empty")
endif()

if(EXISTS "@LOCAL@")
check_file_hash(has_hash hash_is_good)
if(has_hash)
if(hash_is_good)
message(STATUS "File already exists and hash match (skip download):
file='@LOCAL@'
@ALGO@='@EXPECT_VALUE@'"
)
return()
else()
message(STATUS "File already exists but hash mismatch. Removing...")
file(REMOVE "@LOCAL@")
endif()
else()
message(STATUS "File already exists but no hash specified (use URL_HASH):
file='@LOCAL@'
Old file will be removed and new file downloaded from URL."
)
file(REMOVE "@LOCAL@")
endif()
endif()

set(retry_number 5)

foreach(i RANGE ${retry_number})
sleep_before_download(${i})

message(STATUS "downloading...
src='@REMOTE@'
dst='@LOCAL@'
timeout='@TIMEOUT_MSG@'")

@TLS_VERIFY_CODE@
@TLS_CAINFO_CODE@

file(
DOWNLOAD
"@REMOTE@" "@LOCAL@"
@SHOW_PROGRESS@
@TIMEOUT_ARGS@
STATUS status
LOG log
)

list(GET status 0 status_code)
list(GET status 1 status_string)

if(status_code EQUAL 0)
check_file_hash(has_hash hash_is_good)
if(has_hash AND NOT hash_is_good)
message(STATUS "Hash mismatch, removing...")
file(REMOVE "@LOCAL@")
else()
message(STATUS "Downloading... done")
return()
endif()
else()
message("error: downloading '@REMOTE@' failed
status_code: ${status_code}
status_string: ${status_string}
log:
--- LOG BEGIN ---
${log}
--- LOG END ---"
)
endif()
endforeach()

message(FATAL_ERROR "Downloading failed")
48 changes: 48 additions & 0 deletions cmake/modules/3.7/ExternalProject-verify.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#=============================================================================
# Copyright 2008-2013 Kitware, Inc.
# Copyright 2016 Ruslan Baratov
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)

cmake_minimum_required(VERSION 3.5)

if("@LOCAL@" STREQUAL "")
message(FATAL_ERROR "LOCAL can't be empty")
endif()

if(NOT EXISTS "@LOCAL@")
message(FATAL_ERROR "File not found: @LOCAL@")
endif()

if("@ALGO@" STREQUAL "")
message(WARNING "File will not be verified since no URL_HASH specified")
return()
endif()

if("@EXPECT_VALUE@" STREQUAL "")
message(FATAL_ERROR "EXPECT_VALUE can't be empty")
endif()

message(STATUS "verifying file...
file='@LOCAL@'")

file("@ALGO@" "@LOCAL@" actual_value)

if(NOT "${actual_value}" STREQUAL "@EXPECT_VALUE@")
message(FATAL_ERROR "error: @ALGO@ hash of
@LOCAL@
does not match expected value
expected: '@EXPECT_VALUE@'
actual: '${actual_value}'
")
endif()

message(STATUS "verifying file... done")
Loading

0 comments on commit 8d9f922

Please sign in to comment.