]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Include config.h via command line instead of via system.h
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 30 May 2021 18:40:35 +0000 (20:40 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 30 May 2021 18:53:30 +0000 (20:53 +0200)
This makes the definitions in config.h available to all source code,
including third_party_lib. It’s also a first step towards not having to
include system.hpp and its libc headers from all files.

cmake/StandardSettings.cmake
cmake/config.h.in
src/system.hpp
src/third_party/CMakeLists.txt

index a0f0189c7d557154ae3fdf319f9f25740e8f12db..46854f3c00af9ce0cf76db2a3f245232f64034b5 100644 (file)
@@ -3,10 +3,12 @@
 
 add_library(standard_settings INTERFACE)
 
-# Not supported in CMake 3.4: target_compile_features(project_options INTERFACE
-# c_std_11 cxx_std_11)
-
 if(CMAKE_CXX_COMPILER_ID MATCHES "^GNU|(Apple)?Clang$")
+  target_compile_options(
+    standard_settings
+    INTERFACE -include ${CMAKE_BINARY_DIR}/config.h
+  )
+
   option(ENABLE_COVERAGE "Enable coverage reporting for GCC/Clang" FALSE)
   if(ENABLE_COVERAGE)
     target_compile_options(standard_settings INTERFACE --coverage -O0 -g)
@@ -50,5 +52,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "^GNU|(Apple)?Clang$")
   include(StdAtomic)
 
 elseif(MSVC)
-  target_compile_options(standard_settings INTERFACE /std:c++latest /Zc:preprocessor /Zc:__cplusplus /D_CRT_SECURE_NO_WARNINGS)
+  target_compile_options(standard_settings INTERFACE /FI ${CMAKE_BINARY_DIR}/config.h)
+
+  target_compile_options(
+    standard_settings
+    INTERFACE /std:c++latest /Zc:preprocessor /Zc:__cplusplus /D_CRT_SECURE_NO_WARNINGS
+  )
 endif()
index d10e16417f8f05bb42f8fb05897ee3c7c300dcf3..fe99e16d827318fe38449b7b6d38d8c3d0372475 100644 (file)
@@ -6,6 +6,11 @@
 #  endif
 #endif
 
+#ifdef __MINGW32__
+#  define __USE_MINGW_ANSI_STDIO 1
+#  define __STDC_FORMAT_MACROS 1
+#endif
+
 // For example for vasprintf under i686-w64-mingw32-g++-posix. The later
 // definition of _XOPEN_SOURCE disables certain features on Linux, so we need
 // _GNU_SOURCE to re-enable them (makedev, tm_zone).
index fa4bbf3e37d97ffd5ba39ab4afcd27d168c6c82e..b58119e35834fe8ede35183b070adbfb0c11c683 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2010-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#ifdef __MINGW32__
-#  define __USE_MINGW_ANSI_STDIO 1
-#  define __STDC_FORMAT_MACROS 1
-#endif
-
-#include "config.h"
-
 #ifdef HAVE_SYS_FILE_H
 #  include <sys/file.h>
 #endif
index 14dce921603f54d5a890b14a5522d5ca635895d9..54cd3b256354e86e7585a088710fbc911eb3619d 100644 (file)
@@ -10,12 +10,6 @@ if(WIN32)
   target_sources(third_party_lib PRIVATE win32/mktemp.c)
 endif ()
 
-if(MSVC)
-  target_compile_options(third_party_lib PRIVATE /FI ${CMAKE_BINARY_DIR}/config.h)
-else()
-  target_compile_options(third_party_lib PRIVATE -include ${CMAKE_BINARY_DIR}/config.h)
-endif()
-
 if(ENABLE_TRACING)
   target_sources(third_party_lib PRIVATE minitrace.c)
 endif()