Skip to content

Commit

Permalink
Creates LookupCatch to enable particular versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dpshelio committed Sep 8, 2018
1 parent 13bc9b6 commit c8de5c1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 25 deletions.
65 changes: 65 additions & 0 deletions modules/LookUpCatch.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Installs catchorg/Catch2 into build directory
#
# - URL: defaults to latest single_include
# - VERSION: defaults to latest

if(Catch_ARGUMENTS)
cmake_parse_arguments(Catch "" "URL;VERSION" ""
${Catch_ARGUMENTS})
endif()

if(NOT Catch_VERSION)
set(Catch_URL_VERSION master)
else()
set (Catch_URL_VERSION "v${Catch_VERSION}")
endif()

if(NOT Catch_URL)
set(Catch_URL https://raw.githubusercontent.com/catchorg/Catch2/${Catch_URL_VERSION}/single_include/catch2/catch.hpp)
endif()

set(Catch_FILE "${EXTERNAL_ROOT}/include/catch.hpp")
file(MAKE_DIRECTORY "${EXTERNAL_ROOT}/include")
file(DOWNLOAD ${Catch_URL} "${Catch_FILE}")

file(READ "${Catch_FILE}" CATCHSTRING LIMIT 1000)
string(LENGTH "${CATCHSTRING}" CATCHLENGTH)


if(NOT CATCHLENGTH GREATER 500)
find_package(Wget)
if(WGET_FOUND)
execute_process(COMMAND ${WGET_EXECUTABLE}
${Catch_URL}
-O ${Catch_FILE}
)
else()
find_program(CURL_EXECUTABLE curl)
execute_process(COMMAND ${CURL_EXECUTABLE}
-L ${Catch_URL}
-o ${Catch_FILE}
)
endif()
endif()

file(READ "${Catch_FILE}" CATCHSTRING LIMIT 1000)
string(LENGTH "${CATCHSTRING}" CATCHLENGTH)
if(NOT CATCHLENGTH GREATER 500)
file(REMOVE "${Catch_FILE}")
message(FATAL_ERROR "Failed to download Catch ${CATCHSTRING} ${CATCHLENGTH}")
endif()


ExternalProject_Add(
Lookup-Catch
PREFIX "${EXTERNAL_ROOT}"
DOWNLOAD_COMMAND ""
# ARGUMENTS
# Force separate output paths for debug and release builds to allow easy

# Wrap download, configure and build steps in a script to log output
UPDATE_COMMAND ""
LOG_DOWNLOAD ON LOG_CONFIGURE ON LOG_BUILD ON LOG_INSTALL ON
)

add_recursive_cmake_step(Lookup-Catch DEPENDEES install)
26 changes: 1 addition & 25 deletions scripts/AddCatchTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,7 @@ find_package(Catch)

if(NOT CATCH_FOUND)
# setups things so include can be found
include(PackageLookup)
set(catch_url
https://raw.githubusercontent.com/catchorg/Catch2/master/single_include/catch2/catch.hpp)
set(catch_file "${EXTERNAL_ROOT}/include/catch.hpp")
file(MAKE_DIRECTORY "${EXTERNAL_ROOT}/include")
file(DOWNLOAD ${catch_url} "${catch_file}")
file(READ "${catch_file}" CATCHSTRING LIMIT 1000)
string(LENGTH "${CATCHSTRING}" CATCHLENGTH)
if(NOT CATCHLENGTH GREATER 500)
# CMake can't download over https if build lacks ssl. So use wget or curl
find_package(Wget)
if(WGET_FOUND)
execute_process(COMMAND ${WGET_EXECUTABLE} ${catch_url} -O "${catch_file}")
else()
find_program(CURL_EXECUTABLE curl)
execute_process(COMMAND ${CURL_EXECUTABLE} -L ${catch_url} -o "${catch_file}")
endif()
file(READ "${catch_file}" CATCHSTRING LIMIT 1000)
string(LENGTH "${CATCHSTRING}" CATCHLENGTH)
if(NOT CATCHLENGTH GREATER 500)
file(REMOVE "${catch_file}")
message(FATAL_ERROR "Failed to download Catch ${CATCHSTRING} ${CATCHLENGTH}")
endif()
endif()
find_package(Catch REQUIRED)
lookup_package(Catch REQUIRED)
endif()

# Function to create a common main
Expand Down

0 comments on commit c8de5c1

Please sign in to comment.