Removed cmake/common submodule

This commit is contained in:
Mateusz Pusz
2020-09-06 10:23:31 +02:00
parent 32779e01f0
commit d03d7291e4
11 changed files with 316 additions and 10 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "cmake/common"]
path = cmake/common
url = https://github.com/mpusz/cmake-scripts.git

View File

@ -27,7 +27,7 @@ project(mp-units)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# include common tools and workarounds
include(common/cmake/scripts)
include(common/scripts)
# use Conan configuration if available
conan_init(cmake)

Submodule cmake/common deleted from b951a32791

46
cmake/common/conan.cmake Normal file
View File

@ -0,0 +1,46 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Helper to use conan generated configuration if provided
macro(conan_init generator)
if(${generator} STREQUAL "cmake_paths")
include(${CMAKE_BINARY_DIR}/conan_paths.cmake OPTIONAL)
elseif(${generator} STREQUAL "cmake")
if(NOT DEFINED CONAN_PACKAGE_NAME)
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
endif()
endif()
else()
message(FATAL_ERROR "Unknown Conan generator: ${generator}")
endif()
endmacro()
# Checks if conan installed testing dependencies
macro(conan_check_testing test_framework)
if(NOT TARGET CONAN_PKG::${test_framework})
message(FATAL_ERROR "CONAN_PKG::${test_framework} not found!\nPlease run `conan install` with `-e CONAN_RUN_TESTS=True`.")
endif()
endmacro()

View File

@ -0,0 +1,81 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# A path to scripts directory
set(CMAKE_SCRIPTS_ROOT ${CMAKE_CURRENT_LIST_DIR})
# Install provided targets
function(install_targets)
if(NOT CMAKE_INSTALL_BINDIR)
set(CMAKE_INSTALL_BINDIR "bin")
endif()
if(NOT CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")
endif()
if(NOT CMAKE_INSTALL_INCLUDEDIR)
set(CMAKE_INSTALL_INCLUDEDIR "include")
endif()
install(TARGETS ${ARGN}
EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # TODO Remove when CMAKE 3.14
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # TODO Remove when CMAKE 3.14
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # TODO Remove when CMAKE 3.14
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endfunction()
# Generate configuration files and install the package
function(configure_and_install configure_in_file_path namespace version_compare_rules)
if(NOT APPLE)
set(CMAKE_INSTALL_RPATH ${ORIGIN})
endif()
# prepare installation files
include(CMakePackageConfigHelpers)
set(ConfigPackageSource ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME})
set(ConfigPackageDestination lib/cmake/${PROJECT_NAME})
write_basic_package_version_file(
${ConfigPackageSource}/${PROJECT_NAME}-config-version.cmake
COMPATIBILITY ${version_compare_rules})
configure_package_config_file(${configure_in_file_path}
${ConfigPackageSource}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${ConfigPackageDestination})
# install library
install(EXPORT ${PROJECT_NAME}Targets
DESTINATION ${ConfigPackageDestination}
FILE ${PROJECT_NAME}-targets.cmake
NAMESPACE ${namespace}::
COMPONENT Devel)
install(FILES
"${ConfigPackageSource}/${PROJECT_NAME}-config.cmake"
"${ConfigPackageSource}/${PROJECT_NAME}-config-version.cmake"
DESTINATION ${ConfigPackageDestination}
COMPONENT Devel)
# local package
export(EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${namespace}::
FILE ${ConfigPackageSource}/${PROJECT_NAME}-targets.cmake)
endfunction()

View File

@ -0,0 +1,28 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
include(conan)
include(install)
include(static_analysis)
include(warnings)

View File

@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")

View File

@ -0,0 +1,44 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
macro(enable_clang_tidy)
find_program(clang_tidy_cmd NAMES "clang-tidy")
if(NOT clang_tidy_cmd)
message(WARNING "clang-tidy not found!")
else()
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/.clang-tidy")
message(FATAL_ERROR "'${CMAKE_SOURCE_DIR}/.clang-tidy' configuration file not found!")
endif()
set(CMAKE_CXX_CLANG_TIDY "${clang_tidy_cmd}")
endif()
endmacro()
macro(enable_iwyu)
find_program(iwyu_cmd NAMES "include-what-you-use")
if(NOT iwyu_cmd)
message(WARNING "include-what-you-use not found!")
else()
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${iwyu_cmd}")
endif()
endmacro()

110
cmake/common/warnings.cmake Normal file
View File

@ -0,0 +1,110 @@
# The MIT License (MIT)
#
# Copyright (c) 2016 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Based on https://github.com/lefticus/cpp_starter_project/blob/master/cmake/CompilerWarnings.cmake
# Configure compiler warning level
function(set_warnings target)
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)
if(NOT TARGET ${target})
message(FATAL_ERROR "'${target}' is not a CMake target")
endif()
set(MSVC_WARNINGS
/W4 # Baseline reasonable warnings
/w14062 # enumerator 'identifier' in a switch of enum 'enumeration' is not handled
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
/w14263 # 'function': member function does not override any base class virtual member function
/w14265 # 'classname': class has virtual functions, but destructor is not
# virtual instances of this class may not be destructed correctly
/w14266 # 'function': no override available for virtual member function from base 'type'; function is hidden
/w14287 # 'operator': unsigned/negative constant mismatch
/we4289 # nonstandard extension used: 'variable': loop control variable
# declared in the for-loop is used outside the for-loop scope
/w14296 # 'operator': expression is always 'boolean_value'
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
/w14545 # expression before comma evaluates to a function which is missing
# an argument list
/w14546 # function call before comma missing argument list
/w14547 # 'operator': operator before comma has no effect; expected
# operator with side-effect
/w14549 # 'operator': operator before comma has no effect; did you intend
# 'operator'?
/w14555 # expression has no effect; expected expression with side- effect
/w14619 # pragma warning: there is no warning number 'number'
/w14640 # Enable warning on thread un-safe static member initialization
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may
# cause unexpected runtime behavior.
/w14905 # wide string literal cast to 'LPSTR'
/w14906 # string literal cast to 'LPWSTR'
/w14928 # illegal copy-initialization; more than one user-defined
# conversion has been implicitly applied
/permissive- # standards conformance mode for MSVC compiler.
)
set(CLANG_WARNINGS
-Wall
-Wextra # reasonable and standard
-Wpedantic # warn if non-standard C++ is used
-Wshadow # warn the user if a variable declaration shadows one from a parent context
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a
# non-virtual destructor. This helps catch hard to
# track down memory errors
-Wold-style-cast # warn for c-style casts
-Wcast-align # warn for potential performance problem casts
-Wunused # warn on anything being unused
-Woverloaded-virtual # warn if you overload (not override) a virtual function
-Wcast-qual # warn on dropping const or volatile qualifiers
-Wconversion # warn on type conversions that may lose data
-Wsign-conversion # warn on sign conversions
-Wnull-dereference # warn if a null dereference is detected
-Wdouble-promotion # warn if float is implicit promoted to double
-Wformat=2 # warn on security issues around functions that format output (ie printf)
)
if(WARNINGS_AS_ERRORS)
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
endif()
set(GCC_WARNINGS
${CLANG_WARNINGS}
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
-Wduplicated-cond # warn if if / else chain has duplicated conditions
-Wduplicated-branches # warn if if / else branches have duplicated code
-Wlogical-op # warn about logical operations being used where bitwise were probably wanted
)
if(MSVC)
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE)
target_compile_options(${target} INTERFACE ${MSVC_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
target_compile_options(${target} INTERFACE ${CLANG_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${target} INTERFACE ${GCC_WARNINGS})
else()
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
endif()
endfunction()

View File

@ -80,7 +80,7 @@ in *~/.conan/profile* directory. An example profile can look as follows:
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=9
compiler.version=10
compiler.cppstd=20
compiler.libcxx=libstdc++11
build_type=Release
@ -89,8 +89,8 @@ in *~/.conan/profile* directory. An example profile can look as follows:
[build_requires]
[env]
CC=/usr/bin/gcc-9
CXX=/usr/bin/g++-9
CC=/usr/bin/gcc-10
CXX=/usr/bin/g++-10
.. tip::

View File

@ -31,7 +31,7 @@ project(mp-units
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
# include common tools and workarounds
include(common/cmake/scripts)
include(common/scripts)
# use Conan configuration if available
conan_init(cmake)
@ -103,4 +103,4 @@ install(DIRECTORY include/units
)
# generate configuration files and install the package
configure_and_install(../cmake/common/cmake/simple-config.cmake.in mp-units SameMajorVersion)
configure_and_install(../cmake/common/simple-config.cmake.in mp-units SameMajorVersion)