Squashed 'cmake/cable/' changes from eb2188b..a727efd

cea3a65 Cable 0.4.0
52aef91 Add -Wshadow to compiler settings
3091e7d Cable 0.3.1
a605a31 Fix typo else() -> elseif()
6885ca6 Cable 0.3.0
019f336 Upgrade HunterGate
b245d3e Add option -DNATIVE=TRUE
5d95a69 Get rid of default warning level on MSVC
27bd330 Do not check for GCC/clang flags support in MSVC
2b8c975 Require cable_build_type() to be used before project()
d221c8d Cable 0.2.18
d2513e7 Quite log about Cable in subprojects

git-subtree-dir: cmake/cable
git-subtree-split: a727efde6b49e4e18256fcf16831df9a35da39af
This commit is contained in:
Paweł Bylica 2019-05-15 11:58:04 +02:00
parent 83e26147e1
commit a0bd7232d7
4 changed files with 122 additions and 132 deletions

View File

@ -10,8 +10,8 @@ set(cable_build_type_included TRUE)
macro(cable_set_build_type)
if(NOT PROJECT_IS_NESTED)
# Do this configuration only in the top project.
if(NOT PROJECT_SOURCE_DIR)
message(FATAL_ERROR "cable_set_build_type() can be used only after project()")
if(PROJECT_SOURCE_DIR)
message(FATAL_ERROR "cable_set_build_type() can be used before project()")
endif()
cmake_parse_arguments(build_type "" DEFAULT CONFIGURATION_TYPES ${ARGN})

View File

@ -57,7 +57,7 @@ macro(cable_configure_compiler)
endif()
# Enable basing warnings set and treat them as errors.
add_compile_options(-Werror -Wall -Wextra)
add_compile_options(-Werror -Wall -Wextra -Wshadow)
if(NOT cable_NO_CONVERSION_WARNINGS)
# Enable conversion warnings if not explicitly disabled.
@ -67,8 +67,32 @@ macro(cable_configure_compiler)
# Allow unknown pragmas, we don't want to wrap them with #ifdefs.
add_compile_options(-Wno-unknown-pragmas)
# Stack protection.
check_cxx_compiler_flag(-fstack-protector fstack-protector)
if(fstack-protector)
# The compiler supports stack protection options.
if(cable_NO_STACK_PROTECTION)
# Stack protection explicitly disabled.
# Add "no" flag, because in some configuration the compiler has it enabled by default.
add_compile_options(-fno-stack-protector)
else()
# Try enabling the "strong" variant.
cable_add_cxx_compiler_flag_if_supported(-fstack-protector-strong have_stack_protector_strong_support)
if(NOT have_stack_protector_strong_support)
# Fallback to standard variant of "strong" not available.
add_compile_options(-fstack-protector)
endif()
endif()
endif()
cable_add_cxx_compiler_flag_if_supported(-Wimplicit-fallthrough)
elseif(MSVC)
# Get rid of default warning level.
string(REPLACE " /W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE " /W3" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# Enable basing warnings set and treat them as errors.
add_compile_options(/W4 /WX)
@ -77,25 +101,19 @@ macro(cable_configure_compiler)
endif()
check_cxx_compiler_flag(-fstack-protector fstack-protector)
if(fstack-protector)
# The compiler supports stack protection options.
if(cable_NO_STACK_PROTECTION)
# Stack protection explicitly disabled.
# Add "no" flag, because in some configuration the compiler has it enabled by default.
add_compile_options(-fno-stack-protector)
# Option for arch=native.
option(NATIVE "Build for native CPU" OFF)
if(NATIVE)
if(MSVC)
add_compile_options(-arch:AVX)
else()
# Try enabling the "strong" variant.
cable_add_cxx_compiler_flag_if_supported(-fstack-protector-strong have_stack_protector_strong_support)
if(NOT have_stack_protector_strong_support)
# Fallback to standard variant of "strong" not available.
add_compile_options(-fstack-protector)
endif()
add_compile_options(-mtune=native -march=native)
endif()
elseif(NOT MSVC)
# Tune for currently most common CPUs.
cable_add_cxx_compiler_flag_if_supported(-mtune=generic)
endif()
cable_add_cxx_compiler_flag_if_supported(-Wimplicit-fallthrough)
# Sanitizers support.
set(SANITIZE OFF CACHE STRING "Build with the specified sanitizer")
if(SANITIZE)

View File

@ -1,4 +1,4 @@
# Copyright (c) 2013-2017, Ruslan Baratov
# Copyright (c) 2013-2019, Ruslan Baratov
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -25,7 +25,7 @@
# This is a gate file to Hunter package manager.
# Include this file using `include` command and add package you need, example:
#
# cmake_minimum_required(VERSION 3.0)
# cmake_minimum_required(VERSION 3.2)
#
# include("cmake/HunterGate.cmake")
# HunterGate(
@ -43,10 +43,14 @@
# * https://github.com/ruslo/hunter
option(HUNTER_ENABLED "Enable Hunter package manager support" ON)
if(HUNTER_ENABLED)
if(CMAKE_VERSION VERSION_LESS "3.0")
message(FATAL_ERROR "At least CMake version 3.0 required for hunter dependency management."
" Update CMake or set HUNTER_ENABLED to OFF.")
if(CMAKE_VERSION VERSION_LESS "3.2")
message(
FATAL_ERROR
"At least CMake version 3.2 required for Hunter dependency management."
" Update CMake or set HUNTER_ENABLED to OFF."
)
endif()
endif()
@ -56,28 +60,28 @@ option(HUNTER_STATUS_PRINT "Print working status" ON)
option(HUNTER_STATUS_DEBUG "Print a lot info" OFF)
option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON)
set(HUNTER_WIKI "https://github.com/ruslo/hunter/wiki")
set(HUNTER_ERROR_PAGE "https://docs.hunter.sh/en/latest/reference/errors")
function(hunter_gate_status_print)
foreach(print_message ${ARGV})
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
foreach(print_message ${ARGV})
message(STATUS "[hunter] ${print_message}")
endif()
endforeach()
endforeach()
endif()
endfunction()
function(hunter_gate_status_debug)
foreach(print_message ${ARGV})
if(HUNTER_STATUS_DEBUG)
if(HUNTER_STATUS_DEBUG)
foreach(print_message ${ARGV})
string(TIMESTAMP timestamp)
message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}")
endif()
endforeach()
endforeach()
endif()
endfunction()
function(hunter_gate_wiki wiki_page)
message("------------------------------ WIKI -------------------------------")
message(" ${HUNTER_WIKI}/${wiki_page}")
function(hunter_gate_error_page error_page)
message("------------------------------ ERROR ------------------------------")
message(" ${HUNTER_ERROR_PAGE}/${error_page}.html")
message("-------------------------------------------------------------------")
message("")
message(FATAL_ERROR "")
@ -90,14 +94,13 @@ function(hunter_gate_internal_error)
endforeach()
message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
message("")
hunter_gate_wiki("error.internal")
hunter_gate_error_page("error.internal")
endfunction()
function(hunter_gate_fatal_error)
cmake_parse_arguments(hunter "" "WIKI" "" "${ARGV}")
string(COMPARE EQUAL "${hunter_WIKI}" "" have_no_wiki)
if(have_no_wiki)
hunter_gate_internal_error("Expected wiki")
cmake_parse_arguments(hunter "" "ERROR_PAGE" "" "${ARGV}")
if("${hunter_ERROR_PAGE}" STREQUAL "")
hunter_gate_internal_error("Expected ERROR_PAGE")
endif()
message("")
foreach(x ${hunter_UNPARSED_ARGUMENTS})
@ -105,11 +108,11 @@ function(hunter_gate_fatal_error)
endforeach()
message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
message("")
hunter_gate_wiki("${hunter_WIKI}")
hunter_gate_error_page("${hunter_ERROR_PAGE}")
endfunction()
function(hunter_gate_user_error)
hunter_gate_fatal_error(${ARGV} WIKI "error.incorrect.input.data")
hunter_gate_fatal_error(${ARGV} ERROR_PAGE "error.incorrect.input.data")
endfunction()
function(hunter_gate_self root version sha1 result)
@ -130,14 +133,10 @@ function(hunter_gate_self root version sha1 result)
string(SUBSTRING "${sha1}" 0 7 archive_id)
if(EXISTS "${root}/cmake/Hunter")
set(hunter_self "${root}")
else()
set(
hunter_self
"${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked"
)
endif()
set(
hunter_self
"${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked"
)
set("${result}" "${hunter_self}" PARENT_SCOPE)
endfunction()
@ -191,24 +190,10 @@ function(hunter_gate_detect_root)
hunter_gate_fatal_error(
"Can't detect HUNTER_ROOT"
WIKI "error.detect.hunter.root"
ERROR_PAGE "error.detect.hunter.root"
)
endfunction()
macro(hunter_gate_lock dir)
if(NOT HUNTER_SKIP_LOCK)
if("${CMAKE_VERSION}" VERSION_LESS "3.2")
hunter_gate_fatal_error(
"Can't lock, upgrade to CMake 3.2 or use HUNTER_SKIP_LOCK"
WIKI "error.can.not.lock"
)
endif()
hunter_gate_status_debug("Locking directory: ${dir}")
file(LOCK "${dir}" DIRECTORY GUARD FUNCTION)
hunter_gate_status_debug("Lock done")
endif()
endmacro()
function(hunter_gate_download dir)
string(
COMPARE
@ -224,7 +209,7 @@ function(hunter_gate_download dir)
"Settings:"
" HUNTER_ROOT: ${HUNTER_GATE_ROOT}"
" HUNTER_SHA1: ${HUNTER_GATE_SHA1}"
WIKI "error.run.install"
ERROR_PAGE "error.run.install"
)
endif()
string(COMPARE EQUAL "${dir}" "" is_bad)
@ -248,7 +233,10 @@ function(hunter_gate_download dir)
set(build_dir "${dir}/Build")
set(cmakelists "${dir}/CMakeLists.txt")
hunter_gate_lock("${dir}")
hunter_gate_status_debug("Locking directory: ${dir}")
file(LOCK "${dir}" DIRECTORY GUARD FUNCTION)
hunter_gate_status_debug("Lock done")
if(EXISTS "${done_location}")
# while waiting for lock other instance can do all the job
hunter_gate_status_debug("File '${done_location}' found, skip install")
@ -265,7 +253,7 @@ function(hunter_gate_download dir)
file(
WRITE
"${cmakelists}"
"cmake_minimum_required(VERSION 3.0)\n"
"cmake_minimum_required(VERSION 3.2)\n"
"project(HunterDownload LANGUAGES NONE)\n"
"include(ExternalProject)\n"
"ExternalProject_Add(\n"
@ -330,7 +318,11 @@ function(hunter_gate_download dir)
)
if(NOT download_result EQUAL 0)
hunter_gate_internal_error("Configure project failed")
hunter_gate_internal_error(
"Configure project failed."
"To reproduce the error run: ${CMAKE_COMMAND} -H${dir} -B${build_dir} -G${CMAKE_GENERATOR} ${toolchain_arg} ${make_arg}"
"In directory ${dir}"
)
endif()
hunter_gate_status_print(
@ -396,14 +388,14 @@ macro(HunterGate)
)
include("${_hunter_self}/cmake/Hunter")
else()
set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_LIST_DIR}")
set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}")
string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name)
if(_have_project_name)
hunter_gate_fatal_error(
"Please set HunterGate *before* 'project' command. "
"Detected project: ${PROJECT_NAME}"
WIKI "error.huntergate.before.project"
ERROR_PAGE "error.huntergate.before.project"
)
endif()
@ -473,7 +465,7 @@ macro(HunterGate)
"HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces."
"Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error"
"(Use at your own risk!)"
WIKI "error.spaces.in.hunter.root"
ERROR_PAGE "error.spaces.in.hunter.root"
)
endif()
endif()
@ -498,44 +490,37 @@ macro(HunterGate)
)
set(_master_location "${_hunter_self}/cmake/Hunter")
if(EXISTS "${HUNTER_GATE_ROOT}/cmake/Hunter")
# Hunter downloaded manually (e.g. by 'git clone')
set(_unused "xxxxxxxxxx")
set(HUNTER_GATE_SHA1 "${_unused}")
set(HUNTER_GATE_VERSION "${_unused}")
else()
get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE)
set(_done_location "${_archive_id_location}/DONE")
set(_sha1_location "${_archive_id_location}/SHA1")
get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE)
set(_done_location "${_archive_id_location}/DONE")
set(_sha1_location "${_archive_id_location}/SHA1")
# Check Hunter already downloaded by HunterGate
if(NOT EXISTS "${_done_location}")
hunter_gate_download("${_archive_id_location}")
endif()
# Check Hunter already downloaded by HunterGate
if(NOT EXISTS "${_done_location}")
hunter_gate_download("${_archive_id_location}")
endif()
if(NOT EXISTS "${_done_location}")
hunter_gate_internal_error("hunter_gate_download failed")
endif()
if(NOT EXISTS "${_done_location}")
hunter_gate_internal_error("hunter_gate_download failed")
endif()
if(NOT EXISTS "${_sha1_location}")
hunter_gate_internal_error("${_sha1_location} not found")
endif()
file(READ "${_sha1_location}" _sha1_value)
string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal)
if(NOT _is_equal)
hunter_gate_internal_error(
"Short SHA1 collision:"
" ${_sha1_value} (from ${_sha1_location})"
" ${HUNTER_GATE_SHA1} (HunterGate)"
)
endif()
if(NOT EXISTS "${_master_location}")
hunter_gate_user_error(
"Master file not found:"
" ${_master_location}"
"try to update Hunter/HunterGate"
)
endif()
if(NOT EXISTS "${_sha1_location}")
hunter_gate_internal_error("${_sha1_location} not found")
endif()
file(READ "${_sha1_location}" _sha1_value)
string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal)
if(NOT _is_equal)
hunter_gate_internal_error(
"Short SHA1 collision:"
" ${_sha1_value} (from ${_sha1_location})"
" ${HUNTER_GATE_SHA1} (HunterGate)"
)
endif()
if(NOT EXISTS "${_master_location}")
hunter_gate_user_error(
"Master file not found:"
" ${_master_location}"
"try to update Hunter/HunterGate"
)
endif()
include("${_master_location}")
set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES)

View File

@ -10,7 +10,7 @@
#
# This is internal variable automatically updated with external tools.
# Use CABLE_VERSION variable if you need this information.
set(version 0.2.17)
set(version 0.4.0)
# For convenience, add the project CMake module dir to module path.
set(module_dir ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
@ -19,38 +19,25 @@ if(EXISTS ${module_dir})
endif()
if(CABLE_VERSION)
# Some other instance of Cable was initialized in the top project.
# Compare versions of the top project and this instances.
if(CABLE_VERSION VERSION_LESS version)
set(severity WARNING)
set(comment "version older than ${version}")
elseif(CABLE_VERSION VERSION_EQUAL version)
set(severity STATUS)
set(comment "same version")
else()
set(severity STATUS)
set(comment "version newer than ${version}")
endif()
# Find the name of the top project.
# Make sure the name is not overwritten by multiple nested projects.
if(NOT DEFINED cable_top_project_name)
set(cable_top_project_name ${PROJECT_NAME})
endif()
# Some other instance of Cable has been initialized in the top project.
# Mark this project as nested.
set(PROJECT_IS_NESTED TRUE)
message(
${severity}
"[cable ] Cable ${CABLE_VERSION} (${comment}) initialized in the `${cable_top_project_name}` parent project"
)
# Compare versions of the top project and this instances.
if(CABLE_VERSION VERSION_LESS version)
set(comment " (version older than ${version})")
elseif(CABLE_VERSION VERSION_GREATER version)
set(comment " (version newer than ${version})")
endif()
# Log information about initialization in the top project.
file(RELATIVE_PATH subproject_dir ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
cable_debug("${subproject_dir}: Cable ${CABLE_VERSION}${comment} already initialized in the top project")
cable_debug("Project CMake modules directory: ${module_dir}")
unset(version)
unset(module_dir)
unset(severity)
unset(comment)
return()
endif()