From 0eff135b7da86e1be02d9a9a157bbd572ebd4d31 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 16 Apr 2019 14:43:40 +1000 Subject: [PATCH 01/63] Start implementation of generic dependency system --- Findsettings.cmake | 5 ++ GenericFindDependency.cmake | 148 ++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 Findsettings.cmake create mode 100644 GenericFindDependency.cmake diff --git a/Findsettings.cmake b/Findsettings.cmake new file mode 100644 index 0000000..741d978 --- /dev/null +++ b/Findsettings.cmake @@ -0,0 +1,5 @@ +include("GenericFindDependency.cmake") +GenericFindDependency( + TargetName settings + SourceSubdir "c" + ) diff --git a/GenericFindDependency.cmake b/GenericFindDependency.cmake new file mode 100644 index 0000000..f40c7f4 --- /dev/null +++ b/GenericFindDependency.cmake @@ -0,0 +1,148 @@ +function(search_dependency_source) + set(argOptions "") + set(argSingleArguments "TargetName" "SourceDir") + set(argMultiArguments "") + + cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) + + if ("${x_UNPARSED_ARGUMENTS}" != "") + message(FATAL_ERROR "Unexpected extra arguments in search_dependency_source: ${x_UNPARSED_ARGUMENTS}") + endif() + + if(EXISTS "${x_SourceDir}/CMakeLists.txt") + message(STATUS "Found ${x_TargetName} source code in ${x_SourceDir}") + add_subdirectory(${x_SourceDir}) +endfunction() + +function(search_dependency_system) + set(argOptions "") + set(argSingleArguments "TargetName" "SystemHeaderFile" "SystemLibNames") + set(argMultiArguments "") + + cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) + + if ("${x_UNPARSED_ARGUMENTS}" != "") + message(FATAL_ERROR "Unexpected extra arguments in search_dependency_system: ${x_UNPARSED_ARGUMENTS}") + endif() + + find_path(x_IncludeDir ${x_SystemHeaderFile}) + find_library(x_Library NAMES ${x_SystemLibNames}) + + include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(${x_TargetName} DEFAULT_MSG x_Library x_IncludeDir) + + if (${x_TargetName}_FOUND) + add_library(${x_TargetName} UNKNOWN IMPORTED) + set_target_properties(${x_TargetName} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${x_IncludeDir}") + set_property(TARGET ${x_TargetName} APPEND PROPERTY + IMPORTED_LOCATION "${x_Library}") + message(STATUS "Found ${x_TargetName} from the system at ${x_Library}") + endif() +endfunction() + +function(GenericFindDependency) + set(argOptions "") + set(argSingleArguments "") + set(argMultiArguments "") + + cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) + + if("${x_UNPARSED_ARGUMENTS}" != "") + message(FATAL_ERROR "Unexpected unparsed arguments ${x_UNPARSED_ARGUMENTS}") + endif() + + if(TARGET ${x_TargetName}) + # Target already defined, no need to do anything more + return() + endif() + + set(x_Locations "") + + if(NOT x_Prefer) + if (SWIFT_PREFERRED_DEPENDENCY_SOURCE) + set(x_Prefer "${SWIFT_PREFERRED_DEPENDENCY_SOURCE") + else() + set(x_Prefer "source") + endif() + endif() + + if(${x_Prefer} == "source") + list(APPEND x_Locations "source" "system") + else() + list(APPEND x_Locations "system" "source") + endif() + + if(x_Exclude) + foreach(S ${x_Exclude}) + list(REMOVE_ITEM x_Locations ${S}) + endforeach() + endif() + + if(SWIFT_EXCLUDE_DEPENDENCY_SOURCE) + foreach(S ${SWIFT_EXCLUDE_DEPENDENCY_SOURCE}) + list(REMOVE_ITEM x_Locations ${S}) + endforeach() + endif() + + list(LENGTH ${x_Locations} x_NumLocations) + if (${x_NumLocations} == 0) + if (x_REQUIRED) + message(FATAL_ERROR "Could not find dependency ${x_TargetName}, no locations available") + else() + message(WARNING "Could not find dependency ${x_TargetName}, no locations available") + return() + endif() + endif() + + foreach(LOCATION ${x_Locations}) + if (${LOCATION} == "source") + # set defaults + if(NOT x_SourceDir) + if(NOT x_SourcePrefix) + set(x_SourcePrefix "vendored") + endif() + + if (NOT x_SourceSubdir) + set(x_SourceSubdir ".") + endif() + + set(x_SourceDir "${x_SourcePrefix}/${x_SourceSubdir}") + endif() + + search_dependency_source( + TargetName "${x_TargetName}" + SourceDir "${x_SourcePrefix}" + ) + + if(TARGET ${x_TargetName}) + message(STATUS "Using dependency ${x_TargetName} from bundled source code") + return() + endif() + else() + if(NOT x_SystemHeaderFile) + set(x_SystemHeaderFile "lib${x_TargetName}/${x_TargetName}.h") + endif() + + set(SystemLibNames ${x_SystemLibName} ${x_TargetName} "lib${x_TargetName}") + + search_dependency_system( + TargetName "${x_TargetName}" + SystemHeaderFile "${x_SystemHeaderFile}" + SystemLibNames "${x_SystemLibNames}" + ) + + if(TARGET ${x_TargetName}) + message(STATUS "Using dependency ${x_TargetName} from system") + return() + endif() + endif() + endforeach() + + if(x_REQUIRED) + message(FATAL_ERROR "Could not find dependency ${x_TargetName} in any available location") + else() + message(WARNING "Could not find dependency ${x_TargetName} in any available location") + endif() +endfunction() + From 8e2c79ad7cb6c0e5a20a40e737d1a7db8db17668 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 16 Apr 2019 15:20:49 +1000 Subject: [PATCH 02/63] Modules for rtcm and sbp --- Findrtcm.cmake | 5 +++++ Findsbp.cmake | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 Findrtcm.cmake create mode 100644 Findsbp.cmake diff --git a/Findrtcm.cmake b/Findrtcm.cmake new file mode 100644 index 0000000..21d2968 --- /dev/null +++ b/Findrtcm.cmake @@ -0,0 +1,5 @@ +include("GenericFindDependency.cmake") +GenericFindDependency( + TargetName rtcm + SourceSubdir "c" + ) diff --git a/Findsbp.cmake b/Findsbp.cmake new file mode 100644 index 0000000..e3365ec --- /dev/null +++ b/Findsbp.cmake @@ -0,0 +1,5 @@ +include("GenericFindDependency.cmake") +GenericFindDependency( + TargetName sbp + SourceSubdir "c" + ) From 46f61287a7e7c3c55c34440d18ca068e1a0ec9e7 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 16 Apr 2019 16:49:02 +1000 Subject: [PATCH 03/63] Fix up generic dependency code, new modules --- Findrtcm.cmake | 1 - Findsbp.cmake | 2 +- Findsettings.cmake | 2 +- Findswiftnav.cmake | 4 +++ GenericFindDependency.cmake | 71 +++++++++++++++++++------------------ 5 files changed, 43 insertions(+), 37 deletions(-) create mode 100644 Findswiftnav.cmake diff --git a/Findrtcm.cmake b/Findrtcm.cmake index 21d2968..29fd6b1 100644 --- a/Findrtcm.cmake +++ b/Findrtcm.cmake @@ -1,4 +1,3 @@ -include("GenericFindDependency.cmake") GenericFindDependency( TargetName rtcm SourceSubdir "c" diff --git a/Findsbp.cmake b/Findsbp.cmake index e3365ec..569de99 100644 --- a/Findsbp.cmake +++ b/Findsbp.cmake @@ -1,4 +1,4 @@ -include("GenericFindDependency.cmake") +include("GenericFindDependency") GenericFindDependency( TargetName sbp SourceSubdir "c" diff --git a/Findsettings.cmake b/Findsettings.cmake index 741d978..5a10bb4 100644 --- a/Findsettings.cmake +++ b/Findsettings.cmake @@ -1,4 +1,4 @@ -include("GenericFindDependency.cmake") +include("GenericFindDependency") GenericFindDependency( TargetName settings SourceSubdir "c" diff --git a/Findswiftnav.cmake b/Findswiftnav.cmake new file mode 100644 index 0000000..6e74b57 --- /dev/null +++ b/Findswiftnav.cmake @@ -0,0 +1,4 @@ +include("GenericFindDependency") +GenericFindDependency( + TargetName swiftnav + ) diff --git a/GenericFindDependency.cmake b/GenericFindDependency.cmake index f40c7f4..d0be07b 100644 --- a/GenericFindDependency.cmake +++ b/GenericFindDependency.cmake @@ -5,50 +5,53 @@ function(search_dependency_source) cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) - if ("${x_UNPARSED_ARGUMENTS}" != "") + if (x_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unexpected extra arguments in search_dependency_source: ${x_UNPARSED_ARGUMENTS}") endif() if(EXISTS "${x_SourceDir}/CMakeLists.txt") - message(STATUS "Found ${x_TargetName} source code in ${x_SourceDir}") - add_subdirectory(${x_SourceDir}) + message(STATUS "Found ${x_TargetName} source code in ${x_SourceDir}") + add_subdirectory(${x_SourceDir}) + else() + message(STATUS "No ${x_TargetName} source available in ${x_SourceDir}") + endif() endfunction() function(search_dependency_system) set(argOptions "") - set(argSingleArguments "TargetName" "SystemHeaderFile" "SystemLibNames") - set(argMultiArguments "") + set(argSingleArguments "TargetName" "SystemHeaderFile") + set(argMultiArguments "SystemLibNames") cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) - if ("${x_UNPARSED_ARGUMENTS}" != "") + if (x_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unexpected extra arguments in search_dependency_system: ${x_UNPARSED_ARGUMENTS}") endif() - find_path(x_IncludeDir ${x_SystemHeaderFile}) - find_library(x_Library NAMES ${x_SystemLibNames}) + find_path(x_${x_TargetName}_IncludeDir ${x_SystemHeaderFile}) + find_library(x_${x_TargetName}_Library NAMES ${x_SystemLibNames}) - include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) - FIND_PACKAGE_HANDLE_STANDARD_ARGS(${x_TargetName} DEFAULT_MSG x_Library x_IncludeDir) - - if (${x_TargetName}_FOUND) - add_library(${x_TargetName} UNKNOWN IMPORTED) - set_target_properties(${x_TargetName} PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${x_IncludeDir}") - set_property(TARGET ${x_TargetName} APPEND PROPERTY - IMPORTED_LOCATION "${x_Library}") - message(STATUS "Found ${x_TargetName} from the system at ${x_Library}") + if(NOT x_${x_TargetName}_IncludeDir OR NOT x_${x_TargetName}_Library) + message(STATUS "Could not find ${x_TargetName} from any available sysroot path") + return() endif() + + add_library(${x_TargetName} UNKNOWN IMPORTED) + set_target_properties(${x_TargetName} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${x_${x_TargetName}_IncludeDir}") + set_property(TARGET ${x_TargetName} APPEND PROPERTY + IMPORTED_LOCATION "${x_${x_TargetName}_Library}") + message(STATUS "Found ${x_TargetName} from the system at ${x_${x_TargetName}_Library}") endfunction() function(GenericFindDependency) - set(argOptions "") - set(argSingleArguments "") - set(argMultiArguments "") + set(argOptions "REQUIRED") + set(argSingleArguments "TargetName" "Prefer" "SourceDir" "SourcePrefix" "SourceSubdir" "SystemHeaderFile" "SystemLibNames") + set(argMultiArguments "Exclude") cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) - if("${x_UNPARSED_ARGUMENTS}" != "") + if(x_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unexpected unparsed arguments ${x_UNPARSED_ARGUMENTS}") endif() @@ -57,20 +60,20 @@ function(GenericFindDependency) return() endif() - set(x_Locations "") - if(NOT x_Prefer) if (SWIFT_PREFERRED_DEPENDENCY_SOURCE) - set(x_Prefer "${SWIFT_PREFERRED_DEPENDENCY_SOURCE") + set(x_Prefer "${SWIFT_PREFERRED_DEPENDENCY_SOURCE}") else() set(x_Prefer "source") endif() endif() - if(${x_Prefer} == "source") + if(${x_Prefer} STREQUAL "source") list(APPEND x_Locations "source" "system") - else() + elseif(${x_Prefer} STREQUAL "system") list(APPEND x_Locations "system" "source") + else() + message(FATAL_ERROR "Unknown value for dependency location prefer: ${x_Prefer}") endif() if(x_Exclude) @@ -85,8 +88,8 @@ function(GenericFindDependency) endforeach() endif() - list(LENGTH ${x_Locations} x_NumLocations) - if (${x_NumLocations} == 0) + list(LENGTH x_Locations x_NumLocations) + if (${x_NumLocations} EQUAL 0) if (x_REQUIRED) message(FATAL_ERROR "Could not find dependency ${x_TargetName}, no locations available") else() @@ -96,23 +99,23 @@ function(GenericFindDependency) endif() foreach(LOCATION ${x_Locations}) - if (${LOCATION} == "source") + if (${LOCATION} STREQUAL "source") # set defaults if(NOT x_SourceDir) if(NOT x_SourcePrefix) - set(x_SourcePrefix "vendored") + set(x_SourcePrefix "vendored/lib${x_TargetName}") endif() if (NOT x_SourceSubdir) set(x_SourceSubdir ".") endif() - set(x_SourceDir "${x_SourcePrefix}/${x_SourceSubdir}") + set(x_SourceDir "${CMAKE_CURRENT_SOURCE_DIR}/${x_SourcePrefix}/${x_SourceSubdir}") endif() search_dependency_source( TargetName "${x_TargetName}" - SourceDir "${x_SourcePrefix}" + SourceDir "${x_SourceDir}" ) if(TARGET ${x_TargetName}) @@ -124,7 +127,7 @@ function(GenericFindDependency) set(x_SystemHeaderFile "lib${x_TargetName}/${x_TargetName}.h") endif() - set(SystemLibNames ${x_SystemLibName} ${x_TargetName} "lib${x_TargetName}") + set(x_SystemLibNames "${x_SystemLibName}" "${x_TargetName}" "lib${x_TargetName}") search_dependency_system( TargetName "${x_TargetName}" From c818e512b2982b044e3b43bface9e091aadb86c7 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 29 Apr 2019 11:54:46 +1000 Subject: [PATCH 04/63] Add googletest module --- Findgoogletest.cmake | 6 ++++++ GenericFindDependency.cmake | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 Findgoogletest.cmake diff --git a/Findgoogletest.cmake b/Findgoogletest.cmake new file mode 100644 index 0000000..87f246d --- /dev/null +++ b/Findgoogletest.cmake @@ -0,0 +1,6 @@ +include("GenericFindDependency") +GenericFindDependency( + TargetName gtest + SourcePrefix "vendored/googletest" + SourceSubdir "googletest" + ) diff --git a/GenericFindDependency.cmake b/GenericFindDependency.cmake index d0be07b..8fdafb5 100644 --- a/GenericFindDependency.cmake +++ b/GenericFindDependency.cmake @@ -12,6 +12,16 @@ function(search_dependency_source) if(EXISTS "${x_SourceDir}/CMakeLists.txt") message(STATUS "Found ${x_TargetName} source code in ${x_SourceDir}") add_subdirectory(${x_SourceDir}) + + if(NOT TARGET ${x_TargetName}) + message(WARNING "Source code in ${x_SourceDir} did not declare target ${x_TargetName} as was expected") + return() + endif() + + # This is very ugly, but required for some python modules, it will not last beyond this temporary solution + if(EXISTS "${x_SourceDir}/include") + set(x_${x_TargetName}_IncludeDir "${x_SourceDir}/include" CACHE PATH "Path to ${x_TargetName} bundled source code header files") + endif() else() message(STATUS "No ${x_TargetName} source available in ${x_SourceDir}") endif() From 90e483029a849b372ee192f91ee9cd2f55cb0854 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 29 Apr 2019 19:32:27 +1000 Subject: [PATCH 05/63] Allow source to be picked up from multiple places --- FindRapidCheck.cmake | 30 +++++++++++++++++ Findgoogletest.cmake | 10 ++++++ GenericFindDependency.cmake | 66 ++++++++++++++++++++++--------------- 3 files changed, 80 insertions(+), 26 deletions(-) create mode 100644 FindRapidCheck.cmake diff --git a/FindRapidCheck.cmake b/FindRapidCheck.cmake new file mode 100644 index 0000000..3e77d8c --- /dev/null +++ b/FindRapidCheck.cmake @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.2) +include("GenericFindDependency") + +set(RC_ENABLE_GTEST ON CACHE BOOL "" FORCE) + +GenericFindDependency( + TargetName rapidcheck + SourcePrefix vendored/rapidcheck + ) + +# Change all of rapidcheck's include directories to be system includes, to avoid +# compiler errors +get_target_property(rapidcheck_interface_includes rapidcheck INTERFACE_INCLUDE_DIRECTORIES) +if(rapidcheck_interface_includes) + set_target_properties(rapidcheck PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(rapidcheck SYSTEM INTERFACE ${rapidcheck_interface_includes}) +else() + message(WARNING "No include directories in rapidcheck, this seems wrong") +endif() +unset(rapidcheck_interface_includes) + +get_target_property(rapidcheck_gtest_interface_includes rapidcheck_gtest INTERFACE_INCLUDE_DIRECTORIES) +if(rapidcheck_gtest_interface_includes) + set_target_properties(rapidcheck_gtest PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(rapidcheck_gtest SYSTEM INTERFACE ${rapidcheck_gtest_interface_includes}) +else() + message(WARNING "No include directories in rapidcheck_gtest, this seems wrong") +endif() +unset(rapidcheck_gtest_interface_includes) + diff --git a/Findgoogletest.cmake b/Findgoogletest.cmake index 87f246d..29da838 100644 --- a/Findgoogletest.cmake +++ b/Findgoogletest.cmake @@ -4,3 +4,13 @@ GenericFindDependency( SourcePrefix "vendored/googletest" SourceSubdir "googletest" ) + +if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) + # Change all of GoogleTest's include directories to be system includes, to avoid + # compiler errors + get_target_property(gtest_include_directories gtest INTERFACE_INCLUDE_DIRECTORIES) + if(gtest_include_directories) + set_target_properties(gtest PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(gtest SYSTEM INTERFACE ${gtest_include_directories}) + endif() +endif() diff --git a/GenericFindDependency.cmake b/GenericFindDependency.cmake index 8fdafb5..64ed202 100644 --- a/GenericFindDependency.cmake +++ b/GenericFindDependency.cmake @@ -1,7 +1,7 @@ function(search_dependency_source) set(argOptions "") - set(argSingleArguments "TargetName" "SourceDir") - set(argMultiArguments "") + set(argSingleArguments "TargetName") + set(argMultiArguments "SourceSearchPaths") cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) @@ -9,22 +9,27 @@ function(search_dependency_source) message(FATAL_ERROR "Unexpected extra arguments in search_dependency_source: ${x_UNPARSED_ARGUMENTS}") endif() - if(EXISTS "${x_SourceDir}/CMakeLists.txt") - message(STATUS "Found ${x_TargetName} source code in ${x_SourceDir}") - add_subdirectory(${x_SourceDir}) + foreach(P ${x_SourceSearchPaths}) + message(STATUS "Searching in ${P}") + if(EXISTS "${P}/CMakeLists.txt") + message(STATUS "Found ${x_TargetName} source code in ${P}") + add_subdirectory(${P}) + + if(NOT TARGET ${x_TargetName}) + message(WARNING "Source code in ${P} did not declare target ${x_TargetName} as was expected") + endif() + + # This is very ugly, but required for some python modules, it will not last beyond this temporary solution + if(EXISTS "${P}/include") + set(x_${x_TargetName}_IncludeDir "${P}/include" CACHE PATH "Path to ${x_TargetName} bundled source code header files") + endif() - if(NOT TARGET ${x_TargetName}) - message(WARNING "Source code in ${x_SourceDir} did not declare target ${x_TargetName} as was expected") + message(STATUS "Found source code for ${x_TargetName} in ${P}") return() endif() + endforeach() - # This is very ugly, but required for some python modules, it will not last beyond this temporary solution - if(EXISTS "${x_SourceDir}/include") - set(x_${x_TargetName}_IncludeDir "${x_SourceDir}/include" CACHE PATH "Path to ${x_TargetName} bundled source code header files") - endif() - else() - message(STATUS "No ${x_TargetName} source available in ${x_SourceDir}") - endif() + message(STATUS "No ${x_TargetName} source available in search paths") endfunction() function(search_dependency_system) @@ -111,21 +116,30 @@ function(GenericFindDependency) foreach(LOCATION ${x_Locations}) if (${LOCATION} STREQUAL "source") # set defaults + set(x_SourceSearchPaths "") if(NOT x_SourceDir) - if(NOT x_SourcePrefix) - set(x_SourcePrefix "vendored/lib${x_TargetName}") - endif() - - if (NOT x_SourceSubdir) - set(x_SourceSubdir ".") - endif() - - set(x_SourceDir "${CMAKE_CURRENT_SOURCE_DIR}/${x_SourcePrefix}/${x_SourceSubdir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/${CMAKE_FIND_PACKAGE_NAME}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/${x_TargetName}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/lib${x_TargetName}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/${CMAKE_FIND_PACKAGE_NAME}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/${x_TargetName}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/lib${x_TargetName}") + else() + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/${x_TargetName}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/lib${x_TargetName}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/${x_TargetName}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/lib${x_TargetName}/${x_SourceDir}") endif() search_dependency_source( TargetName "${x_TargetName}" - SourceDir "${x_SourceDir}" + SourceSearchPaths "${x_SourceSearchPaths}" ) if(TARGET ${x_TargetName}) @@ -152,8 +166,8 @@ function(GenericFindDependency) endif() endforeach() - if(x_REQUIRED) - message(FATAL_ERROR "Could not find dependency ${x_TargetName} in any available location") + if(x_REQUIRED OR ${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) + message(FATAL_ERROR "Could not find REQUIRED dependency ${x_TargetName} in any available location") else() message(WARNING "Could not find dependency ${x_TargetName} in any available location") endif() From ecc36bd81575be296cf26c484c7113b04b8f60bc Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 30 Apr 2019 10:39:00 +1000 Subject: [PATCH 06/63] Move submodules back vendored->third_party --- FindRapidCheck.cmake | 1 - Findgoogletest.cmake | 3 +-- Findsbp.cmake | 2 +- Findsettings.cmake | 2 +- GenericFindDependency.cmake | 28 ++++++++++++++-------------- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/FindRapidCheck.cmake b/FindRapidCheck.cmake index 3e77d8c..893bf73 100644 --- a/FindRapidCheck.cmake +++ b/FindRapidCheck.cmake @@ -5,7 +5,6 @@ set(RC_ENABLE_GTEST ON CACHE BOOL "" FORCE) GenericFindDependency( TargetName rapidcheck - SourcePrefix vendored/rapidcheck ) # Change all of rapidcheck's include directories to be system includes, to avoid diff --git a/Findgoogletest.cmake b/Findgoogletest.cmake index 29da838..064acf9 100644 --- a/Findgoogletest.cmake +++ b/Findgoogletest.cmake @@ -1,8 +1,7 @@ include("GenericFindDependency") GenericFindDependency( TargetName gtest - SourcePrefix "vendored/googletest" - SourceSubdir "googletest" + SourceDir "googletest" ) if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) diff --git a/Findsbp.cmake b/Findsbp.cmake index 569de99..405e037 100644 --- a/Findsbp.cmake +++ b/Findsbp.cmake @@ -1,5 +1,5 @@ include("GenericFindDependency") GenericFindDependency( TargetName sbp - SourceSubdir "c" + SourceDir "c" ) diff --git a/Findsettings.cmake b/Findsettings.cmake index 5a10bb4..b3efe0f 100644 --- a/Findsettings.cmake +++ b/Findsettings.cmake @@ -1,5 +1,5 @@ include("GenericFindDependency") GenericFindDependency( TargetName settings - SourceSubdir "c" + SourceDir "c" ) diff --git a/GenericFindDependency.cmake b/GenericFindDependency.cmake index 64ed202..9a7ce2e 100644 --- a/GenericFindDependency.cmake +++ b/GenericFindDependency.cmake @@ -118,23 +118,23 @@ function(GenericFindDependency) # set defaults set(x_SourceSearchPaths "") if(NOT x_SourceDir) - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/${CMAKE_FIND_PACKAGE_NAME}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/${x_TargetName}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/lib${x_TargetName}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/${CMAKE_FIND_PACKAGE_NAME}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/${x_TargetName}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/lib${x_TargetName}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_TargetName}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib${x_TargetName}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_TargetName}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/lib${x_TargetName}") else() list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_SourceDir}") list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/${x_TargetName}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/vendored/lib${x_TargetName}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/${x_TargetName}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/vendored/lib${x_TargetName}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_TargetName}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib${x_TargetName}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_TargetName}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/lib${x_TargetName}/${x_SourceDir}") endif() search_dependency_source( From ebd7dd35c9c0aa44b35b3edd2cb9822004ae62a8 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 1 May 2019 15:28:49 +1000 Subject: [PATCH 07/63] Import some more common modules, capitalise package names --- FindEigen.cmake | 14 ++++++++++++++ FindFastCSV.cmake | 15 +++++++++++++++ FindGFlags.cmake | 5 +++++ Findgoogletest.cmake => FindGoogletest.cmake | 0 FindJson.cmake | 15 +++++++++++++++ FindOptional.cmake | 4 ++++ Findrtcm.cmake => FindRtcm.cmake | 0 Findsbp.cmake => FindSbp.cmake | 0 Findsettings.cmake => FindSettings.cmake | 0 Findswiftnav.cmake => FindSwiftnav.cmake | 0 FindYaml-Cpp.cmake | 16 ++++++++++++++++ 11 files changed, 69 insertions(+) create mode 100644 FindEigen.cmake create mode 100644 FindFastCSV.cmake create mode 100644 FindGFlags.cmake rename Findgoogletest.cmake => FindGoogletest.cmake (100%) create mode 100644 FindJson.cmake create mode 100644 FindOptional.cmake rename Findrtcm.cmake => FindRtcm.cmake (100%) rename Findsbp.cmake => FindSbp.cmake (100%) rename Findsettings.cmake => FindSettings.cmake (100%) rename Findswiftnav.cmake => FindSwiftnav.cmake (100%) create mode 100644 FindYaml-Cpp.cmake diff --git a/FindEigen.cmake b/FindEigen.cmake new file mode 100644 index 0000000..a681c90 --- /dev/null +++ b/FindEigen.cmake @@ -0,0 +1,14 @@ +include("GenericFindDependency") +GenericFindDependency( + TargetName eigen + ) + +if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) + # Change all of Eigen's include directories to be system includes, to avoid + # compiler errors + get_target_property(eigen_include_directories eigen INTERFACE_INCLUDE_DIRECTORIES) + if(eigen_include_directories) + set_target_properties(eigen PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(eigen SYSTEM INTERFACE ${eigen_include_directories}) + endif() +endif() diff --git a/FindFastCSV.cmake b/FindFastCSV.cmake new file mode 100644 index 0000000..5f2b06c --- /dev/null +++ b/FindFastCSV.cmake @@ -0,0 +1,15 @@ +include("GenericFindDependency") +GenericFindDependency( + TargetName "fast-csv" + SourceDir "fast-cpp-csv-parser" + ) + +if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) + # Change all of fast-csv's include directories to be system includes, to avoid + # compiler errors + get_target_property(fast-csv_include_directories fast-csv INTERFACE_INCLUDE_DIRECTORIES) + if(fast-csv_include_directories) + set_target_properties(fast-csv PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(fast-csv SYSTEM INTERFACE ${fast-csv_include_directories}) + endif() +endif() diff --git a/FindGFlags.cmake b/FindGFlags.cmake new file mode 100644 index 0000000..f4465bd --- /dev/null +++ b/FindGFlags.cmake @@ -0,0 +1,5 @@ +include("GenericFindDependency") +GenericFindDependency( + TargetName gflags + SourceDir "googleflags" + ) diff --git a/Findgoogletest.cmake b/FindGoogletest.cmake similarity index 100% rename from Findgoogletest.cmake rename to FindGoogletest.cmake diff --git a/FindJson.cmake b/FindJson.cmake new file mode 100644 index 0000000..98851fd --- /dev/null +++ b/FindJson.cmake @@ -0,0 +1,15 @@ +include("GenericFindDependency") +GenericFindDependency( + TargetName "nlohmann_json" + SourceDir "json" + ) + +if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) + # Change all of Json's include directories to be system includes, to avoid + # compiler errors + get_target_property(json_include_directories nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) + if(json_include_directories) + set_target_properties(nlohmann_json PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(nlohmann_json SYSTEM INTERFACE ${json_include_directories}) + endif() +endif() diff --git a/FindOptional.cmake b/FindOptional.cmake new file mode 100644 index 0000000..17484f8 --- /dev/null +++ b/FindOptional.cmake @@ -0,0 +1,4 @@ +include("GenericFindDependency") +GenericFindDependency( + TargetName optional + ) diff --git a/Findrtcm.cmake b/FindRtcm.cmake similarity index 100% rename from Findrtcm.cmake rename to FindRtcm.cmake diff --git a/Findsbp.cmake b/FindSbp.cmake similarity index 100% rename from Findsbp.cmake rename to FindSbp.cmake diff --git a/Findsettings.cmake b/FindSettings.cmake similarity index 100% rename from Findsettings.cmake rename to FindSettings.cmake diff --git a/Findswiftnav.cmake b/FindSwiftnav.cmake similarity index 100% rename from Findswiftnav.cmake rename to FindSwiftnav.cmake diff --git a/FindYaml-Cpp.cmake b/FindYaml-Cpp.cmake new file mode 100644 index 0000000..4f13954 --- /dev/null +++ b/FindYaml-Cpp.cmake @@ -0,0 +1,16 @@ +include("GenericFindDependency") +option(YAML_CPP_BUILD_TOOLS "Enable testing and parse tools" OFF) +option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" OFF) +GenericFindDependency( + TargetName "yaml-cpp" + ) + +if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) + # Change all of Yaml-Cpp's include directories to be system includes, to avoid + # compiler errors + get_target_property(yaml-cpp_include_directories yaml-cpp INTERFACE_INCLUDE_DIRECTORIES) + if(yaml-cpp_include_directories) + set_target_properties(yaml-cpp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(yaml-cpp SYSTEM INTERFACE ${yaml-cpp_include_directories}) + endif() +endif() From a319b527519e512c7aafd5c14128c5ca7a462676 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 1 May 2019 15:33:11 +1000 Subject: [PATCH 08/63] Fix librtcm source path --- FindRtcm.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FindRtcm.cmake b/FindRtcm.cmake index 29fd6b1..c3c9bb3 100644 --- a/FindRtcm.cmake +++ b/FindRtcm.cmake @@ -1,4 +1,4 @@ GenericFindDependency( TargetName rtcm - SourceSubdir "c" + SourceDir "c" ) From 95bf587a8c41d84290f237ad4cd770eb59aa43de Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 1 May 2019 16:08:48 +1000 Subject: [PATCH 09/63] Mark gflags as system, add gnss-converters --- FindGFlags.cmake | 10 ++++++++++ FindGnss-converters.cmake | 5 +++++ 2 files changed, 15 insertions(+) create mode 100644 FindGnss-converters.cmake diff --git a/FindGFlags.cmake b/FindGFlags.cmake index f4465bd..363e04f 100644 --- a/FindGFlags.cmake +++ b/FindGFlags.cmake @@ -3,3 +3,13 @@ GenericFindDependency( TargetName gflags SourceDir "googleflags" ) + +if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) + # Change all of GoogleFlags's include directories to be system includes, to avoid + # compiler errors + get_target_property(gflags_include_directories gflags_nothreads_static INTERFACE_INCLUDE_DIRECTORIES) + if(gflags_include_directories) + set_target_properties(gflags_nothreads_static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(gflags_nothreads_static SYSTEM INTERFACE ${gflags_include_directories}) + endif() +endif() diff --git a/FindGnss-converters.cmake b/FindGnss-converters.cmake new file mode 100644 index 0000000..c41d62f --- /dev/null +++ b/FindGnss-converters.cmake @@ -0,0 +1,5 @@ +include("GenericFindDependency") +GenericFindDependency( + TargetName gnss_converters + SourceDir "gnss-converters/c" + ) From d40e2d2b6664dd6695151a98233c4668af095a07 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 1 May 2019 16:36:01 +1000 Subject: [PATCH 10/63] Add protobuf --- FindProtobuf.cmake | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 FindProtobuf.cmake diff --git a/FindProtobuf.cmake b/FindProtobuf.cmake new file mode 100644 index 0000000..362de09 --- /dev/null +++ b/FindProtobuf.cmake @@ -0,0 +1,5 @@ +include("GenericFindDependency") +GenericFindDependency( + TargetName "libprotobuf" + SourceDir "protobuf/cmake" + ) From 6a88f07e95cde88bc314721e7979e9ff69ff5abf Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 1 May 2019 18:38:05 +1000 Subject: [PATCH 11/63] Alter gflags alias target --- FindGFlags.cmake | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/FindGFlags.cmake b/FindGFlags.cmake index 363e04f..970dad8 100644 --- a/FindGFlags.cmake +++ b/FindGFlags.cmake @@ -7,9 +7,12 @@ GenericFindDependency( if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) # Change all of GoogleFlags's include directories to be system includes, to avoid # compiler errors - get_target_property(gflags_include_directories gflags_nothreads_static INTERFACE_INCLUDE_DIRECTORIES) - if(gflags_include_directories) - set_target_properties(gflags_nothreads_static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") - target_include_directories(gflags_nothreads_static SYSTEM INTERFACE ${gflags_include_directories}) + get_target_property(_aliased gflags ALIASED_TARGET) + if(_aliased) + get_target_property(gflags_include_directories ${_aliased} INTERFACE_INCLUDE_DIRECTORIES) + if(gflags_include_directories) + set_target_properties(${_aliased} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(${_aliased} SYSTEM INTERFACE ${gflags_include_directories}) + endif() endif() endif() From e1663506c9419483362ecc0cddc91d53cacb7e1c Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 6 May 2019 12:20:12 +1000 Subject: [PATCH 12/63] Fix find rtcm --- FindRtcm.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/FindRtcm.cmake b/FindRtcm.cmake index c3c9bb3..19bb658 100644 --- a/FindRtcm.cmake +++ b/FindRtcm.cmake @@ -1,3 +1,4 @@ +include("GenericFindDependency") GenericFindDependency( TargetName rtcm SourceDir "c" From 8aa3820cc808413c495d062932a1bfe6309e617b Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 6 May 2019 14:07:54 +1000 Subject: [PATCH 13/63] More modules --- FindOrion-Proto.cmake | 5 +++++ FindStarling.cmake | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 FindOrion-Proto.cmake create mode 100644 FindStarling.cmake diff --git a/FindOrion-Proto.cmake b/FindOrion-Proto.cmake new file mode 100644 index 0000000..3d4d4b6 --- /dev/null +++ b/FindOrion-Proto.cmake @@ -0,0 +1,5 @@ +include("GenericFindDependency") +GenericFindDependency( + TargetName orion-proto + SourceDir "orion_proto" + ) diff --git a/FindStarling.cmake b/FindStarling.cmake new file mode 100644 index 0000000..31a5eb0 --- /dev/null +++ b/FindStarling.cmake @@ -0,0 +1,4 @@ +include("GenericFindDependency") +GenericFindDependency( + TargetName starling + ) From 5c8ce599ccaade4a696d2a314aee9f34cb5faf2b Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Thu, 9 May 2019 15:03:49 +1000 Subject: [PATCH 14/63] Only include header files from eigen --- FindEigen.cmake | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/FindEigen.cmake b/FindEigen.cmake index a681c90..fd2bd58 100644 --- a/FindEigen.cmake +++ b/FindEigen.cmake @@ -1,14 +1,19 @@ -include("GenericFindDependency") -GenericFindDependency( - TargetName eigen - ) +if(TARGET eigen) + return() +endif() + +add_library(eigen INTERFACE) -if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) - # Change all of Eigen's include directories to be system includes, to avoid - # compiler errors - get_target_property(eigen_include_directories eigen INTERFACE_INCLUDE_DIRECTORIES) - if(eigen_include_directories) - set_target_properties(eigen PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") - target_include_directories(eigen SYSTEM INTERFACE ${eigen_include_directories}) - endif() +# Include Eigen library as system headers to suppress warnings when not +# cross-compiling. GNU ARM toolchain wraps system headers with `extern "C"`, +# causing errors, so in this case Eigen must be #included using +# `#pragma GCC system_header` in the source. +# See https://gcc.gnu.org/onlinedocs/cpp/System-Headers.html +if (NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) + target_include_directories(eigen SYSTEM INTERFACE + ${PROJECT_SOURCE_DIR}/third_party/eigen/) +else() + target_include_directories(eigen INTERFACE + ${PROJECT_SOURCE_DIR}/third_party/eigen/) endif() + From 1fcb326dde3fc99e750e7f2e08822839923f3d36 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Thu, 9 May 2019 16:15:55 +1000 Subject: [PATCH 15/63] Recode Optional's header files as system --- FindOptional.cmake | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/FindOptional.cmake b/FindOptional.cmake index 17484f8..449fc58 100644 --- a/FindOptional.cmake +++ b/FindOptional.cmake @@ -2,3 +2,14 @@ include("GenericFindDependency") GenericFindDependency( TargetName optional ) + +if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) + # Change all of Optional's include directories to be system includes, to avoid + # compiler errors + get_target_property(optional_include_directories optional INTERFACE_INCLUDE_DIRECTORIES) + if(optional_include_directories) + message(WARNING "Resetting optional includes ${optional_include_directories}") + set_target_properties(optional PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(optional SYSTEM INTERFACE ${optional_include_directories}) + endif() +endif() From 524fde4ed7b447d0dc9a1b46b725c25f70bd7764 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 13 May 2019 13:20:15 +1000 Subject: [PATCH 16/63] Start standard cmake options module --- SwiftCmakeOptions.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 SwiftCmakeOptions.cmake diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake new file mode 100644 index 0000000..a32f4ba --- /dev/null +++ b/SwiftCmakeOptions.cmake @@ -0,0 +1,9 @@ +if(NOT PROJECT_NAME) + message(FATAL_ERROR "Must define a project before trying to define options") +endif() + +option(${PROJECT_NAME}_BUILD_TESTS "Enable build of unit tests for ${PROJECT_NAME}" ON) +option(${PROJECT_NAME}_BUILD_DOCS "Enable building of documentation for ${PROJECT_NAME}" ON) +option(${PROJECT_NAME}_BUILD_EXAMPLES "Enable building of example code for ${PROJECT_NAME}" ON) + + From 402b75ca48d4b652d790ca3047198e950b375850 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 13 May 2019 13:25:11 +1000 Subject: [PATCH 17/63] Move FindCheck to common repo --- FindCheck.cmake | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 FindCheck.cmake diff --git a/FindCheck.cmake b/FindCheck.cmake new file mode 100644 index 0000000..8ad818f --- /dev/null +++ b/FindCheck.cmake @@ -0,0 +1,55 @@ +# - Try to find the CHECK libraries +# Once done this will define +# +# CHECK_FOUND - system has check +# CHECK_INCLUDE_DIRS - the check include directory +# CHECK_LIBRARIES - check library +# +# Copyright (c) 2007 Daniel Gollub +# Copyright (c) 2007-2009 Bjoern Ricks +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +INCLUDE( FindPkgConfig ) + +IF ( Check_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "REQUIRED" ) +ELSE( Check_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "" ) +ENDIF ( Check_FIND_REQUIRED ) + +IF ( CHECK_MIN_VERSION ) + PKG_SEARCH_MODULE( CHECK ${_pkgconfig_REQUIRED} check>=${CHECK_MIN_VERSION} ) +ELSE ( CHECK_MIN_VERSION ) + PKG_SEARCH_MODULE( CHECK ${_pkgconfig_REQUIRED} check ) +ENDIF ( CHECK_MIN_VERSION ) + +# Look for CHECK include dir and libraries +IF( NOT CHECK_FOUND AND NOT PKG_CONFIG_FOUND ) + + FIND_PATH( CHECK_INCLUDE_DIRS check.h ) + + FIND_LIBRARY( CHECK_LIBRARIES NAMES check ) + + IF ( CHECK_INCLUDE_DIRS AND CHECK_LIBRARIES ) + SET( CHECK_FOUND 1 ) + IF ( NOT Check_FIND_QUIETLY ) + MESSAGE ( STATUS "Found CHECK: ${CHECK_LIBRARIES}" ) + ENDIF ( NOT Check_FIND_QUIETLY ) + ELSE ( CHECK_INCLUDE_DIRS AND CHECK_LIBRARIES ) + IF ( Check_FIND_REQUIRED ) + MESSAGE( FATAL_ERROR "Could NOT find CHECK" ) + ELSE ( Check_FIND_REQUIRED ) + IF ( NOT Check_FIND_QUIETLY ) + MESSAGE( STATUS "Could NOT find CHECK" ) + ENDIF ( NOT Check_FIND_QUIETLY ) + ENDIF ( Check_FIND_REQUIRED ) + ENDIF ( CHECK_INCLUDE_DIRS AND CHECK_LIBRARIES ) +ENDIF( NOT CHECK_FOUND AND NOT PKG_CONFIG_FOUND ) + +# Hide advanced variables from CMake GUIs +MARK_AS_ADVANCED( CHECK_INCLUDE_DIRS CHECK_LIBRARIES ) + From 02ee7a494a6456141c167363535212c255a61366 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 14 May 2019 11:24:58 +1000 Subject: [PATCH 18/63] Turn swift options in to a function --- SwiftCmakeOptions.cmake | 81 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 6 deletions(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index a32f4ba..62234e4 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -1,9 +1,78 @@ -if(NOT PROJECT_NAME) - message(FATAL_ERROR "Must define a project before trying to define options") -endif() +function(swift_create_project_options) + set(argOptions "") + set(argSingleArguments "PROJECT" "TESTS" "TEST_LIBS" "DOCS" "EXAMPLES") + set(argMultiArguments "TEST_PACKAGES") -option(${PROJECT_NAME}_BUILD_TESTS "Enable build of unit tests for ${PROJECT_NAME}" ON) -option(${PROJECT_NAME}_BUILD_DOCS "Enable building of documentation for ${PROJECT_NAME}" ON) -option(${PROJECT_NAME}_BUILD_EXAMPLES "Enable building of example code for ${PROJECT_NAME}" ON) + cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) + if(x_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unexpected extra arguments in swift_create_project_options: ${x_UNPARSED_ARGUMENTS}") + endif() + + if(NOT x_PROJECT) + set(x_PROJECT ${PROJECT_NAME}) + endif() + + if(NOT x_TESTS) + set(x_TESTS ON) + endif() + + if(NOT x_TEST_LIBS) + set(x_TEST_LIBS ON) + endif() + + if(NOT x_DOCS) + set(x_DOCS ON) + endif() + + if(NOT x_EXAMPLES) + set(x_EXAMPLES ON) + endif() + + # Force test libs to be compiled if we are doing unit tests at all + if(x_TESTS) + set(x_TEST_LIBS ON) + endif() + + if(NOT x_SKIP_CROSS_COMPILING_CHECK) + if(CMAKE_CROSSCOMPILING) + # Don't compile any test stuff if we are cross compiling + message(STATUS "Skipping unit tests because we are cross compiling") + set(x_TESTS OFF) + set(x_TEST_LIBS OFF) + endif() + endif() + + foreach(P "${x_TEST_PACKAGES}") + find_package(${P}) + string(TOUPPER ${P} package_name) + if(NOT ${package_name}_FOUND) + message(STATUS "Disable tests because dependency ${package_name} was not found") + set(x_TESTS OFF) + set(x_TEST_LIBS OFF) + endif() + endforeach() + + option(${x_PROJECT}_BUILD_TEST_LIBS "Enable build of test libraries for ${x_PROJECT}" ${x_TEST_LIBS}) + option(${x_PROJECT}_BUILD_TESTS "Enable build of unit tests for ${x_PROJECT}" ${x_TESTS}) + option(${x_PROJECT}_BUILD_DOCS "Enable build of documentation for ${x_PROJECT}" ${x_DOCS}) + option(${x_PROJECT}_BUILD_EXAMPLES "Enable build of example code for ${x_PROJECT}" ${x_EXAMPLES}) + + if(NOT ${x_PROJECT}_BUILD_TEST_LIBS) + message(STATUS "${x_PROJECT} test libraries are DISABLED") + endif() + + if(NOT ${x_PROJECT}_BUILD_TESTS) + message(STATUS "${x_PROJECT} unit tests are DISABLED") + endif() + + if(NOT ${x_PROJECT}_BUILD_DOCS) + message(STATUS "${x_PROJECT} documentation is DISABLED") + endif() + + if(NOT ${x_PROJECT}_BUILD_EXAMPLES) + message(STATUS "${x_PROJECT} examples are DISABLED") + endif() + +endfunction() From 455bad018099f2ced21e097489b9bd1e54b65384 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 14 May 2019 11:48:26 +1000 Subject: [PATCH 19/63] Add handler for gtest --- SwiftCmakeOptions.cmake | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index 62234e4..ab0d3ec 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -43,15 +43,23 @@ function(swift_create_project_options) endif() endif() - foreach(P "${x_TEST_PACKAGES}") - find_package(${P}) - string(TOUPPER ${P} package_name) - if(NOT ${package_name}_FOUND) - message(STATUS "Disable tests because dependency ${package_name} was not found") - set(x_TESTS OFF) - set(x_TEST_LIBS OFF) - endif() - endforeach() + if(x_TESTS OR x_TEST_LIBS) + foreach(P "${x_TEST_PACKAGES}") + find_package(${P}) + # Annoyingly, different test packages have different ways of reporting they were found + set(found FALSE) + if(${P} STREQUAL "Check" AND CHECK_FOUND) + set(found TRUE) + elseif(${P} STREQUAL "Googletest" AND TARGET gtest) + set(found TRUE) + endif() + if(NOT found) + message(STATUS "Disable tests because dependency ${P} was not found") + set(x_TESTS OFF) + set(x_TEST_LIBS OFF) + endif() + endforeach() + endif() option(${x_PROJECT}_BUILD_TEST_LIBS "Enable build of test libraries for ${x_PROJECT}" ${x_TEST_LIBS}) option(${x_PROJECT}_BUILD_TESTS "Enable build of unit tests for ${x_PROJECT}" ${x_TESTS}) From 82adde80c9c17595abdf79cb99fdfccebc226915 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 14 May 2019 13:32:39 +1000 Subject: [PATCH 20/63] Allow empty test packages argument --- SwiftCmakeOptions.cmake | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index ab0d3ec..6f5b58b 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -44,21 +44,23 @@ function(swift_create_project_options) endif() if(x_TESTS OR x_TEST_LIBS) - foreach(P "${x_TEST_PACKAGES}") - find_package(${P}) - # Annoyingly, different test packages have different ways of reporting they were found - set(found FALSE) - if(${P} STREQUAL "Check" AND CHECK_FOUND) - set(found TRUE) - elseif(${P} STREQUAL "Googletest" AND TARGET gtest) - set(found TRUE) - endif() - if(NOT found) - message(STATUS "Disable tests because dependency ${P} was not found") - set(x_TESTS OFF) - set(x_TEST_LIBS OFF) - endif() - endforeach() + if(x_TEST_PACKAGES) + foreach(P "${x_TEST_PACKAGES}") + find_package(${P}) + # Annoyingly, different test packages have different ways of reporting they were found + set(found FALSE) + if(${P} STREQUAL "Check" AND CHECK_FOUND) + set(found TRUE) + elseif(${P} STREQUAL "Googletest" AND TARGET gtest) + set(found TRUE) + endif() + if(NOT found) + message(STATUS "Disable tests because dependency ${P} was not found") + set(x_TESTS OFF) + set(x_TEST_LIBS OFF) + endif() + endforeach() + endif() endif() option(${x_PROJECT}_BUILD_TEST_LIBS "Enable build of test libraries for ${x_PROJECT}" ${x_TEST_LIBS}) From 18bbbb1fc8acb5e711d06e8a342f1457ac7eec64 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 14 May 2019 13:37:26 +1000 Subject: [PATCH 21/63] Remove some debug messages --- GenericFindDependency.cmake | 2 -- 1 file changed, 2 deletions(-) diff --git a/GenericFindDependency.cmake b/GenericFindDependency.cmake index 9a7ce2e..ff03e81 100644 --- a/GenericFindDependency.cmake +++ b/GenericFindDependency.cmake @@ -10,7 +10,6 @@ function(search_dependency_source) endif() foreach(P ${x_SourceSearchPaths}) - message(STATUS "Searching in ${P}") if(EXISTS "${P}/CMakeLists.txt") message(STATUS "Found ${x_TargetName} source code in ${P}") add_subdirectory(${P}) @@ -24,7 +23,6 @@ function(search_dependency_source) set(x_${x_TargetName}_IncludeDir "${P}/include" CACHE PATH "Path to ${x_TargetName} bundled source code header files") endif() - message(STATUS "Found source code for ${x_TargetName} in ${P}") return() endif() endforeach() From 685120035f252b14ec5557aedf23a118f317486d Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 14 May 2019 16:07:52 +1000 Subject: [PATCH 22/63] Add RapidCheck handler --- FindOptional.cmake | 1 - SwiftCmakeOptions.cmake | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/FindOptional.cmake b/FindOptional.cmake index 449fc58..cb7c692 100644 --- a/FindOptional.cmake +++ b/FindOptional.cmake @@ -8,7 +8,6 @@ if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) # compiler errors get_target_property(optional_include_directories optional INTERFACE_INCLUDE_DIRECTORIES) if(optional_include_directories) - message(WARNING "Resetting optional includes ${optional_include_directories}") set_target_properties(optional PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") target_include_directories(optional SYSTEM INTERFACE ${optional_include_directories}) endif() diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index 6f5b58b..cff5cb3 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -45,7 +45,7 @@ function(swift_create_project_options) if(x_TESTS OR x_TEST_LIBS) if(x_TEST_PACKAGES) - foreach(P "${x_TEST_PACKAGES}") + foreach(P ${x_TEST_PACKAGES}) find_package(${P}) # Annoyingly, different test packages have different ways of reporting they were found set(found FALSE) @@ -53,6 +53,8 @@ function(swift_create_project_options) set(found TRUE) elseif(${P} STREQUAL "Googletest" AND TARGET gtest) set(found TRUE) + elseif(${P} STREQUAL "RapidCheck" AND TARGET rapidcheck) + set(found TRUE) endif() if(NOT found) message(STATUS "Disable tests because dependency ${P} was not found") From 8f25513cb17a070d709978feaaaee829b6b807a8 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 14 May 2019 18:34:31 +1000 Subject: [PATCH 23/63] Allow a package to specify what options it supports --- SwiftCmakeOptions.cmake | 82 ++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index cff5cb3..debdc57 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -1,6 +1,6 @@ function(swift_create_project_options) - set(argOptions "") - set(argSingleArguments "PROJECT" "TESTS" "TEST_LIBS" "DOCS" "EXAMPLES") + set(argOptions "TESTS" "TEST_LIBS" "DOCS" "EXAMPLES" "SKIP_CROSS_COMPILING_CHECK") + set(argSingleArguments "PROJECT") set(argMultiArguments "TEST_PACKAGES") cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) @@ -13,37 +13,33 @@ function(swift_create_project_options) set(x_PROJECT ${PROJECT_NAME}) endif() - if(NOT x_TESTS) - set(x_TESTS ON) - endif() - - if(NOT x_TEST_LIBS) - set(x_TEST_LIBS ON) - endif() - - if(NOT x_DOCS) - set(x_DOCS ON) + if(NOT x_SKIP_CROSS_COMPILING_CHECK) + if(CMAKE_CROSSCOMPILING) + # Don't compile any test stuff if we are cross compiling + message(STATUS "Skipping unit tests because we are cross compiling") + set(disable_tests ON) + endif() endif() - if(NOT x_EXAMPLES) - set(x_EXAMPLES ON) + if(NOT disable_tests AND x_TEST_LIBS) + option(${x_PROJECT}_BUILD_TEST_LIBS "Enable build of test libraries for ${x_PROJECT}" ON) + if(NOT ${x_PROJECT}_BUILD_TEST_LIBS) + message(STATUS "${x_PROJECT} test libraries are DISABLED") + endif() endif() - # Force test libs to be compiled if we are doing unit tests at all - if(x_TESTS) - set(x_TEST_LIBS ON) + if(NOT disable_tests AND x_TESTS) + option(${x_PROJECT}_BUILD_TESTS "Enable build of unit tests for ${x_PROJECT}" ON) + if(NOT ${x_PROJECT}_BUILD_TESTS) + message(STATUS "${x_PROJECT} unit tests are DISABLED") + endif() endif() - if(NOT x_SKIP_CROSS_COMPILING_CHECK) - if(CMAKE_CROSSCOMPILING) - # Don't compile any test stuff if we are cross compiling - message(STATUS "Skipping unit tests because we are cross compiling") - set(x_TESTS OFF) - set(x_TEST_LIBS OFF) - endif() + if(NOT ${x_PROJECT}_BUILD_TESTS AND NOT ${x_PROJECT}_BUILD_TEST_LIBS) + set(disable_tests ON) endif() - if(x_TESTS OR x_TEST_LIBS) + if(NOT disable_tests) if(x_TEST_PACKAGES) foreach(P ${x_TEST_PACKAGES}) find_package(${P}) @@ -55,36 +51,36 @@ function(swift_create_project_options) set(found TRUE) elseif(${P} STREQUAL "RapidCheck" AND TARGET rapidcheck) set(found TRUE) + elseif(${P} STREQUAL "GFlags" AND TARGET gflags) + set(found TRUE) endif() if(NOT found) message(STATUS "Disable tests because dependency ${P} was not found") - set(x_TESTS OFF) - set(x_TEST_LIBS OFF) + set(disable_tests ON) endif() endforeach() endif() endif() - option(${x_PROJECT}_BUILD_TEST_LIBS "Enable build of test libraries for ${x_PROJECT}" ${x_TEST_LIBS}) - option(${x_PROJECT}_BUILD_TESTS "Enable build of unit tests for ${x_PROJECT}" ${x_TESTS}) - option(${x_PROJECT}_BUILD_DOCS "Enable build of documentation for ${x_PROJECT}" ${x_DOCS}) - option(${x_PROJECT}_BUILD_EXAMPLES "Enable build of example code for ${x_PROJECT}" ${x_EXAMPLES}) - - if(NOT ${x_PROJECT}_BUILD_TEST_LIBS) - message(STATUS "${x_PROJECT} test libraries are DISABLED") - endif() - - if(NOT ${x_PROJECT}_BUILD_TESTS) - message(STATUS "${x_PROJECT} unit tests are DISABLED") + if(x_DOCS) + option(${x_PROJECT}_BUILD_DOCS "Enable build of documentation for ${x_PROJECT}" ON) + if(NOT ${x_PROJECT}_BUILD_DOCS) + message(STATUS "${x_PROJECT} documentation is DISABLED") + endif() endif() - if(NOT ${x_PROJECT}_BUILD_DOCS) - message(STATUS "${x_PROJECT} documentation is DISABLED") + if(x_EXAMPLES) + option(${x_PROJECT}_BUILD_EXAMPLES "Enable build of example code for ${x_PROJECT}" ON) + if(NOT ${x_PROJECT}_BUILD_EXAMPLES) + message(STATUS "${x_PROJECT} examples are DISABLED") + endif() endif() - if(NOT ${x_PROJECT}_BUILD_EXAMPLES) - message(STATUS "${x_PROJECT} examples are DISABLED") - endif() + foreach(feat "TESTS" "TEST_LIBS" "DOCS" "EXAMPLES") + if(DEFINED ${x_PROJECT}_BUILD_${feat} AND NOT x_${feat}) + message(WARNING "${x_PROJECT}_BUILD_${feat} is set but the package does not support it") + endif() + endforeach() endfunction() From ab737801cd5e893563f8f2d0ae8495d804703d80 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 15 May 2019 10:30:43 +1000 Subject: [PATCH 24/63] Rework enable/disable logic --- SwiftCmakeOptions.cmake | 105 +++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 39 deletions(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index debdc57..3954313 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -1,6 +1,33 @@ +function(verify_test_dependencies) + cmake_parse_arguments(x "" "" "TEST_PACKAGES" ${ARGN}) + + if(x_TEST_PACKAGES) + foreach(P ${x_TEST_PACKAGES}) + find_package(${P}) + # Annoyingly, different test packages have different ways of reporting they were found + set(found FALSE) + if(${P} STREQUAL "Check" AND CHECK_FOUND) + set(found TRUE) + elseif(${P} STREQUAL "Googletest" AND TARGET gtest) + set(found TRUE) + elseif(${P} STREQUAL "RapidCheck" AND TARGET rapidcheck) + set(found TRUE) + elseif(${P} STREQUAL "GFlags" AND TARGET gflags) + set(found TRUE) + endif() + if(NOT found) + message(STATUS "Disable tests because dependency ${P} was not found") + set(test_components_possible OFF PARENT_SCOPE) + endif() + endforeach() + endif() + set(x_test_packages_verified TRUE PARENT_SCOPE) +endfunction() + + function(swift_create_project_options) - set(argOptions "TESTS" "TEST_LIBS" "DOCS" "EXAMPLES" "SKIP_CROSS_COMPILING_CHECK") - set(argSingleArguments "PROJECT") + set(argOptions "HAS_TESTS" "HAS_TEST_LIBS" "HAS_DOCS" "HAS_EXAMPLES" "SKIP_CROSS_COMPILING_CHECK") + set(argSingleArguments "PROJECT" "DISABLE_TEST_COMPONENTS") set(argMultiArguments "TEST_PACKAGES") cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) @@ -13,72 +40,72 @@ function(swift_create_project_options) set(x_PROJECT ${PROJECT_NAME}) endif() + set(test_components_possible ON) + if(x_DISABLE_TEST_COMPONENTS) + set(test_components_possible OFF) + endif() + if(NOT x_SKIP_CROSS_COMPILING_CHECK) if(CMAKE_CROSSCOMPILING) # Don't compile any test stuff if we are cross compiling message(STATUS "Skipping unit tests because we are cross compiling") - set(disable_tests ON) + set(test_components_possible OFF) endif() endif() - if(NOT disable_tests AND x_TEST_LIBS) - option(${x_PROJECT}_BUILD_TEST_LIBS "Enable build of test libraries for ${x_PROJECT}" ON) - if(NOT ${x_PROJECT}_BUILD_TEST_LIBS) - message(STATUS "${x_PROJECT} test libraries are DISABLED") + if(x_HAS_TESTS) + if(NOT x_test_packages_verified) + verify_test_dependencies(TEST_PACKAGES ${x_TEST_PACKAGES}) endif() - endif() - if(NOT disable_tests AND x_TESTS) - option(${x_PROJECT}_BUILD_TESTS "Enable build of unit tests for ${x_PROJECT}" ON) - if(NOT ${x_PROJECT}_BUILD_TESTS) + option(${x_PROJECT}_ENABLE_TESTS "Enable build of unit tests for ${x_PROJECT}" ${test_components_possible}) + if(${x_PROJECT}_ENABLE_TESTS) + if(test_components_possible) + set(${x_PROJECT}_BUILD_TESTS TRUE CACHE BOOL "Build unit tests for ${x_PROJECT}") + else() + message(WARNING "${x_PROJECT} unit tests explicitly enabled but it isn't possible to build them") + endif() + else() message(STATUS "${x_PROJECT} unit tests are DISABLED") endif() endif() - if(NOT ${x_PROJECT}_BUILD_TESTS AND NOT ${x_PROJECT}_BUILD_TEST_LIBS) - set(disable_tests ON) - endif() + if(x_HAS_TEST_LIBS) + if(NOT x_test_packages_verified) + verify_test_dependencies(TEST_PACKAGES ${x_TEST_PACKAGES}) + endif() - if(NOT disable_tests) - if(x_TEST_PACKAGES) - foreach(P ${x_TEST_PACKAGES}) - find_package(${P}) - # Annoyingly, different test packages have different ways of reporting they were found - set(found FALSE) - if(${P} STREQUAL "Check" AND CHECK_FOUND) - set(found TRUE) - elseif(${P} STREQUAL "Googletest" AND TARGET gtest) - set(found TRUE) - elseif(${P} STREQUAL "RapidCheck" AND TARGET rapidcheck) - set(found TRUE) - elseif(${P} STREQUAL "GFlags" AND TARGET gflags) - set(found TRUE) - endif() - if(NOT found) - message(STATUS "Disable tests because dependency ${P} was not found") - set(disable_tests ON) - endif() - endforeach() + option(${x_PROJECT}_ENABLE_TEST_LIBS "Enable build of test libraries for ${x_PROJECT}" ${test_components_possible}) + if(${x_PROJECT}_ENABLE_TEST_LIBS) + if(test_components_possible) + set(${x_PROJECT}_BUILD_TESTS TRUE CACHE BOOL "Build test libraries for ${x_PROJECT}") + else() + message(WARNING "${x_PROJECT} test libraries are explicitly enabled but it isn't possible to build them") + endif() + else() + message(STATUS "${x_PROJECT} test libraries are DISABLED") endif() endif() - if(x_DOCS) - option(${x_PROJECT}_BUILD_DOCS "Enable build of documentation for ${x_PROJECT}" ON) + if(x_HAS_DOCS) + option(${x_PROJECT}_ENABLE_DOCS "Enable build of documentation for ${x_PROJECT}" ON) + set(${x_PROJECT}_BUILD_DOCS ${${x_PROJECT}_ENABLE_DOCS} CACHE BOOL "Build documentation for ${x_PROJECT}") if(NOT ${x_PROJECT}_BUILD_DOCS) message(STATUS "${x_PROJECT} documentation is DISABLED") endif() endif() if(x_EXAMPLES) - option(${x_PROJECT}_BUILD_EXAMPLES "Enable build of example code for ${x_PROJECT}" ON) + option(${x_PROJECT}_ENABLE_EXAMPLES "Enable build of example code for ${x_PROJECT}" ON) + set(${x_PROJECT}_BUILD_EXAMPLES ${${x_PROJECT}_ENABLE_EXAMPLES} CACHE BOOL "Build examples for ${x_PROJECT}") if(NOT ${x_PROJECT}_BUILD_EXAMPLES) message(STATUS "${x_PROJECT} examples are DISABLED") endif() endif() foreach(feat "TESTS" "TEST_LIBS" "DOCS" "EXAMPLES") - if(DEFINED ${x_PROJECT}_BUILD_${feat} AND NOT x_${feat}) - message(WARNING "${x_PROJECT}_BUILD_${feat} is set but the package does not support it") + if(DEFINED ${x_PROJECT}_ENABLE_${feat} AND NOT x_HAS_${feat}) + message(WARNING "${x_PROJECT}_ENABLE_${feat} is set but the package does not support it") endif() endforeach() From 43c93c74580be6150f063ab38db4f43a15f5046f Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 15 May 2019 15:35:20 +1000 Subject: [PATCH 25/63] Correct build_test_libs name --- SwiftCmakeOptions.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index 3954313..c498b75 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -78,7 +78,7 @@ function(swift_create_project_options) option(${x_PROJECT}_ENABLE_TEST_LIBS "Enable build of test libraries for ${x_PROJECT}" ${test_components_possible}) if(${x_PROJECT}_ENABLE_TEST_LIBS) if(test_components_possible) - set(${x_PROJECT}_BUILD_TESTS TRUE CACHE BOOL "Build test libraries for ${x_PROJECT}") + set(${x_PROJECT}_BUILD_TEST_LIBS TRUE CACHE BOOL "Build test libraries for ${x_PROJECT}") else() message(WARNING "${x_PROJECT} test libraries are explicitly enabled but it isn't possible to build them") endif() From ba7bebf7557dca43270fac608747b8f2e9464416 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 15 May 2019 16:14:00 +1000 Subject: [PATCH 26/63] Only check test dependencies if we are actually building something --- SwiftCmakeOptions.cmake | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index c498b75..c41c0b6 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -53,37 +53,37 @@ function(swift_create_project_options) endif() endif() - if(x_HAS_TESTS) - if(NOT x_test_packages_verified) - verify_test_dependencies(TEST_PACKAGES ${x_TEST_PACKAGES}) - endif() + set(build_tests FALSE) + set(build_test_libs FALSE) + if(x_HAS_TESTS) option(${x_PROJECT}_ENABLE_TESTS "Enable build of unit tests for ${x_PROJECT}" ${test_components_possible}) if(${x_PROJECT}_ENABLE_TESTS) if(test_components_possible) - set(${x_PROJECT}_BUILD_TESTS TRUE CACHE BOOL "Build unit tests for ${x_PROJECT}") - else() - message(WARNING "${x_PROJECT} unit tests explicitly enabled but it isn't possible to build them") + set(build_tests TRUE) endif() - else() - message(STATUS "${x_PROJECT} unit tests are DISABLED") endif() endif() if(x_HAS_TEST_LIBS) - if(NOT x_test_packages_verified) - verify_test_dependencies(TEST_PACKAGES ${x_TEST_PACKAGES}) - endif() - option(${x_PROJECT}_ENABLE_TEST_LIBS "Enable build of test libraries for ${x_PROJECT}" ${test_components_possible}) if(${x_PROJECT}_ENABLE_TEST_LIBS) if(test_components_possible) - set(${x_PROJECT}_BUILD_TEST_LIBS TRUE CACHE BOOL "Build test libraries for ${x_PROJECT}") - else() - message(WARNING "${x_PROJECT} test libraries are explicitly enabled but it isn't possible to build them") + set(build_test_libs TRUE) endif() - else() - message(STATUS "${x_PROJECT} test libraries are DISABLED") + endif() + endif() + + if(build_tests OR build_test_libs) + if(NOT x_test_packages_verified) + verify_test_dependencies(TEST_PACKAGES ${x_TEST_PACKAGES}) + endif() + + if(x_HAS_TESTS) + set(${x_PROJECT}_BUILD_TESTS ${test_components_possible} CACHE BOOL "Build unit tests for ${x_PROJECT}") + endif() + if(x_HAS_TEST_LIBS) + set(${x_PROJECT}_BUILD_TEST_LIBS ${test_components_possible} CACHE BOOL "Build test libraries for ${x_PROJECT}") endif() endif() From b6c0025dd312b3c4a6148ec5febde0e6c5d77ac8 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 15 May 2019 17:21:39 +1000 Subject: [PATCH 27/63] Enable correct test components --- SwiftCmakeOptions.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index c41c0b6..af6bc38 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -79,10 +79,10 @@ function(swift_create_project_options) verify_test_dependencies(TEST_PACKAGES ${x_TEST_PACKAGES}) endif() - if(x_HAS_TESTS) + if(build_tests) set(${x_PROJECT}_BUILD_TESTS ${test_components_possible} CACHE BOOL "Build unit tests for ${x_PROJECT}") endif() - if(x_HAS_TEST_LIBS) + if(build_test_libs) set(${x_PROJECT}_BUILD_TEST_LIBS ${test_components_possible} CACHE BOOL "Build test libraries for ${x_PROJECT}") endif() endif() From 89136bb09fd5c1b0571d03abacb502aed01eeba6 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 15 May 2019 17:49:02 +1000 Subject: [PATCH 28/63] Display message when test components are disabled --- SwiftCmakeOptions.cmake | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index af6bc38..744f6f0 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -79,11 +79,25 @@ function(swift_create_project_options) verify_test_dependencies(TEST_PACKAGES ${x_TEST_PACKAGES}) endif() + if(NOT test_components_possible) + set(build_tests OFF) + set(build_test_libraries OFF) + endif() + endif() + + if(x_HAS_TESTS) if(build_tests) - set(${x_PROJECT}_BUILD_TESTS ${test_components_possible} CACHE BOOL "Build unit tests for ${x_PROJECT}") + set(${x_PROJECT}_BUILD_TESTS TRUE CACHE BOOL "Build unit tests for ${x_PROJECT}") + else() + message(STATUS "${x_PROJECT} unit tests are DISABLED") endif() + endif() + + if(x_HAS_TEST_LIBS) if(build_test_libs) - set(${x_PROJECT}_BUILD_TEST_LIBS ${test_components_possible} CACHE BOOL "Build test libraries for ${x_PROJECT}") + set(${x_PROJECT}_BUILD_TEST_LIBS TRUE CACHE BOOL "Build test libraries for ${x_PROJECT}") + else() + message(STATUS "${x_PROJECT} test libraries are DISABLED") endif() endif() From b8b889f04da11dcc75c81bfb880bdb5f4177b68e Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Fri, 17 May 2019 12:42:42 +1000 Subject: [PATCH 29/63] Disable test libs when deps not available --- SwiftCmakeOptions.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index 744f6f0..ffa6a3e 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -81,7 +81,7 @@ function(swift_create_project_options) if(NOT test_components_possible) set(build_tests OFF) - set(build_test_libraries OFF) + set(build_test_libs OFF) endif() endif() From de02449497fb1bdb9520354caebe87028a2c92ae Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Fri, 17 May 2019 16:12:47 +1000 Subject: [PATCH 30/63] Add more test package handlers --- SwiftCmakeOptions.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index ffa6a3e..ff17e91 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -14,6 +14,12 @@ function(verify_test_dependencies) set(found TRUE) elseif(${P} STREQUAL "GFlags" AND TARGET gflags) set(found TRUE) + elseif(${P} STREQUAL "Json" AND TARGET nlohmann_json) + set(found TRUE) + elseif(${P} STREQUAL "Yaml-Cpp" AND TARGET yaml-cpp) + set(found TRUE) + elseif(${P} STREQUAL "FastCSV" AND TARGET fast-csv) + set(found TRUE) endif() if(NOT found) message(STATUS "Disable tests because dependency ${P} was not found") From 582daa9ad38a6a029c592189d6cc5d119892bb4d Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 21 May 2019 13:36:50 +1000 Subject: [PATCH 31/63] Add some documentation headers --- GenericFindDependency.cmake | 53 +++++++++++++++++ SwiftCmakeOptions.cmake | 111 ++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) diff --git a/GenericFindDependency.cmake b/GenericFindDependency.cmake index ff03e81..b7fe5fd 100644 --- a/GenericFindDependency.cmake +++ b/GenericFindDependency.cmake @@ -1,3 +1,56 @@ +# +# A generic cmake function to search for a dependency from several places and +# include in the build system as appropriate +# +# Dependencies can be picked up either from bundled source code, usually a git +# submodule located in the 'third_party' directory, or from libraries installed +# in the host system or cross compiling sysroot. +# +# By default dependencies are first sought in bundled source code, and if not +# found from the system libraries. This default behaviour can be controlled by +# several options +# +# Exclude - can be used to disable searching in a particular location. Valid +# arguments are 'source' and 'system' +# Prefer - used to override the default search location. Valid arguments are +# 'source' and 'system'. If not specified defaults to 'source' +# +# Similar options can be specified on the command line as well. +# SWIFT_PREFERRED_DEPENDENCY_SOURCE takes the same arguments as above but +# will apply globally across the entire build tree at configure time. For example +# +# cmake -DSWIFT_PREFERRED_DEPENDENCY_SOURCE=system +# +# will try to use depenedencies from the system libraries rather than bundled +# source code. +# +# If the dependency is picked up from the system libraries this function will +# create an interface target which can be used to link in to any other target. +# +# The options "SystemHeaderFile" and "SystemLibNames" will be passed verbatim +# to the cmake functions find_header() and find_library() to search all the +# correct system locations. +# +# When using bundled source code the function will search several default locations +# under '${CMAKE_CURRENT_SOURCE_DIR}/third_party' based on the package and target +# names. The search location can be controlled by the "SourcePrefix" and # "SourceSubDir" +# options +# +# The target name can be controlled by the option "TargetName". When using +# bundled source code this is used to verify the target was created properly +# after calling add_subdirectory +# +# The option REQUIRED can be passed which will cause this function to fail +# if the dependency was not found for any reason. +# +# Example: FindGoogletest.cmake +# +# GenericFindDependency( +# TargetName gtest +# SourceDir "googletest" +# ) +# + function(search_dependency_source) set(argOptions "") set(argSingleArguments "TargetName") diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index ff17e91..2c83448 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -1,3 +1,114 @@ +# Standard options for Swift cmake based project +# +# This module sets up cmake options for whatever features a project has. +# Supports the following features: +# +# - Tests +# - Test libraries for use by other projects +# - Documentation +# - Examples +# +# CMake options are set up with the names +# - {project_name}_ENABLE_{feature} +# +# For example: +# - libsbp_ENABLE_TESTS +# - albatross_ENABLE_EXAMPLES +# +# Options are enabled by default but can be set on the command line at +# configure time, eg +# +# cmake -Dlibsbp_ENABLE_TESTS=OFF +# +# They can also be disabled in CMakeLists.txt in a superproject, eg. +# +# ... +# option(libsbp_ENABLE_TESTS "" OFF) +# find_package(libsbp) +# ... +# +# Usage: +# Import this module and call the function swift_create_project_options +# specifying what features are available in the package. eg +# +# project(libsbp) +# include(SwiftCmakeOptions) +# swift_create_project_options(HAS_TESTS HAS_DOCS) +# +# Test components. +# The TEST and TEST_LIBS features have some extra processing. They will +# be automatically disabled when cross compiling, regardless of whether +# they are explicitly enabled or not. This behaviour can be disabled +# by passing the option SKIP_CROSS_COMPILING_CHECK. For example +# +# swift_create_project_options(HAS_TESTS SKIP_CROSS_COMPILING_CHECK) +# +# will enable unit tests and test libraries even when cross compiling. +# +# Conversely, the option DISABLE_TEST_COMPONENTS can be used to force +# unit tests and test libraries to always be disabled, ignore any user +# preference. For example +# +# swift_create_project_options(HAS_TESTS DISABLE_TEST_COMPONENTS TRUE) +# +# will disable unit tests and test libraries even if the user has +# requested them. This is useful so a project can disable test components +# based on other conditions that this module is not aware of, such as +# when using a particular compiler. The following example will always +# disable test components when using the Visual Studio compiler +# +# set(disable_tests FALSE) +# if(MSVC) +# set(disable_tests TRUE) +# endif() +# swift_create_project_options(HAS_TESTS DISABLE_TEST_COMPONENTS ${disable_tests}) +# +# A list of dependencies for test components can be specified using the +# TEST_PACKAGES option. Pass a list of packages which will be searched for +# using the find_package() cmake function. If any of the packages is not +# found the test components will be automatically disabled +# +# swift_create_project_options(HAS_TESTS TEST_PACKAGES "Googletest" "RapidCheck") +# +# The following test packages are currently supported: +# +# - Googletest (targets gtest etc) +# - RapidCheck +# - GFlags +# - Json +# - Yaml-Cpp +# - FastCSV +# +# Finally, this function will use the current project name as a prefix +# to all options and output variables. This can be overridden by +# passing the PROJECT option +# +# swift_create_project_options(PROJECT test_project HAS_TESTS) +# +# will create an option called test_project_ENABLE_TESTS +# +# After processing this function sets several cache variables which can +# be used elsewhere to determine which targets to compile. The output +# cache variable name is in the form {project}_BUILD_{feature}. eg +# +# libsbp_BUILD_TESTS +# albatross_BUILD_EXAMPLES +# +# This can be used in CMakeLists.txt to selective compile targets eg. +# +# if(libsbp_BUILD_TESTS) +# add_executable(libsbp-test ) +# endif() +# +# or include subdirectories +# +# if(albatross_BUILD_EXAMPLES) +# add_subdirectory(examples) +# endif() +# +# or any other valid cmake construct. +# + function(verify_test_dependencies) cmake_parse_arguments(x "" "" "TEST_PACKAGES" ${ARGN}) From f90a8b525a4b3adea6755d7618ddb21a7943eae8 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 22 May 2019 08:06:18 +1000 Subject: [PATCH 32/63] Correct has examples test --- SwiftCmakeOptions.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index 2c83448..b6832f5 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -226,7 +226,7 @@ function(swift_create_project_options) endif() endif() - if(x_EXAMPLES) + if(x_HAS_EXAMPLES) option(${x_PROJECT}_ENABLE_EXAMPLES "Enable build of example code for ${x_PROJECT}" ON) set(${x_PROJECT}_BUILD_EXAMPLES ${${x_PROJECT}_ENABLE_EXAMPLES} CACHE BOOL "Build examples for ${x_PROJECT}") if(NOT ${x_PROJECT}_BUILD_EXAMPLES) From 795e726b69ea91bafb18cf99a59a3ff729b089c3 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 22 May 2019 11:45:49 +1000 Subject: [PATCH 33/63] Generalise system includes --- FindFastCSV.cmake | 11 +---------- FindGFlags.cmake | 14 +------------- FindGoogletest.cmake | 11 +---------- FindJson.cmake | 10 +--------- FindOptional.cmake | 11 +---------- FindRapidCheck.cmake | 3 ++- FindYaml-Cpp.cmake | 11 +---------- GenericFindDependency.cmake | 33 ++++++++++++++++++++++++++------- 8 files changed, 34 insertions(+), 70 deletions(-) diff --git a/FindFastCSV.cmake b/FindFastCSV.cmake index 5f2b06c..d9589c3 100644 --- a/FindFastCSV.cmake +++ b/FindFastCSV.cmake @@ -2,14 +2,5 @@ include("GenericFindDependency") GenericFindDependency( TargetName "fast-csv" SourceDir "fast-cpp-csv-parser" + SYSTEM_INCLUDES ) - -if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) - # Change all of fast-csv's include directories to be system includes, to avoid - # compiler errors - get_target_property(fast-csv_include_directories fast-csv INTERFACE_INCLUDE_DIRECTORIES) - if(fast-csv_include_directories) - set_target_properties(fast-csv PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") - target_include_directories(fast-csv SYSTEM INTERFACE ${fast-csv_include_directories}) - endif() -endif() diff --git a/FindGFlags.cmake b/FindGFlags.cmake index 970dad8..296bbbc 100644 --- a/FindGFlags.cmake +++ b/FindGFlags.cmake @@ -2,17 +2,5 @@ include("GenericFindDependency") GenericFindDependency( TargetName gflags SourceDir "googleflags" + SYSTEM_INCLUDES ) - -if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) - # Change all of GoogleFlags's include directories to be system includes, to avoid - # compiler errors - get_target_property(_aliased gflags ALIASED_TARGET) - if(_aliased) - get_target_property(gflags_include_directories ${_aliased} INTERFACE_INCLUDE_DIRECTORIES) - if(gflags_include_directories) - set_target_properties(${_aliased} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") - target_include_directories(${_aliased} SYSTEM INTERFACE ${gflags_include_directories}) - endif() - endif() -endif() diff --git a/FindGoogletest.cmake b/FindGoogletest.cmake index 064acf9..312805f 100644 --- a/FindGoogletest.cmake +++ b/FindGoogletest.cmake @@ -2,14 +2,5 @@ include("GenericFindDependency") GenericFindDependency( TargetName gtest SourceDir "googletest" + SYSTEM_INCLUDES ) - -if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) - # Change all of GoogleTest's include directories to be system includes, to avoid - # compiler errors - get_target_property(gtest_include_directories gtest INTERFACE_INCLUDE_DIRECTORIES) - if(gtest_include_directories) - set_target_properties(gtest PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") - target_include_directories(gtest SYSTEM INTERFACE ${gtest_include_directories}) - endif() -endif() diff --git a/FindJson.cmake b/FindJson.cmake index 98851fd..d1e966c 100644 --- a/FindJson.cmake +++ b/FindJson.cmake @@ -2,14 +2,6 @@ include("GenericFindDependency") GenericFindDependency( TargetName "nlohmann_json" SourceDir "json" + SYSTEM_INCLUDES ) -if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) - # Change all of Json's include directories to be system includes, to avoid - # compiler errors - get_target_property(json_include_directories nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) - if(json_include_directories) - set_target_properties(nlohmann_json PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") - target_include_directories(nlohmann_json SYSTEM INTERFACE ${json_include_directories}) - endif() -endif() diff --git a/FindOptional.cmake b/FindOptional.cmake index cb7c692..7275ccd 100644 --- a/FindOptional.cmake +++ b/FindOptional.cmake @@ -1,14 +1,5 @@ include("GenericFindDependency") GenericFindDependency( TargetName optional + SYSTEM_INCLUDES ) - -if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) - # Change all of Optional's include directories to be system includes, to avoid - # compiler errors - get_target_property(optional_include_directories optional INTERFACE_INCLUDE_DIRECTORIES) - if(optional_include_directories) - set_target_properties(optional PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") - target_include_directories(optional SYSTEM INTERFACE ${optional_include_directories}) - endif() -endif() diff --git a/FindRapidCheck.cmake b/FindRapidCheck.cmake index 893bf73..c46bef2 100644 --- a/FindRapidCheck.cmake +++ b/FindRapidCheck.cmake @@ -8,7 +8,8 @@ GenericFindDependency( ) # Change all of rapidcheck's include directories to be system includes, to avoid -# compiler errors +# compiler errors. The generalised version in GenericFindDependency isn't suitable +# in this instance. get_target_property(rapidcheck_interface_includes rapidcheck INTERFACE_INCLUDE_DIRECTORIES) if(rapidcheck_interface_includes) set_target_properties(rapidcheck PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") diff --git a/FindYaml-Cpp.cmake b/FindYaml-Cpp.cmake index 4f13954..51f8d94 100644 --- a/FindYaml-Cpp.cmake +++ b/FindYaml-Cpp.cmake @@ -3,14 +3,5 @@ option(YAML_CPP_BUILD_TOOLS "Enable testing and parse tools" OFF) option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" OFF) GenericFindDependency( TargetName "yaml-cpp" + SYSTEM_INCLUDES ) - -if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) - # Change all of Yaml-Cpp's include directories to be system includes, to avoid - # compiler errors - get_target_property(yaml-cpp_include_directories yaml-cpp INTERFACE_INCLUDE_DIRECTORIES) - if(yaml-cpp_include_directories) - set_target_properties(yaml-cpp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") - target_include_directories(yaml-cpp SYSTEM INTERFACE ${yaml-cpp_include_directories}) - endif() -endif() diff --git a/GenericFindDependency.cmake b/GenericFindDependency.cmake index b7fe5fd..f41932e 100644 --- a/GenericFindDependency.cmake +++ b/GenericFindDependency.cmake @@ -33,13 +33,18 @@ # # When using bundled source code the function will search several default locations # under '${CMAKE_CURRENT_SOURCE_DIR}/third_party' based on the package and target -# names. The search location can be controlled by the "SourcePrefix" and # "SourceSubDir" +# names. The search location can be controlled by the "SourcePrefix" and "SourceSubDir" # options # # The target name can be controlled by the option "TargetName". When using # bundled source code this is used to verify the target was created properly # after calling add_subdirectory # +# Passing the option SYSTEM_INCLUDES will rewrite the target include directories +# so that they are marked as system headers. This will usually be passed to +# the compiler as an command line option as decided by cmake. Be careful with +# this option, it will supress warning which might otherwise be helpful. +# # The option REQUIRED can be passed which will cause this function to fail # if the dependency was not found for any reason. # @@ -111,7 +116,7 @@ function(search_dependency_system) endfunction() function(GenericFindDependency) - set(argOptions "REQUIRED") + set(argOptions "REQUIRED" "SYSTEM_INCLUDES") set(argSingleArguments "TargetName" "Prefer" "SourceDir" "SourcePrefix" "SourceSubdir" "SystemHeaderFile" "SystemLibNames") set(argMultiArguments "Exclude") @@ -195,7 +200,7 @@ function(GenericFindDependency) if(TARGET ${x_TargetName}) message(STATUS "Using dependency ${x_TargetName} from bundled source code") - return() + break() endif() else() if(NOT x_SystemHeaderFile) @@ -212,15 +217,29 @@ function(GenericFindDependency) if(TARGET ${x_TargetName}) message(STATUS "Using dependency ${x_TargetName} from system") - return() + break() endif() endif() endforeach() - if(x_REQUIRED OR ${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) - message(FATAL_ERROR "Could not find REQUIRED dependency ${x_TargetName} in any available location") + if(TARGET ${x_TargetName}) + if(x_SYSTEM_INCLUDES) + if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) + get_target_property(directories ${x_TargetName} INTERFACE_INCLUDE_DIRECTORIES) + if(directories) + message(STATUS "Marking ${x_TargetName} include directories as system") + set_target_properties(${x_TargetName} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(${x_TargetName} SYSTEM INTERFACE ${directories}) + endif() + endif() + endif() else() - message(WARNING "Could not find dependency ${x_TargetName} in any available location") + # Target not found in any location + if(x_REQUIRED OR ${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) + message(FATAL_ERROR "Could not find REQUIRED dependency ${x_TargetName} in any available location") + else() + message(WARNING "Could not find dependency ${x_TargetName} in any available location") + endif() endif() endfunction() From ed6f8ddcb1dd1588f1a6805a89b8de032ad234c8 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 22 May 2019 11:50:55 +1000 Subject: [PATCH 34/63] Don't use generalised version for gflags --- FindGFlags.cmake | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/FindGFlags.cmake b/FindGFlags.cmake index 296bbbc..8ab8819 100644 --- a/FindGFlags.cmake +++ b/FindGFlags.cmake @@ -2,5 +2,18 @@ include("GenericFindDependency") GenericFindDependency( TargetName gflags SourceDir "googleflags" - SYSTEM_INCLUDES ) + +if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) + # Change all of GoogleFlags's include directories to be system includes, to avoid + # compiler errors. The generalised version of this in GenericFindDependency won'y + # work here because we are dealing with an aliased target + get_target_property(_aliased gflags ALIASED_TARGET) + if(_aliased) + get_target_property(gflags_include_directories ${_aliased} INTERFACE_INCLUDE_DIRECTORIES) + if(gflags_include_directories) + set_target_properties(${_aliased} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(${_aliased} SYSTEM INTERFACE ${gflags_include_directories}) + endif() + endif() +endif() From f1a680475418846d030ac4c1f04ef0dad1b4a5d6 Mon Sep 17 00:00:00 2001 From: Matt Woodward <46688854+woodfell@users.noreply.github.com> Date: Thu, 23 May 2019 08:48:08 +1000 Subject: [PATCH 35/63] libsettings cmake file is at the top level Co-Authored-By: Ben Altieri --- FindSettings.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/FindSettings.cmake b/FindSettings.cmake index b3efe0f..f13c8e4 100644 --- a/FindSettings.cmake +++ b/FindSettings.cmake @@ -1,5 +1,4 @@ include("GenericFindDependency") GenericFindDependency( TargetName settings - SourceDir "c" ) From 1401abeeade1c2d96e96484cc62f16e0755c1ef8 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Thu, 23 May 2019 11:21:43 +1000 Subject: [PATCH 36/63] Tidy up GenericFindDependency, add comments --- GenericFindDependency.cmake | 159 ++++++++++++++++++++++++++---------- 1 file changed, 114 insertions(+), 45 deletions(-) diff --git a/GenericFindDependency.cmake b/GenericFindDependency.cmake index f41932e..fa367d8 100644 --- a/GenericFindDependency.cmake +++ b/GenericFindDependency.cmake @@ -33,8 +33,7 @@ # # When using bundled source code the function will search several default locations # under '${CMAKE_CURRENT_SOURCE_DIR}/third_party' based on the package and target -# names. The search location can be controlled by the "SourcePrefix" and "SourceSubDir" -# options +# names. The search location can be controlled by the "SourceDir" parameter # # The target name can be controlled by the option "TargetName". When using # bundled source code this is used to verify the target was created properly @@ -53,6 +52,7 @@ # GenericFindDependency( # TargetName gtest # SourceDir "googletest" +# SYSTEM_INCLUDES # ) # @@ -115,22 +115,27 @@ function(search_dependency_system) message(STATUS "Found ${x_TargetName} from the system at ${x_${x_TargetName}_Library}") endfunction() -function(GenericFindDependency) - set(argOptions "REQUIRED" "SYSTEM_INCLUDES") - set(argSingleArguments "TargetName" "Prefer" "SourceDir" "SourcePrefix" "SourceSubdir" "SystemHeaderFile" "SystemLibNames") - set(argMultiArguments "Exclude") - - cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) - - if(x_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unexpected unparsed arguments ${x_UNPARSED_ARGUMENTS}") - endif() - - if(TARGET ${x_TargetName}) - # Target already defined, no need to do anything more - return() - endif() - +# To be called from GenericFindDependency +# +# Create the variable which will contain a list of possible search locations sorted +# by order of preference +# +# This is a macro so all input and output variable exist in the context of the caller +# +# This macro will return(), ie cause the caller to return, if there are no available locations. +# It will raise a fatal error if unknown values are specified for any of the input parameters. +# +# Inputs: +# - x_Prefer - Parameter to GenericFindDependency, preferred location as defined by the project +# - SWIFT_PREFERRED_DEPENDENCY_SOURCE - Global user preference, defined on the command line +# - x_Exclude - List of sources to exclude from consideration +# - SWIFT_EXCLUDE_DEPENDENCY_SOURCE - Global user exclude list, defined on the command line +# +# Outputs: +# - x_Locations - List of locations to search for the dependency +# - x_NumLocations - Length of x_Locations +# +macro(setup_search_locations) if(NOT x_Prefer) if (SWIFT_PREFERRED_DEPENDENCY_SOURCE) set(x_Prefer "${SWIFT_PREFERRED_DEPENDENCY_SOURCE}") @@ -168,53 +173,121 @@ function(GenericFindDependency) return() endif() endif() +endmacro() + +# +# To be called from GenericFindDependency +# +# Creates a list of paths to be searched for source code for the dependency +# +# This is a macro, all input and output variables exist in the context of the caller +# +# If a source dir path is not explicitly specified this macro will generate a list of +# probable locations for the dependency source code. It outputs a list of absolute +# paths to be searched +# +# Inputs: +# - x_SourceDir - Parameter to GenericFindDependency, appened to the generated search paths +# +# Outputs: +# - x_SourceSearchPaths - A list of paths to be searched for source code +# +macro(create_source_search_paths) + # set defaults + set(x_SourceSearchPaths "") + if(NOT x_SourceDir) + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_TargetName}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib${x_TargetName}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_TargetName}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/lib${x_TargetName}") + else() + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_TargetName}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib${x_TargetName}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_TargetName}/${x_SourceDir}") + list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/lib${x_TargetName}/${x_SourceDir}") + endif() +endmacro() + +# +# Helper function to mark the specified target's include directories as system. This is +# then passed to the compiler which will surpress warnings generated from any header file +# included by this path. Use with care +# +# Should only be called from GenericFindDependency +# +function(mark_target_as_system_includes TGT) + get_target_property(directories ${x_TargetName} INTERFACE_INCLUDE_DIRECTORIES) + if(directories) + message(STATUS "Marking ${x_TargetName} include directories as system") + set_target_properties(${x_TargetName} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(${x_TargetName} SYSTEM INTERFACE ${directories}) + endif() +endfunction() + +function(GenericFindDependency) + set(argOptions "REQUIRED" "SYSTEM_INCLUDES") + set(argSingleArguments "TargetName" "Prefer" "SourceDir" "SystemHeaderFile" "SystemLibNames") + set(argMultiArguments "Exclude") + + cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) + + if(x_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unexpected unparsed arguments ${x_UNPARSED_ARGUMENTS}") + endif() + + if(TARGET ${x_TargetName}) + # Target already defined, no need to do anything more + return() + endif() + + # Generate a list of locations to search for the dependency in order of preference + setup_search_locations() foreach(LOCATION ${x_Locations}) if (${LOCATION} STREQUAL "source") - # set defaults - set(x_SourceSearchPaths "") - if(NOT x_SourceDir) - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_TargetName}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib${x_TargetName}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_TargetName}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/lib${x_TargetName}") - else() - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_TargetName}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib${x_TargetName}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_TargetName}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/lib${x_TargetName}/${x_SourceDir}") - endif() + # Try looking for bundled source code + + # Set up search locations for source code + create_source_search_paths() + # Look for a suitably named directory which contains a CMakeLists.txt, try to add it search_dependency_source( TargetName "${x_TargetName}" SourceSearchPaths "${x_SourceSearchPaths}" ) + # If the expected target was created we have succeeded if(TARGET ${x_TargetName}) message(STATUS "Using dependency ${x_TargetName} from bundled source code") break() endif() else() + # Try looking for a header file and library in the system paths + if(NOT x_SystemHeaderFile) + # Use a sensible header file name if not explicitly set set(x_SystemHeaderFile "lib${x_TargetName}/${x_TargetName}.h") endif() + # Look for common library naming patterns set(x_SystemLibNames "${x_SystemLibName}" "${x_TargetName}" "lib${x_TargetName}") + # Search either system libraries or sysroot, this is handled by cmake itself search_dependency_system( TargetName "${x_TargetName}" SystemHeaderFile "${x_SystemHeaderFile}" SystemLibNames "${x_SystemLibNames}" ) + # If the target was found we have succeeded if(TARGET ${x_TargetName}) message(STATUS "Using dependency ${x_TargetName} from system") break() @@ -222,15 +295,11 @@ function(GenericFindDependency) endif() endforeach() + # Final validation that the target was properly created from some source if(TARGET ${x_TargetName}) if(x_SYSTEM_INCLUDES) if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) - get_target_property(directories ${x_TargetName} INTERFACE_INCLUDE_DIRECTORIES) - if(directories) - message(STATUS "Marking ${x_TargetName} include directories as system") - set_target_properties(${x_TargetName} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") - target_include_directories(${x_TargetName} SYSTEM INTERFACE ${directories}) - endif() + mark_target_as_system_includes(${x_TargetName}) endif() endif() else() From 9f13b0ec52ef5398549d2480fbfb637acec48b63 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Thu, 23 May 2019 11:27:50 +1000 Subject: [PATCH 37/63] Change function/macro parameters to use upper case --- FindFastCSV.cmake | 4 +- FindGFlags.cmake | 6 +- FindGnss-converters.cmake | 4 +- FindGoogletest.cmake | 4 +- FindJson.cmake | 4 +- FindOptional.cmake | 2 +- FindOrion-Proto.cmake | 4 +- FindProtobuf.cmake | 4 +- FindRapidCheck.cmake | 2 +- FindRtcm.cmake | 4 +- FindSbp.cmake | 4 +- FindSettings.cmake | 2 +- FindStarling.cmake | 2 +- FindSwiftnav.cmake | 2 +- FindYaml-Cpp.cmake | 2 +- GenericFindDependency.cmake | 166 ++++++++++++++++++------------------ 16 files changed, 108 insertions(+), 108 deletions(-) diff --git a/FindFastCSV.cmake b/FindFastCSV.cmake index d9589c3..8816f5d 100644 --- a/FindFastCSV.cmake +++ b/FindFastCSV.cmake @@ -1,6 +1,6 @@ include("GenericFindDependency") GenericFindDependency( - TargetName "fast-csv" - SourceDir "fast-cpp-csv-parser" + TARGET "fast-csv" + SOURCE_DIR "fast-cpp-csv-parser" SYSTEM_INCLUDES ) diff --git a/FindGFlags.cmake b/FindGFlags.cmake index 8ab8819..37f420f 100644 --- a/FindGFlags.cmake +++ b/FindGFlags.cmake @@ -1,12 +1,12 @@ include("GenericFindDependency") GenericFindDependency( - TargetName gflags - SourceDir "googleflags" + TARGET gflags + SOURCE_DIR "googleflags" ) if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) # Change all of GoogleFlags's include directories to be system includes, to avoid - # compiler errors. The generalised version of this in GenericFindDependency won'y + # compiler errors. The generalised version of this in GenericFindDependency won't # work here because we are dealing with an aliased target get_target_property(_aliased gflags ALIASED_TARGET) if(_aliased) diff --git a/FindGnss-converters.cmake b/FindGnss-converters.cmake index c41d62f..a45aa1b 100644 --- a/FindGnss-converters.cmake +++ b/FindGnss-converters.cmake @@ -1,5 +1,5 @@ include("GenericFindDependency") GenericFindDependency( - TargetName gnss_converters - SourceDir "gnss-converters/c" + TARGET gnss_converters + SOURCE_DIR "gnss-converters/c" ) diff --git a/FindGoogletest.cmake b/FindGoogletest.cmake index 312805f..01668e8 100644 --- a/FindGoogletest.cmake +++ b/FindGoogletest.cmake @@ -1,6 +1,6 @@ include("GenericFindDependency") GenericFindDependency( - TargetName gtest - SourceDir "googletest" + TARGET gtest + SOURCE_DIR "googletest" SYSTEM_INCLUDES ) diff --git a/FindJson.cmake b/FindJson.cmake index d1e966c..9e97715 100644 --- a/FindJson.cmake +++ b/FindJson.cmake @@ -1,7 +1,7 @@ include("GenericFindDependency") GenericFindDependency( - TargetName "nlohmann_json" - SourceDir "json" + TARGET "nlohmann_json" + SOURCE_DIR "json" SYSTEM_INCLUDES ) diff --git a/FindOptional.cmake b/FindOptional.cmake index 7275ccd..299d1f9 100644 --- a/FindOptional.cmake +++ b/FindOptional.cmake @@ -1,5 +1,5 @@ include("GenericFindDependency") GenericFindDependency( - TargetName optional + TARGET optional SYSTEM_INCLUDES ) diff --git a/FindOrion-Proto.cmake b/FindOrion-Proto.cmake index 3d4d4b6..277be74 100644 --- a/FindOrion-Proto.cmake +++ b/FindOrion-Proto.cmake @@ -1,5 +1,5 @@ include("GenericFindDependency") GenericFindDependency( - TargetName orion-proto - SourceDir "orion_proto" + TARGET orion-proto + SOURCE_DIR "orion_proto" ) diff --git a/FindProtobuf.cmake b/FindProtobuf.cmake index 362de09..4cdfc18 100644 --- a/FindProtobuf.cmake +++ b/FindProtobuf.cmake @@ -1,5 +1,5 @@ include("GenericFindDependency") GenericFindDependency( - TargetName "libprotobuf" - SourceDir "protobuf/cmake" + TARGET "libprotobuf" + SOURCE_DIR "protobuf/cmake" ) diff --git a/FindRapidCheck.cmake b/FindRapidCheck.cmake index c46bef2..6a81b37 100644 --- a/FindRapidCheck.cmake +++ b/FindRapidCheck.cmake @@ -4,7 +4,7 @@ include("GenericFindDependency") set(RC_ENABLE_GTEST ON CACHE BOOL "" FORCE) GenericFindDependency( - TargetName rapidcheck + TARGET rapidcheck ) # Change all of rapidcheck's include directories to be system includes, to avoid diff --git a/FindRtcm.cmake b/FindRtcm.cmake index 19bb658..3d5f43f 100644 --- a/FindRtcm.cmake +++ b/FindRtcm.cmake @@ -1,5 +1,5 @@ include("GenericFindDependency") GenericFindDependency( - TargetName rtcm - SourceDir "c" + TARGET rtcm + SOURCE_DIR "c" ) diff --git a/FindSbp.cmake b/FindSbp.cmake index 405e037..785ee63 100644 --- a/FindSbp.cmake +++ b/FindSbp.cmake @@ -1,5 +1,5 @@ include("GenericFindDependency") GenericFindDependency( - TargetName sbp - SourceDir "c" + TARGET sbp + SOURCE_DIR "c" ) diff --git a/FindSettings.cmake b/FindSettings.cmake index f13c8e4..5db14f6 100644 --- a/FindSettings.cmake +++ b/FindSettings.cmake @@ -1,4 +1,4 @@ include("GenericFindDependency") GenericFindDependency( - TargetName settings + TARGET settings ) diff --git a/FindStarling.cmake b/FindStarling.cmake index 31a5eb0..f9ab4be 100644 --- a/FindStarling.cmake +++ b/FindStarling.cmake @@ -1,4 +1,4 @@ include("GenericFindDependency") GenericFindDependency( - TargetName starling + TARGET starling ) diff --git a/FindSwiftnav.cmake b/FindSwiftnav.cmake index 6e74b57..ceea74b 100644 --- a/FindSwiftnav.cmake +++ b/FindSwiftnav.cmake @@ -1,4 +1,4 @@ include("GenericFindDependency") GenericFindDependency( - TargetName swiftnav + TARGET swiftnav ) diff --git a/FindYaml-Cpp.cmake b/FindYaml-Cpp.cmake index 51f8d94..593bb8e 100644 --- a/FindYaml-Cpp.cmake +++ b/FindYaml-Cpp.cmake @@ -2,6 +2,6 @@ include("GenericFindDependency") option(YAML_CPP_BUILD_TOOLS "Enable testing and parse tools" OFF) option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" OFF) GenericFindDependency( - TargetName "yaml-cpp" + TARGET "yaml-cpp" SYSTEM_INCLUDES ) diff --git a/GenericFindDependency.cmake b/GenericFindDependency.cmake index fa367d8..d82aa12 100644 --- a/GenericFindDependency.cmake +++ b/GenericFindDependency.cmake @@ -10,9 +10,9 @@ # found from the system libraries. This default behaviour can be controlled by # several options # -# Exclude - can be used to disable searching in a particular location. Valid +# EXCLUDE - can be used to disable searching in a particular location. Valid # arguments are 'source' and 'system' -# Prefer - used to override the default search location. Valid arguments are +# PREFER - used to override the default search location. Valid arguments are # 'source' and 'system'. If not specified defaults to 'source' # # Similar options can be specified on the command line as well. @@ -27,15 +27,15 @@ # If the dependency is picked up from the system libraries this function will # create an interface target which can be used to link in to any other target. # -# The options "SystemHeaderFile" and "SystemLibNames" will be passed verbatim +# The options "SYSTEM_HEADER_FILE" and "SYSTEM_LIB_NAMES" will be passed verbatim # to the cmake functions find_header() and find_library() to search all the # correct system locations. # # When using bundled source code the function will search several default locations # under '${CMAKE_CURRENT_SOURCE_DIR}/third_party' based on the package and target -# names. The search location can be controlled by the "SourceDir" parameter +# names. The search location can be controlled by the "SOURCE_DIR" parameter # -# The target name can be controlled by the option "TargetName". When using +# The target name can be controlled by the option "TARGET". When using # bundled source code this is used to verify the target was created properly # after calling add_subdirectory # @@ -50,16 +50,16 @@ # Example: FindGoogletest.cmake # # GenericFindDependency( -# TargetName gtest -# SourceDir "googletest" +# TARGET gtest +# SOURCE_DIR "googletest" # SYSTEM_INCLUDES # ) # function(search_dependency_source) set(argOptions "") - set(argSingleArguments "TargetName") - set(argMultiArguments "SourceSearchPaths") + set(argSingleArguments "TARGET") + set(argMultiArguments "SOURCE_SEARCH_PATHS") cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) @@ -67,31 +67,31 @@ function(search_dependency_source) message(FATAL_ERROR "Unexpected extra arguments in search_dependency_source: ${x_UNPARSED_ARGUMENTS}") endif() - foreach(P ${x_SourceSearchPaths}) + foreach(P ${x_SOURCE_SEARCH_PATHS}) if(EXISTS "${P}/CMakeLists.txt") - message(STATUS "Found ${x_TargetName} source code in ${P}") + message(STATUS "Found ${x_TARGET} source code in ${P}") add_subdirectory(${P}) - if(NOT TARGET ${x_TargetName}) - message(WARNING "Source code in ${P} did not declare target ${x_TargetName} as was expected") + if(NOT TARGET ${x_TARGET}) + message(WARNING "Source code in ${P} did not declare target ${x_TARGET} as was expected") endif() # This is very ugly, but required for some python modules, it will not last beyond this temporary solution if(EXISTS "${P}/include") - set(x_${x_TargetName}_IncludeDir "${P}/include" CACHE PATH "Path to ${x_TargetName} bundled source code header files") + set(x_${x_TARGET}_IncludeDir "${P}/include" CACHE PATH "Path to ${x_TARGET} bundled source code header files") endif() return() endif() endforeach() - message(STATUS "No ${x_TargetName} source available in search paths") + message(STATUS "No ${x_TARGET} source available in search paths") endfunction() function(search_dependency_system) set(argOptions "") - set(argSingleArguments "TargetName" "SystemHeaderFile") - set(argMultiArguments "SystemLibNames") + set(argSingleArguments "TARGET" "SYSTEM_HEADER_FILE") + set(argMultiArguments "SYSTEM_LIB_NAMES") cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) @@ -99,20 +99,20 @@ function(search_dependency_system) message(FATAL_ERROR "Unexpected extra arguments in search_dependency_system: ${x_UNPARSED_ARGUMENTS}") endif() - find_path(x_${x_TargetName}_IncludeDir ${x_SystemHeaderFile}) - find_library(x_${x_TargetName}_Library NAMES ${x_SystemLibNames}) + find_path(x_${x_TARGET}_IncludeDir ${x_SYSTEM_HEADER_FILE}) + find_library(x_${x_TARGET}_Library NAMES ${x_SYSTEM_LIB_NAMES}) - if(NOT x_${x_TargetName}_IncludeDir OR NOT x_${x_TargetName}_Library) - message(STATUS "Could not find ${x_TargetName} from any available sysroot path") + if(NOT x_${x_TARGET}_IncludeDir OR NOT x_${x_TARGET}_Library) + message(STATUS "Could not find ${x_TARGET} from any available sysroot path") return() endif() - add_library(${x_TargetName} UNKNOWN IMPORTED) - set_target_properties(${x_TargetName} PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${x_${x_TargetName}_IncludeDir}") - set_property(TARGET ${x_TargetName} APPEND PROPERTY - IMPORTED_LOCATION "${x_${x_TargetName}_Library}") - message(STATUS "Found ${x_TargetName} from the system at ${x_${x_TargetName}_Library}") + add_library(${x_TARGET} UNKNOWN IMPORTED) + set_target_properties(${x_TARGET} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${x_${x_TARGET}_IncludeDir}") + set_property(TARGET ${x_TARGET} APPEND PROPERTY + IMPORTED_LOCATION "${x_${x_TARGET}_Library}") + message(STATUS "Found ${x_TARGET} from the system at ${x_${x_TARGET}_Library}") endfunction() # To be called from GenericFindDependency @@ -126,9 +126,9 @@ endfunction() # It will raise a fatal error if unknown values are specified for any of the input parameters. # # Inputs: -# - x_Prefer - Parameter to GenericFindDependency, preferred location as defined by the project +# - x_PREFER - Parameter to GenericFindDependency, preferred location as defined by the project # - SWIFT_PREFERRED_DEPENDENCY_SOURCE - Global user preference, defined on the command line -# - x_Exclude - List of sources to exclude from consideration +# - x_EXCLUDE - List of sources to exclude from consideration # - SWIFT_EXCLUDE_DEPENDENCY_SOURCE - Global user exclude list, defined on the command line # # Outputs: @@ -136,24 +136,24 @@ endfunction() # - x_NumLocations - Length of x_Locations # macro(setup_search_locations) - if(NOT x_Prefer) + if(NOT x_PREFER) if (SWIFT_PREFERRED_DEPENDENCY_SOURCE) - set(x_Prefer "${SWIFT_PREFERRED_DEPENDENCY_SOURCE}") + set(x_PREFER "${SWIFT_PREFERRED_DEPENDENCY_SOURCE}") else() - set(x_Prefer "source") + set(x_PREFER "source") endif() endif() - if(${x_Prefer} STREQUAL "source") + if(${x_PREFER} STREQUAL "source") list(APPEND x_Locations "source" "system") - elseif(${x_Prefer} STREQUAL "system") + elseif(${x_PREFER} STREQUAL "system") list(APPEND x_Locations "system" "source") else() - message(FATAL_ERROR "Unknown value for dependency location prefer: ${x_Prefer}") + message(FATAL_ERROR "Unknown value for dependency location prefer: ${x_PREFER}") endif() - if(x_Exclude) - foreach(S ${x_Exclude}) + if(x_EXCLUDE) + foreach(S ${x_EXCLUDE}) list(REMOVE_ITEM x_Locations ${S}) endforeach() endif() @@ -167,9 +167,9 @@ macro(setup_search_locations) list(LENGTH x_Locations x_NumLocations) if (${x_NumLocations} EQUAL 0) if (x_REQUIRED) - message(FATAL_ERROR "Could not find dependency ${x_TargetName}, no locations available") + message(FATAL_ERROR "Could not find dependency ${x_TARGET}, no locations available") else() - message(WARNING "Could not find dependency ${x_TargetName}, no locations available") + message(WARNING "Could not find dependency ${x_TARGET}, no locations available") return() endif() endif() @@ -187,32 +187,32 @@ endmacro() # paths to be searched # # Inputs: -# - x_SourceDir - Parameter to GenericFindDependency, appened to the generated search paths +# - x_SOURCE_DIR - Parameter to GenericFindDependency, appened to the generated search paths # # Outputs: -# - x_SourceSearchPaths - A list of paths to be searched for source code +# - x_SOURCE_SEARCH_PATHS - A list of paths to be searched for source code # macro(create_source_search_paths) # set defaults - set(x_SourceSearchPaths "") - if(NOT x_SourceDir) - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_TargetName}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib${x_TargetName}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_TargetName}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/lib${x_TargetName}") + set(x_SOURCE_SEARCH_PATHS "") + if(NOT x_SOURCE_DIR) + list(APPEND x_SOURCE_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}") + list(APPEND x_SOURCE_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_TARGET}") + list(APPEND x_SOURCE_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib${x_TARGET}") + list(APPEND x_SOURCE_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}") + list(APPEND x_SOURCE_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/third_party/${x_TARGET}") + list(APPEND x_SOURCE_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/third_party/lib${x_TARGET}") else() - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_TargetName}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib${x_TargetName}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/${x_TargetName}/${x_SourceDir}") - list(APPEND x_SourceSearchPaths "${PROJECT_SOURCE_DIR}/third_party/lib${x_TargetName}/${x_SourceDir}") + list(APPEND x_SOURCE_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/${x_SOURCE_DIR}") + list(APPEND x_SOURCE_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_SOURCE_DIR}") + list(APPEND x_SOURCE_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/${x_SOURCE_DIR}") + list(APPEND x_SOURCE_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/third_party/${x_SOURCE_DIR}") + list(APPEND x_SOURCE_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}/${x_SOURCE_DIR}") + list(APPEND x_SOURCE_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/${x_TARGET}/${x_SOURCE_DIR}") + list(APPEND x_SOURCE_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/lib${x_TARGET}/${x_SOURCE_DIR}") + list(APPEND x_SOURCE_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/third_party/${CMAKE_FIND_PACKAGE_NAME}/${x_SOURCE_DIR}") + list(APPEND x_SOURCE_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/third_party/${x_TARGET}/${x_SOURCE_DIR}") + list(APPEND x_SOURCE_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/third_party/lib${x_TARGET}/${x_SOURCE_DIR}") endif() endmacro() @@ -223,19 +223,19 @@ endmacro() # # Should only be called from GenericFindDependency # -function(mark_target_as_system_includes TGT) - get_target_property(directories ${x_TargetName} INTERFACE_INCLUDE_DIRECTORIES) +function(mark_target_as_system_includes TARGET) + get_target_property(directories ${x_TARGET} INTERFACE_INCLUDE_DIRECTORIES) if(directories) - message(STATUS "Marking ${x_TargetName} include directories as system") - set_target_properties(${x_TargetName} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") - target_include_directories(${x_TargetName} SYSTEM INTERFACE ${directories}) + message(STATUS "Marking ${x_TARGET} include directories as system") + set_target_properties(${x_TARGET} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "") + target_include_directories(${x_TARGET} SYSTEM INTERFACE ${directories}) endif() endfunction() function(GenericFindDependency) set(argOptions "REQUIRED" "SYSTEM_INCLUDES") - set(argSingleArguments "TargetName" "Prefer" "SourceDir" "SystemHeaderFile" "SystemLibNames") - set(argMultiArguments "Exclude") + set(argSingleArguments "TARGET" "PREFER" "SOURCE_DIR" "SYSTEM_HEADER_FILE" "SYSTEM_LIB_NAMES") + set(argMultiArguments "EXCLUDE") cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) @@ -243,7 +243,7 @@ function(GenericFindDependency) message(FATAL_ERROR "Unexpected unparsed arguments ${x_UNPARSED_ARGUMENTS}") endif() - if(TARGET ${x_TargetName}) + if(TARGET ${x_TARGET}) # Target already defined, no need to do anything more return() endif() @@ -260,54 +260,54 @@ function(GenericFindDependency) # Look for a suitably named directory which contains a CMakeLists.txt, try to add it search_dependency_source( - TargetName "${x_TargetName}" - SourceSearchPaths "${x_SourceSearchPaths}" + TARGET "${x_TARGET}" + SOURCE_SEARCH_PATHS "${x_SOURCE_SEARCH_PATHS}" ) # If the expected target was created we have succeeded - if(TARGET ${x_TargetName}) - message(STATUS "Using dependency ${x_TargetName} from bundled source code") + if(TARGET ${x_TARGET}) + message(STATUS "Using dependency ${x_TARGET} from bundled source code") break() endif() else() # Try looking for a header file and library in the system paths - if(NOT x_SystemHeaderFile) + if(NOT x_SYSTEM_HEADER_FILE) # Use a sensible header file name if not explicitly set - set(x_SystemHeaderFile "lib${x_TargetName}/${x_TargetName}.h") + set(x_SYSTEM_HEADER_FILE "lib${x_TARGET}/${x_TARGET}.h") endif() # Look for common library naming patterns - set(x_SystemLibNames "${x_SystemLibName}" "${x_TargetName}" "lib${x_TargetName}") + set(x_SYSTEM_LIB_NAMES "${x_SystemLibName}" "${x_TARGET}" "lib${x_TARGET}") # Search either system libraries or sysroot, this is handled by cmake itself search_dependency_system( - TargetName "${x_TargetName}" - SystemHeaderFile "${x_SystemHeaderFile}" - SystemLibNames "${x_SystemLibNames}" + TARGET "${x_TARGET}" + SYSTEM_HEADER_FILE "${x_SYSTEM_HEADER_FILE}" + SYSTEM_LIB_NAMES "${x_SYSTEM_LIB_NAMES}" ) # If the target was found we have succeeded - if(TARGET ${x_TargetName}) - message(STATUS "Using dependency ${x_TargetName} from system") + if(TARGET ${x_TARGET}) + message(STATUS "Using dependency ${x_TARGET} from system") break() endif() endif() endforeach() # Final validation that the target was properly created from some source - if(TARGET ${x_TargetName}) + if(TARGET ${x_TARGET}) if(x_SYSTEM_INCLUDES) if(NOT CMAKE_CROSSCOMPILING OR THIRD_PARTY_INCLUDES_AS_SYSTEM) - mark_target_as_system_includes(${x_TargetName}) + mark_target_as_system_includes(${x_TARGET}) endif() endif() else() # Target not found in any location if(x_REQUIRED OR ${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) - message(FATAL_ERROR "Could not find REQUIRED dependency ${x_TargetName} in any available location") + message(FATAL_ERROR "Could not find REQUIRED dependency ${x_TARGET} in any available location") else() - message(WARNING "Could not find dependency ${x_TargetName} in any available location") + message(WARNING "Could not find dependency ${x_TARGET} in any available location") endif() endif() endfunction() From d22d5e45b6fab0bdf303db46755455d550821449 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Fri, 24 May 2019 14:55:42 +1000 Subject: [PATCH 38/63] Permit test libs dependencies to be specified separately --- SwiftCmakeOptions.cmake | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index b6832f5..eb54d2f 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -66,10 +66,15 @@ # A list of dependencies for test components can be specified using the # TEST_PACKAGES option. Pass a list of packages which will be searched for # using the find_package() cmake function. If any of the packages is not -# found the test components will be automatically disabled +# found the unit tests will be disabled # # swift_create_project_options(HAS_TESTS TEST_PACKAGES "Googletest" "RapidCheck") # +# Similarly, the TEST_LIBS_PACKAGES can be used to specify the dependencies +# of the test libraries. If takes the same behaviour as the TEST_PACKAGES library +# except it will only disable the test libraries feature if requirements are not +# met. If this option is not specified it assumes the same value as TEST_PACKAGES +# # The following test packages are currently supported: # # - Googletest (targets gtest etc) @@ -134,18 +139,19 @@ function(verify_test_dependencies) endif() if(NOT found) message(STATUS "Disable tests because dependency ${P} was not found") - set(test_components_possible OFF PARENT_SCOPE) + set(test_component_possible OFF PARENT_SCOPE) + else() + set(test_component_possible ON PARENT_SCOPE) endif() endforeach() endif() - set(x_test_packages_verified TRUE PARENT_SCOPE) endfunction() function(swift_create_project_options) set(argOptions "HAS_TESTS" "HAS_TEST_LIBS" "HAS_DOCS" "HAS_EXAMPLES" "SKIP_CROSS_COMPILING_CHECK") set(argSingleArguments "PROJECT" "DISABLE_TEST_COMPONENTS") - set(argMultiArguments "TEST_PACKAGES") + set(argMultiArguments "TEST_PACKAGES" "TEST_LIBS_PACKAGES") cmake_parse_arguments(x "${argOptions}" "${argSingleArguments}" "${argMultiArguments}" ${ARGN}) @@ -191,13 +197,22 @@ function(swift_create_project_options) endif() endif() - if(build_tests OR build_test_libs) - if(NOT x_test_packages_verified) + if(build_tests) + verify_test_dependencies(TEST_PACKAGES ${x_TEST_PACKAGES}) + + if(NOT test_component_possible) + set(build_tests OFF) + endif() + endif() + + if(build_test_libs) + if(x_TEST_LIBS_PACKAGES) + verify_test_dependencies(TEST_PACKAGES ${x_TEST_LIBS_PACKAGES}) + else() verify_test_dependencies(TEST_PACKAGES ${x_TEST_PACKAGES}) endif() - if(NOT test_components_possible) - set(build_tests OFF) + if(NOT test_component_possible) set(build_test_libs OFF) endif() endif() From 54f7e956af433b048d13d121c03032b43ac5cce4 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 27 May 2019 13:41:01 +1000 Subject: [PATCH 39/63] Check tests and test libs deps separately --- SwiftCmakeOptions.cmake | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/SwiftCmakeOptions.cmake b/SwiftCmakeOptions.cmake index eb54d2f..17af973 100644 --- a/SwiftCmakeOptions.cmake +++ b/SwiftCmakeOptions.cmake @@ -117,6 +117,7 @@ function(verify_test_dependencies) cmake_parse_arguments(x "" "" "TEST_PACKAGES" ${ARGN}) + set(dependencies_available ON PARENT_SCOPE) if(x_TEST_PACKAGES) foreach(P ${x_TEST_PACKAGES}) find_package(${P}) @@ -139,9 +140,7 @@ function(verify_test_dependencies) endif() if(NOT found) message(STATUS "Disable tests because dependency ${P} was not found") - set(test_component_possible OFF PARENT_SCOPE) - else() - set(test_component_possible ON PARENT_SCOPE) + set(dependencies_available OFF PARENT_SCOPE) endif() endforeach() endif() @@ -163,16 +162,20 @@ function(swift_create_project_options) set(x_PROJECT ${PROJECT_NAME}) endif() - set(test_components_possible ON) + set(tests_possible ON) + set(test_libs_possible ON) if(x_DISABLE_TEST_COMPONENTS) - set(test_components_possible OFF) + message(STATUS "Test components disabled by project") + set(tests_possible OFF) + set(test_libs_possible OFF) endif() if(NOT x_SKIP_CROSS_COMPILING_CHECK) if(CMAKE_CROSSCOMPILING) # Don't compile any test stuff if we are cross compiling message(STATUS "Skipping unit tests because we are cross compiling") - set(test_components_possible OFF) + set(tests_possible OFF) + set(test_libs_possible OFF) endif() endif() @@ -180,18 +183,18 @@ function(swift_create_project_options) set(build_test_libs FALSE) if(x_HAS_TESTS) - option(${x_PROJECT}_ENABLE_TESTS "Enable build of unit tests for ${x_PROJECT}" ${test_components_possible}) + option(${x_PROJECT}_ENABLE_TESTS "Enable build of unit tests for ${x_PROJECT}" ${tests_possible}) if(${x_PROJECT}_ENABLE_TESTS) - if(test_components_possible) + if(tests_possible) set(build_tests TRUE) endif() endif() endif() if(x_HAS_TEST_LIBS) - option(${x_PROJECT}_ENABLE_TEST_LIBS "Enable build of test libraries for ${x_PROJECT}" ${test_components_possible}) + option(${x_PROJECT}_ENABLE_TEST_LIBS "Enable build of test libraries for ${x_PROJECT}" ${test_libs_possible}) if(${x_PROJECT}_ENABLE_TEST_LIBS) - if(test_components_possible) + if(test_libs_possible) set(build_test_libs TRUE) endif() endif() @@ -200,7 +203,7 @@ function(swift_create_project_options) if(build_tests) verify_test_dependencies(TEST_PACKAGES ${x_TEST_PACKAGES}) - if(NOT test_component_possible) + if(NOT dependencies_available) set(build_tests OFF) endif() endif() @@ -212,7 +215,7 @@ function(swift_create_project_options) verify_test_dependencies(TEST_PACKAGES ${x_TEST_PACKAGES}) endif() - if(NOT test_component_possible) + if(NOT dependencies_available) set(build_test_libs OFF) endif() endif() From c1a4c9403c9147fec1103822cab6ed2c5fa381ee Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Fri, 24 May 2019 16:32:33 +1000 Subject: [PATCH 40/63] Add initial clang format module --- ClangFormat.cmake | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 ClangFormat.cmake diff --git a/ClangFormat.cmake b/ClangFormat.cmake new file mode 100644 index 0000000..3ebad40 --- /dev/null +++ b/ClangFormat.cmake @@ -0,0 +1,61 @@ +function(swift_setup_clang_format) + set(argOption "") + set(argSingle "PROJECT" "SCRIPT") + set(argMulti "CLANG_FORMAT_NAMES") + + cmake_parse_arguments(x "${argOptions}" "${argSingle}" "${argMulti}" ${ARGN}) + + if(NOT PROJECT) + set(PROJECT ${PROJECT_NAME}) + endif() + + if(NOT x_CLANG_FORMAT_NAMES) + set(x_CLANG_FORMAT_NAMES + clang-format60 clang-format-6.0 + clang-format40 clang-format-4.0 + clang-format39 clang-format-3.9 + clang-format38 clang-format-3.8 + clang-format37 clang-format-3.7 + clang-format36 clang-format-3.6 + clang-format35 clang-format-3.5 + clang-format34 clang-format-3.4 + clang-format + ) + endif() + find_program(CLANG_FORMAT NAMES ${x_CLANG_FORMAT_NAMES}) + + if("${CLANG_FORMAT}" STREQUAL "CLANG_FORMAT-NOTFOUND") + message(warning "Could not find appropriate clang-format, target disabled") + return() + else() + message(STATUS "Using ${CLANG_FORMAT}") + set(${PROJECT_NAME}_CLANG_FORMAT ${CLANG_FORMAT} CACHE STRING "Absolute path to clang-format for ${PROJECT_NAME}") + endif() + + set(target clang-format-${PROJECT}) + + if(x_SCRIPT) + set(custom_scripts {x_SCRIPT}) + else() + set(custom_scripts "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clang-format.sh" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clang-format.bash") + endif() + + foreach(script ${x_SCRIPTS}) + if(EXISTS ${script}) + message(STATUS "Initialising clang format target for ${PROJECT_NAME} using existing script in ${script}") + add_custom_target(${target} + COMMAND "${script}" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + ) + return() + endif() + endforeach() + + add_custom_target(${target} + echo "format" + COMMAND git ls-files '*.[ch]' '*.cpp' '*.cc' '*.hpp' + COMMAND git ls-files '*.[ch]' '*.cpp' '*.cc' '*.hpp' + | xargs ${${PROJECT}_CLANG_FORMAT} -i + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) +endfunction() From 01bac3e556c51ad66f0bbb6bfa71c16be477cd57 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Fri, 24 May 2019 16:39:18 +1000 Subject: [PATCH 41/63] Make clang-format support optional --- ClangFormat.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ClangFormat.cmake b/ClangFormat.cmake index 3ebad40..f8091b7 100644 --- a/ClangFormat.cmake +++ b/ClangFormat.cmake @@ -9,6 +9,14 @@ function(swift_setup_clang_format) set(PROJECT ${PROJECT_NAME}) endif() + option(${PROJECT}_ENABLE_CLANG_FORMAT "Enable auto-formatting of code using clang-format" ON) + + if(NOT ${PROJECT}_ENABLE_CLANG_FORMAT) + # Explicitly disabled + message(STATUS "${PROJECT} clang-format support is DISABLED") + return() + endif() + if(NOT x_CLANG_FORMAT_NAMES) set(x_CLANG_FORMAT_NAMES clang-format60 clang-format-6.0 From dcdfedd3e6f8f51284eed5d24f3029ed7be6f887 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 27 May 2019 08:11:30 +1000 Subject: [PATCH 42/63] Fix up clang format module, create clang-format-all alias for top level project --- ClangFormat.cmake | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/ClangFormat.cmake b/ClangFormat.cmake index f8091b7..d21195b 100644 --- a/ClangFormat.cmake +++ b/ClangFormat.cmake @@ -1,19 +1,27 @@ function(swift_setup_clang_format) set(argOption "") - set(argSingle "PROJECT" "SCRIPT") + set(argSingle "SCRIPT") set(argMulti "CLANG_FORMAT_NAMES") cmake_parse_arguments(x "${argOptions}" "${argSingle}" "${argMulti}" ${ARGN}) - if(NOT PROJECT) - set(PROJECT ${PROJECT_NAME}) + set(top_level_project OFF) + if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME}) + # This is the top level project, ie the CMakeLists.txt which cmake was run + # on directly, not a submodule/subproject. We can do some special things now. + # The option to enable clang formatting will be enabled by default only for + # top level projects. Also the top level project will create an alias target + # clang-format-all against the project specific target + set(top_level_project ON) endif() - option(${PROJECT}_ENABLE_CLANG_FORMAT "Enable auto-formatting of code using clang-format" ON) + message(STATUS "top_level_project ${top_level_project}") - if(NOT ${PROJECT}_ENABLE_CLANG_FORMAT) + option(${PROJECT_NAME}_ENABLE_CLANG_FORMAT "Enable auto-formatting of code using clang-format" ${top_level_project}) + + if(NOT ${PROJECT_NAME}_ENABLE_CLANG_FORMAT) # Explicitly disabled - message(STATUS "${PROJECT} clang-format support is DISABLED") + message(STATUS "${PROJECT_NAME} clang-format support is DISABLED") return() endif() @@ -40,10 +48,10 @@ function(swift_setup_clang_format) set(${PROJECT_NAME}_CLANG_FORMAT ${CLANG_FORMAT} CACHE STRING "Absolute path to clang-format for ${PROJECT_NAME}") endif() - set(target clang-format-${PROJECT}) + set(target clang-format-${PROJECT_NAME}) if(x_SCRIPT) - set(custom_scripts {x_SCRIPT}) + set(custom_scripts ${x_SCRIPT}) else() set(custom_scripts "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clang-format.sh" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clang-format.bash") endif() @@ -59,11 +67,20 @@ function(swift_setup_clang_format) endif() endforeach() + # Don't quote the command here, we need it to come out as a cmake list to be passed to + # add_custom_target correctly + set(format_all_command git ls-files '*.[ch]' '*.cpp' '*.cc' '*.hpp' | xargs ${${PROJECT_NAME}_CLANG_FORMAT} -i) + add_custom_target(${target} - echo "format" - COMMAND git ls-files '*.[ch]' '*.cpp' '*.cc' '*.hpp' - COMMAND git ls-files '*.[ch]' '*.cpp' '*.cc' '*.hpp' - | xargs ${${PROJECT}_CLANG_FORMAT} -i + COMMAND ${format_all_command} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + + if(${top_level_project}) + # Cmake doesn't support aliasing non-library targets, so we have to just redefine the target entirely + add_custom_target(clang-format-all + COMMAND ${format_all_command} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endif() endfunction() From 1b5bde351921a901456d2cfd3e9b948b7cce1d79 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 27 May 2019 13:18:12 +1000 Subject: [PATCH 43/63] Start clang tidy module --- ClangFormat.cmake | 24 ++++----- ClangTidy.cmake | 122 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 ClangTidy.cmake diff --git a/ClangFormat.cmake b/ClangFormat.cmake index d21195b..8a22e08 100644 --- a/ClangFormat.cmake +++ b/ClangFormat.cmake @@ -41,7 +41,7 @@ function(swift_setup_clang_format) find_program(CLANG_FORMAT NAMES ${x_CLANG_FORMAT_NAMES}) if("${CLANG_FORMAT}" STREQUAL "CLANG_FORMAT-NOTFOUND") - message(warning "Could not find appropriate clang-format, target disabled") + message(WARNING "Could not find appropriate clang-format, target disabled") return() else() message(STATUS "Using ${CLANG_FORMAT}") @@ -56,30 +56,30 @@ function(swift_setup_clang_format) set(custom_scripts "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clang-format.sh" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clang-format.bash") endif() - foreach(script ${x_SCRIPTS}) + foreach(script ${custom_scripts}) if(EXISTS ${script}) message(STATUS "Initialising clang format target for ${PROJECT_NAME} using existing script in ${script}") - add_custom_target(${target} - COMMAND "${script}" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - ) - return() + set(command ${script}) endif() endforeach() - # Don't quote the command here, we need it to come out as a cmake list to be passed to - # add_custom_target correctly - set(format_all_command git ls-files '*.[ch]' '*.cpp' '*.cc' '*.hpp' | xargs ${${PROJECT_NAME}_CLANG_FORMAT} -i) + if(NOT command) + # Use a default formatting command + # Don't quote the command here, we need it to come out as a cmake list to be passed to + # add_custom_target correctly + set(command git ls-files '*.[ch]' '*.cpp' '*.cc' '*.hpp' | xargs ${${PROJECT_NAME}_CLANG_FORMAT} -i) + endif() + add_custom_target(${target} - COMMAND ${format_all_command} + COMMAND ${command} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) if(${top_level_project}) # Cmake doesn't support aliasing non-library targets, so we have to just redefine the target entirely add_custom_target(clang-format-all - COMMAND ${format_all_command} + COMMAND ${command} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif() diff --git a/ClangTidy.cmake b/ClangTidy.cmake new file mode 100644 index 0000000..bba1da3 --- /dev/null +++ b/ClangTidy.cmake @@ -0,0 +1,122 @@ +function(swift_setup_clang_tidy) + set(argOption "") + set(argSingle "SCRIPT") + set(argMulti "CLANG_TIDY_NAMES" "TARGETS") + + cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN}) + + set(top_level_project OFF) + if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME}) + set(top_level_project ON) + endif() + + option(${PROJECT_NAME}_ENABLE_CLANG_TIDY "Enable auto-linting of code using code-tidy" ${top_level_project}) + + if(NOT ${PROJECT_NAME}_ENABLE_CLANG_TIDY) + message(STATUS "${PROJECT_NAME} clang-tidy support is DISABLED") + return() + endif() + + set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "Export compile commands" FORCE) + + if(NOT x_CLANG_TIDY_NAMES) + set(x_CLANG_TIDY_NAMES + clang-tidy60 clang-tidy-6.0 + clang-tidy40 clang-tidy-4.0 + clang-tidy39 clang-tidy-3.9 + clang-tidy38 clang-tidy-3.8 + clang-tidy37 clang-tidy-3.7 + clang-tidy36 clang-tidy-3.6 + clang-tidy35 clang-tidy-3.5 + clang-tidy34 clang-tidy-3.4 + clang-tidy + ) + endif() + find_program(CLANG_TIDY NAMES ${x_CLANG_TIDY_NAMES}) + + if("${CLANG_TIDY}" STREQUAL "CLANG_TIDY-NOTFOUND") + message(WARNING "Could not find appropriate clang-tidy, target disabled") + return() + endif() + + message(STATUS "Using ${CLANG_TIDY}") + set(${PROJECT_NAME}_CLANG_TIDY ${CLANG_TIDY} CACHE STRING "Absolute path to clang-tidy for ${PROJECT_NAME}") + + if(x_SCRIPT) + set(custom_scripts ${x_SCRIPT}) + else() + set(custom_scripts "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clang-tidy.sh" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/clang-tidy.bash") + endif() + + foreach(script ${custom_scripts}) + if(EXISTS ${script}) + message(STATUS "Initialising clang tidy target for ${PROJECT_NAME} using existing script in ${script}") + add_custom_target( + clang-tidy-${PROJECT_NAME} + COMMAND ${script} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + if(top_level_project) + add_custom_target( + clang-tidy-all + COMMAND ${script} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endif() + return() + endif() + endforeach() + + foreach(target ${${PROJECT_NAME}_clang_tidy_targets}) + set(target_srcs "") + set(abs_target_srcs "") + get_target_property(target_srcs ${target} SOURCES) + foreach(file ${target_srcs}) + if(${file} MATCHES ".*\\.h$") + list(REMOVE_ITEM target_srcs ${file}) + endif() + endforeach() + + list(REMOVE_DUPLICATES target_srcs) + + get_target_property(target_dir ${target} SOURCE_DIR) + foreach(file ${target_srcs}) + get_filename_component(abs_file ${file} ABSOLUTE BASE_DIR ${target_dir}) + list(APPEND abs_target_srcs ${abs_file}) + endforeach() + + if(abs_target_srcs) + add_custom_target( + clang-tidy-${target} + COMMAND echo ${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes-${target}.yaml ${abs_target_srcs} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + list(APPEND all_srcs ${abs_target_srcs}) + else() + message(WARNING "Target ${target} does not have any lintable sources") + endif() + endforeach() + + if(all_srcs) + if(top_level_project) + list(REMOVE_DUPLICATES all_srcs) + add_custom_target( + clang-tidy-all + COMMAND ${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes.yaml ${all_srcs} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endif() + else() + message(WARNING "Project ${PROJECT_NAME} did not enable linting for any targets") + endif() +endfunction() + +function(swift_target_enable_clang_tidy TARGET) + if(NOT TARGET ${TARGET}) + message(WARNING "Trying to enable clang-tidy for ${TARGET} which doesn't exist") + return() + endif() + + list(APPEND ${PROJECT_NAME}_clang_tidy_targets ${TARGET}) + set(${PROJECT_NAME}_clang_tidy_targets ${${PROJECT_NAME}_clang_tidy_targets} CACHE INTERNAL "List of targets in ${PROJECT_NAME} to auto-lint with clang-tidy") +endfunction() From 3c8d57f8a2edef4da87fdb13c460d694332d41a4 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 27 May 2019 13:22:12 +1000 Subject: [PATCH 44/63] Enable command --- ClangTidy.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ClangTidy.cmake b/ClangTidy.cmake index bba1da3..955c445 100644 --- a/ClangTidy.cmake +++ b/ClangTidy.cmake @@ -88,7 +88,7 @@ function(swift_setup_clang_tidy) if(abs_target_srcs) add_custom_target( clang-tidy-${target} - COMMAND echo ${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes-${target}.yaml ${abs_target_srcs} + COMMAND ${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes-${target}.yaml ${abs_target_srcs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) list(APPEND all_srcs ${abs_target_srcs}) From 12b121be4c92752659d097e87d935c81bfa3dd4f Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 27 May 2019 13:22:34 +1000 Subject: [PATCH 45/63] Remove debug message --- ClangFormat.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/ClangFormat.cmake b/ClangFormat.cmake index 8a22e08..3652eea 100644 --- a/ClangFormat.cmake +++ b/ClangFormat.cmake @@ -15,7 +15,6 @@ function(swift_setup_clang_format) set(top_level_project ON) endif() - message(STATUS "top_level_project ${top_level_project}") option(${PROJECT_NAME}_ENABLE_CLANG_FORMAT "Enable auto-formatting of code using clang-format" ${top_level_project}) From 4084d4928b6dac290b8ca95d6c464b6cb7cfa047 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 27 May 2019 15:13:42 +1000 Subject: [PATCH 46/63] Pass argument to custom format/tidy script --- ClangFormat.cmake | 2 +- ClangTidy.cmake | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/ClangFormat.cmake b/ClangFormat.cmake index 3652eea..ae4a067 100644 --- a/ClangFormat.cmake +++ b/ClangFormat.cmake @@ -58,7 +58,7 @@ function(swift_setup_clang_format) foreach(script ${custom_scripts}) if(EXISTS ${script}) message(STATUS "Initialising clang format target for ${PROJECT_NAME} using existing script in ${script}") - set(command ${script}) + set(command ${script} all) endif() endforeach() diff --git a/ClangTidy.cmake b/ClangTidy.cmake index 955c445..19e806f 100644 --- a/ClangTidy.cmake +++ b/ClangTidy.cmake @@ -51,15 +51,10 @@ function(swift_setup_clang_tidy) foreach(script ${custom_scripts}) if(EXISTS ${script}) message(STATUS "Initialising clang tidy target for ${PROJECT_NAME} using existing script in ${script}") - add_custom_target( - clang-tidy-${PROJECT_NAME} - COMMAND ${script} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) if(top_level_project) add_custom_target( clang-tidy-all - COMMAND ${script} + COMMAND ${script} all WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif() @@ -118,5 +113,5 @@ function(swift_target_enable_clang_tidy TARGET) endif() list(APPEND ${PROJECT_NAME}_clang_tidy_targets ${TARGET}) - set(${PROJECT_NAME}_clang_tidy_targets ${${PROJECT_NAME}_clang_tidy_targets} CACHE INTERNAL "List of targets in ${PROJECT_NAME} to auto-lint with clang-tidy") + set(${PROJECT_NAME}_clang_tidy_targets ${${PROJECT_NAME}_clang_tidy_targets} CACHE INTERNAL "List of targets in ${PROJECT_NAME} to auto-lint with clang-tidy" FORCE) endfunction() From f2b5657b364aedf96865dd7da6faa20958ea35ae Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 28 May 2019 11:47:14 +1000 Subject: [PATCH 47/63] Change clang-tidy interface --- ClangTidy.cmake | 83 +++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/ClangTidy.cmake b/ClangTidy.cmake index 19e806f..8380052 100644 --- a/ClangTidy.cmake +++ b/ClangTidy.cmake @@ -1,7 +1,7 @@ function(swift_setup_clang_tidy) set(argOption "") set(argSingle "SCRIPT") - set(argMulti "CLANG_TIDY_NAMES" "TARGETS") + set(argMulti "CLANG_TIDY_NAMES" "TARGETS" "FILES") cmake_parse_arguments(x "${argOption}" "${argSingle}" "${argMulti}" ${ARGN}) @@ -60,37 +60,54 @@ function(swift_setup_clang_tidy) endif() return() endif() + + if(x_SCRIPT) + # Was passed a script name but it doesn't exist + message(WARNING "Specified clang-tidy script ${x_SCRIPT} doesn't exist") + return() + endif() endforeach() - foreach(target ${${PROJECT_NAME}_clang_tidy_targets}) - set(target_srcs "") - set(abs_target_srcs "") - get_target_property(target_srcs ${target} SOURCES) - foreach(file ${target_srcs}) - if(${file} MATCHES ".*\\.h$") - list(REMOVE_ITEM target_srcs ${file}) + if(x_TARGETS) + foreach(target ${x_TARGETS}) + if(NOT TARGET ${target}) + message(WARNING "clang-tidy enabled for non-existent target ${target}") + continue() endif() - endforeach() - - list(REMOVE_DUPLICATES target_srcs) - get_target_property(target_dir ${target} SOURCE_DIR) - foreach(file ${target_srcs}) - get_filename_component(abs_file ${file} ABSOLUTE BASE_DIR ${target_dir}) - list(APPEND abs_target_srcs ${abs_file}) + # Extract the list of source files from the target and convert to absolute paths + set(target_srcs "") + set(abs_target_srcs "") + get_target_property(target_srcs ${target} SOURCES) + foreach(file ${target_srcs}) + if(${file} MATCHES ".*\\.h$") + list(REMOVE_ITEM target_srcs ${file}) + endif() + endforeach() + + list(REMOVE_DUPLICATES target_srcs) + + get_target_property(target_dir ${target} SOURCE_DIR) + foreach(file ${target_srcs}) + get_filename_component(abs_file ${file} ABSOLUTE BASE_DIR ${target_dir}) + list(APPEND abs_target_srcs ${abs_file}) + endforeach() + + if(abs_target_srcs) + list(APPEND all_srcs ${abs_target_srcs}) + else() + message(WARNING "Target ${target} does not have any lintable sources") + endif() endforeach() - - if(abs_target_srcs) - add_custom_target( - clang-tidy-${target} - COMMAND ${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes-${target}.yaml ${abs_target_srcs} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) - list(APPEND all_srcs ${abs_target_srcs}) - else() - message(WARNING "Target ${target} does not have any lintable sources") - endif() - endforeach() + elseif(x_FILES) + foreach(pattern ${x_FILES}) + set(files "") + file(GLOB files ${pattern}) + list(APPEND all_srcs ${files}) + endforeach() + else() + message(FATAL_ERROR "Must specify either SCRIPT, FILES, or TARGETS in order to set up clang-tidy") + endif() if(all_srcs) if(top_level_project) @@ -102,16 +119,6 @@ function(swift_setup_clang_tidy) ) endif() else() - message(WARNING "Project ${PROJECT_NAME} did not enable linting for any targets") + message(WARNING "Project ${PROJECT_NAME} did not enable linting for any files/targets") endif() endfunction() - -function(swift_target_enable_clang_tidy TARGET) - if(NOT TARGET ${TARGET}) - message(WARNING "Trying to enable clang-tidy for ${TARGET} which doesn't exist") - return() - endif() - - list(APPEND ${PROJECT_NAME}_clang_tidy_targets ${TARGET}) - set(${PROJECT_NAME}_clang_tidy_targets ${${PROJECT_NAME}_clang_tidy_targets} CACHE INTERNAL "List of targets in ${PROJECT_NAME} to auto-lint with clang-tidy" FORCE) -endfunction() From ec012028a284f22d31c7714c4c445ad14f69fdc2 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 28 May 2019 13:26:29 +1000 Subject: [PATCH 48/63] Mark as system includes --- FindGnss-converters.cmake | 1 + FindOrion-Proto.cmake | 1 + FindProtobuf.cmake | 1 + FindRtcm.cmake | 1 + FindSbp.cmake | 1 + FindSettings.cmake | 1 + FindStarling.cmake | 1 + FindSwiftnav.cmake | 1 + 8 files changed, 8 insertions(+) diff --git a/FindGnss-converters.cmake b/FindGnss-converters.cmake index a45aa1b..cda9bed 100644 --- a/FindGnss-converters.cmake +++ b/FindGnss-converters.cmake @@ -2,4 +2,5 @@ include("GenericFindDependency") GenericFindDependency( TARGET gnss_converters SOURCE_DIR "gnss-converters/c" + SYSTEM_INCLUDES ) diff --git a/FindOrion-Proto.cmake b/FindOrion-Proto.cmake index 277be74..474bbc4 100644 --- a/FindOrion-Proto.cmake +++ b/FindOrion-Proto.cmake @@ -2,4 +2,5 @@ include("GenericFindDependency") GenericFindDependency( TARGET orion-proto SOURCE_DIR "orion_proto" + SYSTEM_INCLUDES ) diff --git a/FindProtobuf.cmake b/FindProtobuf.cmake index 4cdfc18..80a75f3 100644 --- a/FindProtobuf.cmake +++ b/FindProtobuf.cmake @@ -2,4 +2,5 @@ include("GenericFindDependency") GenericFindDependency( TARGET "libprotobuf" SOURCE_DIR "protobuf/cmake" + SYSTEM_INCLUDES ) diff --git a/FindRtcm.cmake b/FindRtcm.cmake index 3d5f43f..c1f4bb1 100644 --- a/FindRtcm.cmake +++ b/FindRtcm.cmake @@ -2,4 +2,5 @@ include("GenericFindDependency") GenericFindDependency( TARGET rtcm SOURCE_DIR "c" + SYSTEM_INCLUDES ) diff --git a/FindSbp.cmake b/FindSbp.cmake index 785ee63..251c640 100644 --- a/FindSbp.cmake +++ b/FindSbp.cmake @@ -2,4 +2,5 @@ include("GenericFindDependency") GenericFindDependency( TARGET sbp SOURCE_DIR "c" + SYSTEM_INCLUDES ) diff --git a/FindSettings.cmake b/FindSettings.cmake index 5db14f6..b86f23d 100644 --- a/FindSettings.cmake +++ b/FindSettings.cmake @@ -1,4 +1,5 @@ include("GenericFindDependency") GenericFindDependency( TARGET settings + SYSTEM_INCLUDES ) diff --git a/FindStarling.cmake b/FindStarling.cmake index f9ab4be..6ef49e2 100644 --- a/FindStarling.cmake +++ b/FindStarling.cmake @@ -1,4 +1,5 @@ include("GenericFindDependency") GenericFindDependency( TARGET starling + SYSTEM_INCLUDES ) diff --git a/FindSwiftnav.cmake b/FindSwiftnav.cmake index ceea74b..9c44bfa 100644 --- a/FindSwiftnav.cmake +++ b/FindSwiftnav.cmake @@ -1,4 +1,5 @@ include("GenericFindDependency") GenericFindDependency( TARGET swiftnav + SYSTEM_INCLUDES ) From 876e6cd3d46a04da6956da01dd5b5949ddf155cc Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 29 May 2019 08:32:59 +1000 Subject: [PATCH 49/63] Add basic ccache module --- CCache.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 CCache.cmake diff --git a/CCache.cmake b/CCache.cmake new file mode 100644 index 0000000..b65bf62 --- /dev/null +++ b/CCache.cmake @@ -0,0 +1,12 @@ +option(SWIFT_ENABLE_CCACHE "Use ccache to speed up compilation process" OFF) + +if(SWIFT_ENABLE_CCACHE) + find_program(CCACHE_PATH ccache) + if(CCACHE_PATH) + message(STATUS "Using ccache at ${CCACHE_PATH}") + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PATH}) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_PATH}) + else() + message(STATUS "Could not find ccache") + endif() +endif() From 327931a5fb13b504fd658210140521dc78059f1d Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 29 May 2019 08:33:22 +1000 Subject: [PATCH 50/63] Use git commands to filter file list, add diff target --- ClangTidy.cmake | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ClangTidy.cmake b/ClangTidy.cmake index 8380052..f975702 100644 --- a/ClangTidy.cmake +++ b/ClangTidy.cmake @@ -114,9 +114,19 @@ function(swift_setup_clang_tidy) list(REMOVE_DUPLICATES all_srcs) add_custom_target( clang-tidy-all - COMMAND ${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes.yaml ${all_srcs} + COMMAND + ${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes.yaml + `git ls-files ${all_srcs}` WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + add_custom_target( + clang-tidy-diff + COMMAND + ${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes.yaml + `git diff --diff-filter=ACMRTUXB --name-only master -- ${all_srcs}` + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endif() else() message(WARNING "Project ${PROJECT_NAME} did not enable linting for any files/targets") From 3059860e93959368c6ff76d73ec4c0cd39ef2716 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 29 May 2019 08:34:15 +1000 Subject: [PATCH 51/63] Add namespaced targets --- ClangTidy.cmake | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ClangTidy.cmake b/ClangTidy.cmake index f975702..f51aff0 100644 --- a/ClangTidy.cmake +++ b/ClangTidy.cmake @@ -110,8 +110,23 @@ function(swift_setup_clang_tidy) endif() if(all_srcs) + list(REMOVE_DUPLICATES all_srcs) + add_custom_target( + clang-tidy-all-${PROJECT_NAME} + COMMAND + ${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes.yaml + `git ls-files ${all_srcs}` + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + add_custom_target( + clang-tidy-diff-${PROJECT_NAME} + COMMAND + ${${PROJECT_NAME}_CLANG_TIDY} -p ${CMAKE_BINARY_DIR} --export-fixes=${CMAKE_CURRENT_SOURCE_DIR}/fixes.yaml + `git diff --diff-filter=ACMRTUXB --name-only master -- ${all_srcs}` + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + if(top_level_project) - list(REMOVE_DUPLICATES all_srcs) add_custom_target( clang-tidy-all COMMAND @@ -126,7 +141,6 @@ function(swift_setup_clang_tidy) `git diff --diff-filter=ACMRTUXB --name-only master -- ${all_srcs}` WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) - endif() else() message(WARNING "Project ${PROJECT_NAME} did not enable linting for any files/targets") From e43d46df19e5dc33c875f73c62a97ea5a37892a4 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 29 May 2019 10:41:29 +1000 Subject: [PATCH 52/63] Add diff clang format target --- ClangFormat.cmake | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/ClangFormat.cmake b/ClangFormat.cmake index ae4a067..6376af0 100644 --- a/ClangFormat.cmake +++ b/ClangFormat.cmake @@ -58,27 +58,46 @@ function(swift_setup_clang_format) foreach(script ${custom_scripts}) if(EXISTS ${script}) message(STATUS "Initialising clang format target for ${PROJECT_NAME} using existing script in ${script}") - set(command ${script} all) + set(all_command ${script} all) + set(diff_command ${script} diff) endif() endforeach() - if(NOT command) + if(x_SCRIPT) + message(WARNING "Specified clang-format script ${x_SCRIPT} doesn't exist") + return() + endif() + + set(default_patterns "*.[ch]" "*.cpp" "*.cc" "*.hpp") + if(NOT all_command) # Use a default formatting command # Don't quote the command here, we need it to come out as a cmake list to be passed to # add_custom_target correctly - set(command git ls-files '*.[ch]' '*.cpp' '*.cc' '*.hpp' | xargs ${${PROJECT_NAME}_CLANG_FORMAT} -i) + set(all_command git ls-files ${default_patterns} | xargs ${${PROJECT_NAME}_CLANG_FORMAT} -i) + endif() + + if(NOT diff_command) + set(diff_command git diff --diff-filter=ACMRTUXB --name-only master -- ${default_patterns} | xargs ${${PROJECT_NAME}_CLANG_FORMAT} -i) endif() - add_custom_target(${target} - COMMAND ${command} + add_custom_target(clang-format-all-${PROJECT_NAME} + COMMAND ${all_command} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + add_custom_target(clang-format-diff-${PROJECT_NAME} + COMMAND ${diff_command} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) if(${top_level_project}) # Cmake doesn't support aliasing non-library targets, so we have to just redefine the target entirely add_custom_target(clang-format-all - COMMAND ${command} + COMMAND ${all_command} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + add_custom_target(clang-format-diff + COMMAND ${diff_command} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) endif() From af61d02b44cc95dc39cd2a43ffdd19b6f20c1b38 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 29 May 2019 11:00:27 +1000 Subject: [PATCH 53/63] Create extra clang tidy targets using custom script --- ClangTidy.cmake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ClangTidy.cmake b/ClangTidy.cmake index f51aff0..91af3e9 100644 --- a/ClangTidy.cmake +++ b/ClangTidy.cmake @@ -51,12 +51,27 @@ function(swift_setup_clang_tidy) foreach(script ${custom_scripts}) if(EXISTS ${script}) message(STATUS "Initialising clang tidy target for ${PROJECT_NAME} using existing script in ${script}") + add_custom_target( + clang-tidy-all-${PROJECT_NAME} + COMMAND ${script} all + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + add_custom_target( + clang-tidy-diff-${PROJECT_NAME} + COMMAND ${script} diff + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) if(top_level_project) add_custom_target( clang-tidy-all COMMAND ${script} all WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + add_custom_target( + clang-tidy-diff + COMMAND ${script} diff + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) endif() return() endif() From 007f9a425e37efe0aa64defc5adc4e79aba797c6 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Wed, 29 May 2019 17:19:40 +1000 Subject: [PATCH 54/63] Break up to clarify, add documentation --- ClangFormat.cmake | 178 ++++++++++++++++++-------- ClangTidy.cmake | 309 +++++++++++++++++++++++++++++----------------- 2 files changed, 321 insertions(+), 166 deletions(-) diff --git a/ClangFormat.cmake b/ClangFormat.cmake index 6376af0..6841472 100644 --- a/ClangFormat.cmake +++ b/ClangFormat.cmake @@ -1,3 +1,87 @@ +# +# A module to create custom targets to format source and header files in a git repo +# +# The function swift_setup_clang_format will create several targets which will +# use clang-format to format source code according to a configuration file. 2 types +# of targets will be created, one for formatting all files in the repository and the +# other for formatting only the files which differ from master. The list of files to +# format is generated by git itself. +# +# The created targets have the names +# +# - clang-format-all-${PROJECT_NAME} - formats all files in the repo +# - clang-format-diff-${PROJECT_NAME} - formats only changed files +# +# In addition if the current project is at the top level of the working tree 2 more +# targets will be created +# +# - clang-format-all +# - clang-format-diff +# +# which are aliases for the namespaced targets. If every project in a working +# directory uses this module to create auto-formatting targets there will never be +# a name clash +# +# The parameter SCRIPT can be used to specify a custom formatting command instead +# of calling clang-format directly. This should be executable and will be called +# with a single argument of either 'all' or 'diff' according to the target +# +# clang-format-all-${PROJECT_NAME} will run `