Skip to content

Commit

Permalink
Merge pull request #28 from aminya/pch_headers_option
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Nov 22, 2021
2 parents 3fb2f69 + a368cb5 commit ecf6389
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ProjectOptions(
# ENABLE_INCLUDE_WHAT_YOU_USE
# ENABLE_COVERAGE
# ENABLE_PCH
# PCH_HEADERS
# ENABLE_DOXYGEN
# ENABLE_USER_LINKER
# ENABLE_BUILD_WITH_TIME_TRACE
Expand Down Expand Up @@ -95,6 +96,7 @@ It accepts the following named flags:

It gets the following named parameters (each accepting multiple values):

- `PCH_HEADERS`: the list of the headers to precompile
- `MSVC_WARNINGS`: Override the defaults for the MSVC warnings
- `CLANG_WARNINGS`: Override the defaults for the CLANG warnings
- `GCC_WARNINGS`: Override the defaults for the GCC warnings
Expand Down Expand Up @@ -166,6 +168,7 @@ ProjectOptions(
# ENABLE_INCLUDE_WHAT_YOU_USE
# ENABLE_COVERAGE
# ENABLE_PCH
# PCH_HEADERS
# ENABLE_DOXYGEN
# ENABLE_IPO
# ENABLE_USER_LINKER
Expand Down
23 changes: 12 additions & 11 deletions src/Index.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include("${ProjectOptions_SRC_DIR}/SystemLink.cmake")
# - ENABLE_COVERAGE: Enable coverage reporting for gcc/clang
# - ENABLE_CACHE: Enable cache if available
# - ENABLE_PCH: Enable Precompiled Headers
# - PCH_HEADERS: the list of the headers to precompile
# - ENABLE_CONAN: Use Conan for dependency management
# - ENABLE_DOXYGEN: Enable doxygen doc builds of source
# - ENABLE_IPO: Enable Interprocedural Optimization, aka Link Time Optimization (LTO)
Expand Down Expand Up @@ -58,7 +59,7 @@ macro(ProjectOptions)
ENABLE_SANITIZER_THREAD
ENABLE_SANITIZER_MEMORY)
set(oneValueArgs MSVC_WARNINGS CLANG_WARNINGS GCC_WARNINGS)
set(multiValueArgs CONAN_OPTIONS)
set(multiValueArgs PCH_HEADERS CONAN_OPTIONS)
cmake_parse_arguments(
ProjectOptions
"${options}"
Expand Down Expand Up @@ -143,16 +144,16 @@ macro(ProjectOptions)

# Very basic PCH example
if(${ProjectOptions_ENABLE_PCH})
# This sets a global PCH parameter, each project will build its own PCH, which is a good idea if any #define's change
#
# consider breaking this out per project as necessary
target_precompile_headers(
project_options
INTERFACE
<vector>
<string>
<map>
<utility>)
# This sets a global PCH parameter, each project will build its own PCH, which is a good idea
# if any #define's change consider breaking this out per project as necessary
if(NOT ProjectOptions_PCH_HEADERS)
set(ProjectOptions_PCH_HEADERS
<vector>
<string>
<map>
<utility>)
endif()
target_precompile_headers(project_options INTERFACE ${ProjectOptions_PCH_HEADERS})
endif()

if(${ProjectOptions_ENABLE_VCPKG})
Expand Down
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ProjectOptions(
# ENABLE_INCLUDE_WHAT_YOU_USE
# ENABLE_COVERAGE
# ENABLE_PCH
# PCH_HEADERS <Eigen/Dense> <fmt/core.h> <vector> <utility> <string> <string_view>
# ENABLE_DOXYGEN
# ENABLE_IPO
# ENABLE_USER_LINKER
Expand All @@ -39,6 +40,7 @@ ProjectOptions(
# ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
# ENABLE_SANITIZER_THREAD
# ENABLE_SANITIZER_MEMORY
# CLANG_WARNINGS "-Weverything"
)
# NOTE: project_options and project_warnings are defined inside ProjectOptions

Expand Down
10 changes: 5 additions & 5 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include <string_view>

// test c libraries
// #include <cassert>
// #include <cctype>
// #include <cstddef>
// #include <cstring>
// #include <cstdint>
#include <cassert>
#include <cctype>
#include <cstddef>
#include <cstring>
#include <cstdint>


int main() {
Expand Down

0 comments on commit ecf6389

Please sign in to comment.