-# Building upon same version as llvm. Let's assume they did their homework and
-# it's a good version. Compare:
-# ~~~
-# https://repology.org/badge/vertical-allrepos/cmake.svg?minversion=3.4.3
-# ~~~
cmake_minimum_required(VERSION 3.4.3)
project(ccache LANGUAGES C CXX)
set(CMAKE_C_STANDARD_REQUIRED YES)
set(CMAKE_C_EXTENSIONS NO)
-# Always export compile_commands.json as it's useful for so many tools.
+# Always export compile_commands.json since it's useful for many tools.
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(GenerateVersionFile)
#
-# 3rd party
+# Third party
#
-option(USE_LIBZSTD_FROM_INTERNET "Download and use libzstd from the Internet"
- OFF)
+option(USE_LIBZSTD_FROM_INTERNET "Download and use libzstd from the Internet" OFF)
find_package(zstd 1.1.2 REQUIRED)
option(USE_LIBB2_FROM_INTERNET "Download and use libb2 from the Internet" OFF)
find_package(libb2 0.98 REQUIRED)
#
-# special flags
+# Special flags
#
-# Note: cppcheck will scan everything after this point. Zstd and libb2 are above
+# Note: Cppcheck will scan everything after this point. zstd and libb2 are above
# so they don't get scanned.
#
include(CodeAnalysis)
option(ENABLE_TRACING "Enable possibility to use internal ccache tracing" OFF)
#
-# ccache_lib
+# Source code
#
add_subdirectory(src)
#
-# ccache
+# ccache executable
#
add_executable(ccache src/main.cpp)
-target_link_libraries(ccache PRIVATE standard_settings standard_warnings
- ccache_lib)
+target_link_libraries(ccache PRIVATE standard_settings standard_warnings ccache_lib)
+#
+# Documentation
+#
add_subdirectory(doc)
#
-# installation
+# Installation
#
include(GNUInstallDirs)
install(TARGETS ccache DESTINATION ${CMAKE_INSTALL_BINDIR})
#
-# packaging
+# Packaging
#
include(CCachePackConfig)
#
-# test and unittest
+# Tests
#
-option(ENABLE_TESTING "Enable Tests" ON)
+option(ENABLE_TESTING "Enable tests" ON)
if(ENABLE_TESTING)
enable_testing()
add_subdirectory(unittest)
add_subdirectory(test)
- # Note: VERSION_GREATER_EQUAL requires cmake 3.17
+ # Note: VERSION_GREATER_EQUAL requires CMake 3.17
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.17")
list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
endif()
- # Add 'check' target which will compile & run tests
+ # Add "check" target which compiles and runs tests.
+ set(
+ check_command
+ ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure)
if(CMAKE_CONFIGURATION_TYPES)
- add_custom_target(
- check
- COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process
- --output-on-failure --build-config "$<CONFIGURATION>"
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- DEPENDS ccache unittest)
- else()
- add_custom_target(
- check
- COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process
- --output-on-failure
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- DEPENDS ccache unittest)
+ list(APPEND check_command --build-config "$<CONFIGURATION>")
endif()
+ add_custom_target(
+ check
+ COMMAND ${check_command}
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ DEPENDS ccache unittest)
endif()
#
-# Special formatting targets. You can also run the scripts without cmake/make!
+# Special formatting targets
#
-
-find_program(CLANG_FORMAT_EXE NAMES "clang-format"
- DOC "Path to clang-format executable")
-mark_as_advanced(CLANG_FORMAT_EXE) # don't show in ccmake
+find_program(
+ CLANG_FORMAT_EXE
+ NAMES "clang-format"
+ DOC "Path to clang-format executable.")
+mark_as_advanced(CLANG_FORMAT_EXE) # Don't show in CMake UIs
if(NOT CLANG_FORMAT_EXE)
- message(WARNING "clang-format not found.")
+ message(WARNING "clang-format not found")
else()
add_custom_target(
format
add_custom_target(
check_format
COMMAND misc/check_format.sh
- COMMENT "Checking correctly formatted code"
+ COMMENT "Checking code formatting"
USES_TERMINAL
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
-# Note: this is part of CMakeLists.txt file, not to be confused with
-# CPackConfig.cmake
+# Note: This is part of CMakeLists.txt file, not to be confused with
+# CPackConfig.cmake.
-find_program(NINJA_EXE NAMES "ninja" DOC "Path to ninja executable")
-mark_as_advanced(NINJA_EXE) # don't show in ccmake
+find_program(NINJA_EXE NAMES "ninja" DOC "Path to Ninja executable")
+mark_as_advanced(NINJA_EXE) # Don't show in CMake UIs
if(NINJA_EXE)
set(CPACK_CMAKE_GENERATOR "Ninja")
else()
set(CPACK_CMAKE_GENERATOR "Unix Makefiles")
endif()
-# make obvious which version is used
+# Make it obvious which version is used.
set(CMAKE_DEBUG_POSTFIX "-d")
if(${CMAKE_VERSION} VERSION_LESS "3.9")
set(CPACK_PACKAGE_DESCRIPTION "${CMAKE_PROJECT_DESCRIPTION}")
endif()
-# from GenerateVersionFile.cmake
+# From GenerateVersionFile.cmake.
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_VERBATIM_VARIABLES ON)
set(CPACK_SOURCE_GENERATOR "TGZ")
-# Default includes build directory, so improve it: Include buildenv, but exclude
-# other build directories like /build/, /build-* and /build_*
list(APPEND CPACK_SOURCE_IGNORE_FILES "^${CMAKE_SOURCE_DIR}/\\.git")
-list(APPEND CPACK_SOURCE_IGNORE_FILES "^${CMAKE_SOURCE_DIR}/build[\\-_/]")
+list(APPEND CPACK_SOURCE_IGNORE_FILES "^${CMAKE_SOURCE_DIR}/build[-_/]")
list(APPEND CPACK_SOURCE_IGNORE_FILES "^${CMAKE_BINARY_DIR}")
set(CPACK_PACKAGE_FILE_NAME "ccache-binary")
message(WARNING "CppCheck requires cmake 3.10")
else()
find_program(CPPCHECK_EXE cppcheck)
- mark_as_advanced(CPPCHECK_EXE) # don't show in ccmake
+ mark_as_advanced(CPPCHECK_EXE) # Don't show in CMake UIs
if(CPPCHECK_EXE)
set(CMAKE_CXX_CPPCHECK
${CPPCHECK_EXE}
-# Set a default build type if none was specified
+# Set a default build type if none was specified.
-if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
- # Default to Release for zip builds and Debug for git builds
- if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
- set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE)
- else()
- set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build."
- FORCE)
- endif()
- message(
- STATUS
- "Setting CMAKE_BUILD_TYPE to '${CMAKE_BUILD_TYPE}' as none was specified."
- )
+if(CMAKE_BUILD_TYPE OR CMAKE_CONFIGURATION_TYPES)
+ return()
+endif()
- # Set the possible values of build type for ccmake
- set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
- "MinSizeRel" "RelWithDebInfo")
+# Default to Release for end user builds (from source archive) and Debug for
+# development builds (in a Git repository).
+if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
+ set(
+ CMAKE_BUILD_TYPE "Debug"
+ CACHE STRING "Choose the type of build." FORCE)
+else()
+ set(
+ CMAKE_BUILD_TYPE "Release"
+ CACHE STRING "Choose the type of build." FORCE)
endif()
+message(
+ STATUS
+ "Setting CMAKE_BUILD_TYPE to ${CMAKE_BUILD_TYPE} as none was specified."
+)
+
+# Set the possible values of build type for CMake UIs.
+set_property(
+ CACHE CMAKE_BUILD_TYPE
+ PROPERTY
+ STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
if(NOT EXISTS "${libb2_dir}.tar.gz")
file(DOWNLOAD "${libb2_url}" "${libb2_dir}.tar.gz")
endif()
- execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${libb2_dir}.tar.gz"
- WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -E tar xf "${libb2_dir}.tar.gz"
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
file(
WRITE "${libb2_dir}/src/config.h.cmake.in"
[=[
- /* Define if you have the `explicit_bzero' function. */
- #cmakedefine HAVE_EXPLICIT_BZERO
- /* Define if you have the `explicit_memset' function. */
- #cmakedefine HAVE_EXPLICIT_MEMSET
- /* Define if you have the `memset' function. */
- #cmakedefine HAVE_MEMSET
- /* Define if you have the `memset_s' function. */
- #cmakedefine HAVE_MEMSET_S
- ]=])
-
- file(
- WRITE "${libb2_dir}/src/CMakeLists.txt"
- [=[
- project(libb2 C)
-
- include(CheckFunctionExists)
- foreach(func IN ITEMS
- explicit_bzero
- explicit_memset
- memset
- memset_s
- )
- string(TOUPPER ${func} func_var)
- set(func_var HAVE_${func_var})
- check_function_exists(${func} ${func_var})
- endforeach()
-
- configure_file(config.h.cmake.in config.h)
- set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
- add_library(libblake2b_ref STATIC blake2b-ref.c blake2s-ref.c)
- target_compile_definitions(libblake2b_ref PRIVATE SUFFIX=_ref)
-
- function(add_libblake2b name suffix)
- add_library(${name} STATIC blake2b.c blake2s.c)
- target_compile_definitions(${name} PRIVATE ${suffix})
- target_compile_options(${name} PRIVATE ${ARGN})
- endfunction()
-
- add_libblake2b(libblake2b_sse2 SUFFIX=_sse2 -msse2)
- add_libblake2b(libblake2b_ssse3 SUFFIX=_ssse3 -msse2 -mssse3)
- add_libblake2b(libblake2b_sse41 SUFFIX=_sse41 -msse2 -mssse3 -msse4.1)
- add_libblake2b(libblake2s_avx SUFFIX=_avx -msse2 -mssse3 -msse4.1 -mavx)
- add_libblake2b(libblake2b_xop SUFFIX=_xop -msse2 -mssse3 -msse4.1 -mavx -mxop)
-
- add_library(libb2 STATIC blake2-dispatch.c)
- target_link_libraries(libb2
- PUBLIC
- libblake2b_ref libblake2b_sse2 libblake2b_ssse3
- libblake2b_sse41 libblake2s_avx libblake2b_xop
- )
- ]=])
+/* Define if you have the `explicit_bzero' function. */
+#cmakedefine HAVE_EXPLICIT_BZERO
+/* Define if you have the `explicit_memset' function. */
+#cmakedefine HAVE_EXPLICIT_MEMSET
+/* Define if you have the `memset' function. */
+#cmakedefine HAVE_MEMSET
+/* Define if you have the `memset_s' function. */
+#cmakedefine HAVE_MEMSET_S
+]=])
+
+ file(READ "cmake/Libb2CMakeLists.txt" libb2_cmakelists)
+ file(WRITE "${libb2_dir}/src/CMakeLists.txt" "${libb2_cmakelists}")
add_subdirectory("${libb2_dir}/src" "${libb2_build}" EXCLUDE_FROM_ALL)
add_library(libb2::libb2 ALIAS libb2)
- set_target_properties(libb2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
- "${libb2_dir}/src")
+ set_target_properties(
+ libb2
+ PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${libb2_dir}/src")
set(libb2_FOUND TRUE)
else()
add_library(libb2::libb2 UNKNOWN IMPORTED)
set_target_properties(
libb2::libb2
- PROPERTIES IMPORTED_LOCATION "${LIBB2_LIBRARY}"
- INTERFACE_INCLUDE_DIRECTORIES "${LIBB2_INCLUDE_DIR}")
+ PROPERTIES
+ IMPORTED_LOCATION "${LIBB2_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${LIBB2_INCLUDE_DIR}")
endif()
include(FeatureSummary)
set_package_properties(
- libb2 PROPERTIES URL "http://blake2.net/"
+ libb2
+ PROPERTIES
+ URL "http://blake2.net/"
DESCRIPTION "C library providing BLAKE2b, BLAKE2s, BLAKE2bp, BLAKE2sp")
if(USE_LIBZSTD_FROM_INTERNET)
# Although ${zstd_FIND_VERSION} was requested, let's download a newer version.
- # Note: structure has changed in 1.3.0, download supports only 1.3.0 and
- # newer.
+ # Note: The directory structure has changed in 1.3.0; we only support 1.3.0
+ # and newer.
set(zstd_version "1.4.4")
set(zstd_url https://github.com/facebook/zstd/archive/v${zstd_version}.tar.gz)
file(DOWNLOAD "${zstd_url}" "${zstd_dir}.tar.gz")
endif()
- execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${zstd_dir}.tar.gz"
- WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -E tar xf "${zstd_dir}.tar.gz"
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
set(ZSTD_BUILD_SHARED OFF)
add_subdirectory("${zstd_dir}/build/cmake" "${zstd_build}" EXCLUDE_FROM_ALL)
add_library(ZSTD::ZSTD ALIAS libzstd_static)
- set_target_properties(libzstd_static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
- "${zstd_dir}/lib")
+ set_target_properties(
+ libzstd_static
+ PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${zstd_dir}/lib")
set(zstd_FOUND TRUE)
else()
add_library(ZSTD::ZSTD UNKNOWN IMPORTED)
set_target_properties(
- ZSTD::ZSTD PROPERTIES IMPORTED_LOCATION "${ZSTD_LIBRARY}"
- INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIR}")
+ ZSTD::ZSTD
+ PROPERTIES
+ IMPORTED_LOCATION "${ZSTD_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIR}")
endif()
include(FeatureSummary)
set_package_properties(
- zstd PROPERTIES URL "https://facebook.github.io/zstd"
+ zstd
+ PROPERTIES
+ URL "https://facebook.github.io/zstd"
DESCRIPTION "Zstandard - Fast real-time compression algorithm")
-# Determines VERSION from git. See also VERSION_ERROR and VERSION_DIRTY.
+# Determines VERSION from Git. See also VERSION_ERROR and VERSION_DIRTY.
function(get_version_from_git)
find_package(Git)
if(NOT GIT_FOUND)
--- /dev/null
+project(libb2 C)
+
+include(CheckFunctionExists)
+foreach(func IN ITEMS explicit_bzero explicit_memset memset memset_s)
+ string(TOUPPER ${func} func_var)
+ set(func_var HAVE_${func_var})
+ check_function_exists(${func} ${func_var})
+endforeach()
+
+configure_file(config.h.cmake.in config.h)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_library(libblake2b_ref STATIC blake2b-ref.c blake2s-ref.c)
+target_compile_definitions(libblake2b_ref PRIVATE SUFFIX=_ref)
+
+function(add_libblake2b name suffix)
+ add_library(${name} STATIC blake2b.c blake2s.c)
+ target_compile_definitions(${name} PRIVATE ${suffix})
+ target_compile_options(${name} PRIVATE ${ARGN})
+endfunction()
+
+add_libblake2b(libblake2b_sse2 SUFFIX=_sse2 -msse2)
+add_libblake2b(libblake2b_ssse3 SUFFIX=_ssse3 -msse2 -mssse3)
+add_libblake2b(libblake2b_sse41 SUFFIX=_sse41 -msse2 -mssse3 -msse4.1)
+add_libblake2b(libblake2s_avx SUFFIX=_avx -msse2 -mssse3 -msse4.1 -mavx)
+add_libblake2b(libblake2b_xop SUFFIX=_xop -msse2 -mssse3 -msse4.1 -mavx -mxop)
+
+add_library(libb2 STATIC blake2-dispatch.c)
+target_link_libraries(
+ libb2
+ PUBLIC
+ libblake2b_ref libblake2b_sse2 libblake2b_ssse3 libblake2b_sse41
+ libblake2s_avx libblake2b_xop)
-# This file provides a special target 'standard_settings' which shall be linked
-# privately by all other targets.
+# This file provides a special "standard_settings" target which is supposed to
+# be linked privately by all other targets.
add_library(standard_settings INTERFACE)
-# Not supported in cmake 3.4: target_compile_features(project_options INTERFACE
+# Not supported in CMake 3.4: target_compile_features(project_options INTERFACE
# c_std_11 cxx_std_11)
-if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL
- "Clang")
- option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" FALSE)
+if(CMAKE_CXX_COMPILER_ID MATCHES "^GNU|Clang$")
+ option(ENABLE_COVERAGE "Enable coverage reporting for GCC/Clang" FALSE)
if(ENABLE_COVERAGE)
target_compile_options(standard_settings INTERFACE --coverage -O0 -g)
target_link_libraries(standard_settings INTERFACE --coverage)
list(APPEND SANITIZERS "memory")
endif()
- option(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
- "Enable undefined behavior sanitizer" FALSE)
+ option(
+ ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
+ "Enable undefined behavior sanitizer"
+ FALSE)
if(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR)
list(APPEND SANITIZERS "undefined")
endif()
if(SANITIZERS)
string(REPLACE ";" " " LIST_OF_SANITIZERS "${SANITIZERS}")
- target_compile_options(standard_settings
- INTERFACE -fsanitize=${LIST_OF_SANITIZERS})
- target_link_libraries(standard_settings
- INTERFACE -fsanitize=${LIST_OF_SANITIZERS})
+ target_compile_options(
+ standard_settings
+ INTERFACE -fsanitize=${LIST_OF_SANITIZERS})
+ target_link_libraries(
+ standard_settings
+ INTERFACE -fsanitize=${LIST_OF_SANITIZERS})
endif()
endif()
-# This file provides a special target 'standard_warnings' which shall be linked
-# privately by all product and test code, but not by third_party code.
+# This file provides a special "standard_warnings" target which is supposed to
+# be linked privately by all product and test code, but not by third party code.
add_library(standard_warnings INTERFACE)
if(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/.git" OR DEFINED ENV{"CI"})
- # Enabled by default for builds based on git as this will prevent bad pull
- # requests to ccache repository. Also enabled in case of Travis builds
- # (Environment var CI is set).
+ # Enabled by default for development builds and CI builds.
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)
else()
- # Disabled by default so compilation doesn't fail with new compilers, just
- # because they produce a new warning.
+ # Disabled by default for end user builds so compilation doesn't fail with new
+ # compilers that may emit new warnings.
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" FALSE)
endif()
# check_cxx_compiler_flag caches the result, so a unique variable name is
# required for every flag to be checked.
#
-# * flag [in], e.g. XXX
-# * variable_name_of_variable_name [in], e.g. "TEMP". This is the variable that
-# "HAS_XXX" will be written to.
-function(generate_unique_has_flag_variable_name flag
- variable_name_of_variable_name)
- string(REGEX REPLACE "[=-]" "_" variable_name "${flag}")
- string(TOUPPER "${variable_name}" variable_name)
- set(${variable_name_of_variable_name} "HAS_${variable_name}" PARENT_SCOPE)
+# Parameters:
+#
+# * flag [in], e.g. FLAG
+# * var_name_of_var_name [in], e.g. "TEMP". This is the variable that "HAS_FLAG"
+# will be written to.
+function(generate_unique_has_flag_var_name flag var_name_of_var_name)
+ string(REGEX REPLACE "[=-]" "_" var_name "${flag}")
+ string(TOUPPER "${var_name}" var_name)
+ set(${var_name_of_var_name} "HAS_${var_name}" PARENT_SCOPE)
endfunction()
function(add_target_compile_flag_if_supported_ex target flag alternative_flag)
# has_flag will contain "HAS_$flag" so each flag gets a unique HAS variable.
- generate_unique_has_flag_variable_name("${flag}" "has_flag")
+ generate_unique_has_flag_var_name("${flag}" "has_flag")
- # Instead of passing "has_flag" this is passing the content of has_flag.
+ # Instead of passing "has_flag" this passes the content of has_flag.
check_cxx_compiler_flag("${flag}" "${has_flag}")
- # If the variable named in has_flag is true, compiler supports the cxx flag.
if(${${has_flag}})
target_compile_options(${target} INTERFACE "${flag}")
elseif("${alternative_flag}")
endif()
endfunction()
-# ToDo: Is there a better way to private an optional third argument?
+# TODO: Is there a better way to provide an optional third argument?
macro(add_target_compile_flag_if_supported target flag)
add_target_compile_flag_if_supported_ex("${target}" "${flag}" "")
endmacro()
-# Several standard warnings disabled for now so no code change is required as
-# part of CMake-Switch commit.
set(CLANG_GCC_WARNINGS
-Wall
-Wextra
-Wunused
-Woverloaded-virtual
-Wpedantic
- # To be enabled in the future:
- #
- # * -Wshadow
- # * -Wold-style-cast
- # * -Wconversion
- # * -Wsign-conversion
- # * -Wnull-dereference
- # * -Wformat=2
+
+ # Candidates for enabling in the future:
+ # -Wshadow
+ # -Wold-style-cast
+ # -Wconversion
+ # -Wsign-conversion
+ # -Wnull-dereference
+ # -Wformat=2
)
-# Tested separately as this is not supported by clang 3.4
+# Tested separately as this is not supported by Clang 3.4.
add_target_compile_flag_if_supported(standard_warnings "-Wdouble-promotion")
if(WARNINGS_AS_ERRORS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0)
- set(CLANG_GCC_WARNINGS ${CLANG_GCC_WARNINGS} -Qunused-arguments -Wno-error=unreachable-code)
+ set(
+ CLANG_GCC_WARNINGS
+ ${CLANG_GCC_WARNINGS}
+ -Qunused-arguments
+ -Wno-error=unreachable-code)
endif()
target_compile_options(
standard_warnings
- INTERFACE ${CLANG_GCC_WARNINGS}
- -Weverything
- -Wno-c++98-compat-pedantic
- -Wno-c++98-compat
- -Wno-constexpr-not-const
- -Wno-conversion
- -Wno-disabled-macro-expansion
- -Wno-documentation-unknown-command
- -Wno-error=reserved-id-macro # libb2 blake2.h
- -Wno-exit-time-destructors
- -Wno-format-nonliteral
- -Wno-global-constructors
- -Wno-implicit-fallthrough
- -Wno-padded
- -Wno-shorten-64-to-32
- -Wno-sign-conversion
- -Wno-weak-vtables
- -Wno-old-style-cast)
-
- # If compiler supports shadow-field-in-constructor, disable only that.
+ INTERFACE
+ ${CLANG_GCC_WARNINGS}
+ -Weverything
+ -Wno-c++98-compat-pedantic
+ -Wno-c++98-compat
+ -Wno-constexpr-not-const
+ -Wno-conversion
+ -Wno-disabled-macro-expansion
+ -Wno-documentation-unknown-command
+ -Wno-error=reserved-id-macro # libb2 blake2.h
+ -Wno-exit-time-destructors
+ -Wno-format-nonliteral
+ -Wno-global-constructors
+ -Wno-implicit-fallthrough
+ -Wno-padded
+ -Wno-shorten-64-to-32
+ -Wno-sign-conversion
+ -Wno-weak-vtables
+ -Wno-old-style-cast)
+
+ # If compiler supports -Wshadow-field-in-constructor, disable only that.
# Otherwise disable shadow.
add_target_compile_flag_if_supported_ex(
standard_warnings "-Wno-shadow-field-in-constructor" "-Wno-shadow")
# Disable C++20 compatibility for now.
add_target_compile_flag_if_supported(standard_warnings "-Wno-c++2a-compat")
- # If compiler supports these warnings, they have to be disabled for now.
- add_target_compile_flag_if_supported(standard_warnings
- "-Wno-zero-as-null-pointer-constant")
- add_target_compile_flag_if_supported(standard_warnings
- "-Wno-undefined-func-template")
- add_target_compile_flag_if_supported(standard_warnings
- "-Wno-return-std-move-in-c++11")
+ # If compiler supports these warnings they have to be disabled for now.
+ add_target_compile_flag_if_supported(
+ standard_warnings "-Wno-zero-as-null-pointer-constant")
+ add_target_compile_flag_if_supported(
+ standard_warnings "-Wno-undefined-func-template")
+ add_target_compile_flag_if_supported(
+ standard_warnings "-Wno-return-std-move-in-c++11")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(
standard_warnings
INTERFACE ${CLANG_GCC_WARNINGS}
-
- -Wlogical-op # warn about logical operations being used where bitwise were probably wanted.
-
- #
- # To be enabled in the future:
- #
- # * -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
- # * -Wuseless-cast # warn if you perform a cast to the same type
+ # Warn about logical operations being used where bitwise were probably
+ # wanted.
+ -Wlogical-op
+
+ # Candidates for enabling in the future:
+ # -Wduplicated-cond
+ # -Wduplicated-branches
+ # -Wuseless-cast
)
- # Exact version or reason unknown, discovered in Ubuntu 14 docker test with gcc 4.8.4
+ # TODO: Exact version or reason unknown, discovered in Ubuntu 14 Docker test
+ # with GCC 4.8.4
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.5)
- add_target_compile_flag_if_supported(standard_warnings "-Wno-missing-field-initializers")
- add_target_compile_flag_if_supported(standard_warnings "-Wno-unused-variable")
+ add_target_compile_flag_if_supported(
+ standard_warnings "-Wno-missing-field-initializers")
+ add_target_compile_flag_if_supported(
+ standard_warnings "-Wno-unused-variable")
endif()
endif()
+find_program(ASCIIDOC_EXE asciidoc)
+mark_as_advanced(ASCIIDOC_EXE) # Don't show in CMake UIs
-find_program (ASCIIDOC_EXE asciidoc)
-mark_as_advanced(ASCIIDOC_EXE) # don't show in ccmake
-if (NOT ASCIIDOC_EXE)
- message (WARNING "Could not find asciidoc: documentation & manpage will not be generated")
+if(NOT ASCIIDOC_EXE)
+ message(WARNING "Could not find asciidoc; documentation will not be generated")
else()
#
- # documentation
+ # Documentation
#
add_custom_target(documentation)
- function(generate_html in out)
- add_custom_command (
+ function(generate_html adoc_file)
+ string(REGEX REPLACE "\.adoc$" ".html" html_file "${adoc_file}")
+ add_custom_command(
TARGET documentation
- COMMAND ${ASCIIDOC_EXE} -o "${CMAKE_BINARY_DIR}/${out}" -a revnumber="${VERSION}" -a toc -b xhtml11 "${CMAKE_SOURCE_DIR}/${in}"
- BYPRODUCTS "${out}"
+ COMMAND
+ ${ASCIIDOC_EXE}
+ -o "${CMAKE_BINARY_DIR}/${html_file}"
+ -a revnumber="${VERSION}"
+ -a toc
+ -b xhtml11
+ "${CMAKE_SOURCE_DIR}/${adoc_file}"
+ BYPRODUCTS "${html_file}"
)
endfunction()
- add_custom_command (
+ add_custom_command(
TARGET documentation
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/doc"
BYPRODUCTS "doc"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
- generate_html(LICENSE.adoc LICENSE.html)
- generate_html(doc/AUTHORS.adoc doc/AUTHORS.html)
- generate_html(doc/MANUAL.adoc doc/MANUAL.html)
- generate_html(doc/NEWS.adoc doc/NEWS.html)
+ generate_html(LICENSE.adoc)
+ generate_html(doc/AUTHORS.adoc)
+ generate_html(doc/MANUAL.adoc)
+ generate_html(doc/NEWS.adoc)
#
- # manpage
+ # Man page
#
-
- find_program (A2X_EXE a2x)
- mark_as_advanced(A2X_EXE) # don't show in ccmake
- if (NOT A2X_EXE)
- message (WARNING "Could not find a2x: manpage will not be generated")
+ find_program(A2X_EXE a2x)
+ mark_as_advanced(A2X_EXE) # Don't show in CMake UIs
+ if(NOT A2X_EXE)
+ message(WARNING "Could not find a2x; man page will not be generated")
else()
add_custom_target(manpage)
- # MANUAL.adoc -> MANUAL.xml -> MANUAL manpage
- add_custom_command (
- TARGET manpage
- COMMAND ${ASCIIDOC_EXE} -o - -a revnumber=${VERSION} -d manpage -b docbook "${CMAKE_SOURCE_DIR}/doc/MANUAL.adoc" | perl -pe 's!<literal>\(.*?\)</literal>!<emphasis role="strong">\\1</emphasis>!g' > "${CMAKE_BINARY_DIR}/MANUAL.xml"
- BYPRODUCTS "${CMAKE_BINARY_DIR}/MANUAL.xml"
- )
-
- add_custom_command (
- TARGET manpage
- COMMAND a2x --doctype manpage --format manpage "${CMAKE_BINARY_DIR}/MANUAL.xml"
- BYPRODUCTS ccache.1
- )
+ # MANUAL.adoc -> MANUAL.xml -> man page
+ add_custom_command(
+ TARGET manpage
+ COMMAND
+ ${ASCIIDOC_EXE}
+ -o -
+ -a revnumber=${VERSION}
+ -d manpage
+ -b docbook "${CMAKE_SOURCE_DIR}/doc/MANUAL.adoc"
+ | perl -pe 's!<literal>\(.*?\)</literal>!<emphasis role="strong">\\1</emphasis>!g'
+ >"${CMAKE_BINARY_DIR}/MANUAL.xml"
+ BYPRODUCTS "${CMAKE_BINARY_DIR}/MANUAL.xml"
+ )
+ add_custom_command(
+ TARGET manpage
+ COMMAND a2x --doctype manpage --format manpage "${CMAKE_BINARY_DIR}/MANUAL.xml"
+ BYPRODUCTS ccache.1
+ )
endif()
endif()
target_link_libraries(ccache_lib PRIVATE ws2_32 "psapi")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
- target_link_libraries(ccache_lib PRIVATE -static gcc stdc++ winpthread
- -dynamic)
+ target_link_libraries(
+ ccache_lib PRIVATE -static gcc stdc++ winpthread -dynamic)
else()
target_link_libraries(ccache_lib PRIVATE -static c++ -dynamic)
endif()
find_package(Threads REQUIRED)
target_link_libraries(
- ccache_lib PRIVATE standard_settings standard_warnings ZSTD::ZSTD
- libb2::libb2 Threads::Threads third_party_lib)
+ ccache_lib
+ PRIVATE standard_settings standard_warnings ZSTD::ZSTD libb2::libb2
+ Threads::Threads third_party_lib)
-# There is currently no separate interface directory.
target_include_directories(ccache_lib PRIVATE ${CMAKE_BINARY_DIR} .)
add_subdirectory(third_party)
target_sources(third_party_lib PRIVATE minitrace.c)
endif()
-# Treat third party headers as system files. (No warning from those headers)
-target_include_directories(third_party_lib PRIVATE ${CMAKE_BINARY_DIR} . SYSTEM
- INTERFACE .)
+# Treat third party headers as system files (no warning for those headers).
+target_include_directories(
+ third_party_lib
+ PRIVATE ${CMAKE_BINARY_DIR} . SYSTEM INTERFACE .)
target_link_libraries(third_party_lib PRIVATE standard_settings)
-# third_party (for now) has way fewer compiler warnings enabled than the rest of
-# the code.
-
-# These warnings are enabled by default even without e.g. -Wall. But (for now)
-# we don't want even them in third_party.
+# These warnings are enabled by default even without e.g. -Wall, but we don't
+# want them in third_party.
target_compile_options(
third_party_lib
- PRIVATE $<$<COMPILE_LANGUAGE:C>:-Wno-implicit-function-declaration
- -Wno-int-conversion>)
+ PRIVATE
+ $<$<COMPILE_LANGUAGE:C>:-Wno-implicit-function-declaration
+ -Wno-int-conversion>)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_options(third_party_lib
- PRIVATE $<$<COMPILE_LANGUAGE:C>:-Wno-attributes>)
+ target_compile_options(
+ third_party_lib
+ PRIVATE $<$<COMPILE_LANGUAGE:C>:-Wno-attributes>)
endif()
# The headers are included from the rest of the project, so turn off warnings as
-# requried (for now).
+# required.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(third_party_lib INTERFACE -Wno-shadow)
endif()
function(addtest name)
- add_test(NAME "producttest.${name}"
+ add_test(
+ NAME "producttest.${name}"
COMMAND ${CMAKE_SOURCE_DIR}/test/run ${name}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
- set(
- environment
- CCACHE=${CMAKE_BINARY_DIR}/ccache
- EXIT_IF_SKIPPED=true
- )
+ set(environment CCACHE=${CMAKE_BINARY_DIR}/ccache EXIT_IF_SKIPPED=true)
set_tests_properties(
"producttest.${name}"
PROPERTIES
test_hashutil.cpp
test_legacy_util.cpp)
-target_link_libraries(unittest PRIVATE standard_settings standard_warnings
- ccache_lib)
+target_link_libraries(
+ unittest
+ PRIVATE standard_settings standard_warnings ccache_lib)
target_include_directories(unittest PRIVATE ${CMAKE_BINARY_DIR} . ../src)
-# add to ctest
add_test(NAME unittest COMMAND unittest)