]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Clean up CMake configuration
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 16 Jun 2020 19:09:48 +0000 (21:09 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 17 Jun 2020 07:16:37 +0000 (09:16 +0200)
15 files changed:
CMakeLists.txt
cmake/CCachePackConfig.cmake
cmake/CodeAnalysis.cmake
cmake/DefaultBuildType.cmake
cmake/Findlibb2.cmake
cmake/Findzstd.cmake
cmake/GenerateVersionFile.cmake
cmake/Libb2CMakeLists.txt [new file with mode: 0644]
cmake/StandardSettings.cmake
cmake/StandardWarnings.cmake
doc/CMakeLists.txt
src/CMakeLists.txt
src/third_party/CMakeLists.txt
test/CMakeLists.txt
unittest/CMakeLists.txt

index 978b949ea5714e41f728a3d1e64d0ded577b857b..07fb7a6280d48561c9288d87deac3928f3739e48 100644 (file)
@@ -1,8 +1,3 @@
-# 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)
@@ -16,7 +11,7 @@ set(CMAKE_C_STANDARD 99)
 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")
@@ -35,91 +30,89 @@ include(GenerateConfigurationFile)
 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
@@ -131,7 +124,7 @@ else()
   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()
index 9a69eecc2784d0103f282b06347e1eb9bbbea900..343837d28c4ce520aca64d2e1a89a13a384b23e8 100644 (file)
@@ -1,22 +1,22 @@
-# 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)
@@ -29,10 +29,8 @@ endif()
 
 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")
index 927486da7be14387e414ba475b5e8f8898b9a4c5..ae31cd90a5884b2af357c55488edb1a596f10f46 100644 (file)
@@ -4,7 +4,7 @@ if(ENABLE_CPPCHECK)
     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}
index fb7a387aa9fdbd090dabd0483987bd7366975c8a..87b76474587fd6fe02bd59b13413ef29fca91065 100644 (file)
@@ -1,19 +1,27 @@
-# 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")
index 012a14c5f91dbfd2de2268f8ea8eeec3e9966a83..a68760704041a15d657d90d0b8bb5d7e0ff4a652 100644 (file)
@@ -14,69 +14,31 @@ if(USE_LIBB2_FROM_INTERNET)
   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()
@@ -92,11 +54,14 @@ 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")
index 758b6cc959fb26371c906fffdb311cbd37e28a8b..3aed656682751e35b910e604801de829957cb70e 100644 (file)
@@ -4,8 +4,8 @@ endif()
 
 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)
 
@@ -16,15 +16,18 @@ if(USE_LIBZSTD_FROM_INTERNET)
     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()
@@ -39,11 +42,15 @@ 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")
index 29d4e3b4a6d7055b56262a3dc2c80c16ad2dc5fc..6348ab1fc6cc979648f39c77bde7230e764f269a 100644 (file)
@@ -1,4 +1,4 @@
-# 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)
diff --git a/cmake/Libb2CMakeLists.txt b/cmake/Libb2CMakeLists.txt
new file mode 100644 (file)
index 0000000..bde206e
--- /dev/null
@@ -0,0 +1,33 @@
+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)
index c28bd718e6714fa6c1b89a74084a5629b54898f2..9ca91a2e1aab8ede7604b0bbd62ad1a816ec7ed6 100644 (file)
@@ -1,14 +1,13 @@
-# 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)
@@ -26,8 +25,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL
     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()
@@ -39,9 +40,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL
 
   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()
index 0edf577969cf411ba3d039aab39d52287209f35c..2e1b50970e9c2810e38bcb7abbd047713c8a866b 100644 (file)
@@ -1,15 +1,13 @@
-# 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()
 
@@ -18,24 +16,24 @@ include(CheckCXXCompilerFlag)
 # 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}")
@@ -43,13 +41,11 @@ function(add_target_compile_flag_if_supported_ex target flag 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
@@ -58,16 +54,16 @@ set(CLANG_GCC_WARNINGS
     -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)
@@ -76,31 +72,36 @@ endif()
 
 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")
@@ -108,33 +109,33 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
   # 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()
index 5117ff6307433a0bf23c1f5639a9ac4fbc909011..e9a1926ada5b282fe69b845078610ebb7c13f7ff 100644 (file)
@@ -1,56 +1,68 @@
+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()
index dc1ac78b0d582f8dea53f14f87bc28eab716580f..f7190cfb97a8a60f71b87233fc46ad381e304d78 100644 (file)
@@ -44,8 +44,8 @@ if(WIN32)
   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()
@@ -53,10 +53,10 @@ 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)
index b6beab919c98d4e8cc4ae44bdd5f1c6ad3b318eb..5c264a450fc15b549faadc03037583bf20bbb3d5 100644 (file)
@@ -3,28 +3,28 @@ if(ENABLE_TRACING)
   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()
index 996003ccbb12303c286172874dac0d51f1ac40e4..17c62e9a8a6cee527ea066106335142dd53e5ba1 100644 (file)
@@ -1,13 +1,10 @@
 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
index d1873310caa233de017e59e125be472706a6788a..7e34081658935ef77f890f12097fdccf82ed39e2 100644 (file)
@@ -21,10 +21,10 @@ add_executable(
   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)