Skip to content

Commit

Permalink
Improve PCH and enable PCH for Catch2 and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Feb 3, 2024
1 parent eb07e1e commit 05109fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")

# add an option for building the test suite
sfml_set_option(SFML_BUILD_TEST_SUITE FALSE BOOL "TRUE to build the SFML test suite, FALSE to ignore it")

if(SFML_BUILD_TEST_SUITE)
# this definition is used in the PCH file to speed up compilation of tests
# `add_definitions` must be called before `add_subdirectory`
add_definitions(-DSFML_BUILD_TEST_SUITE)
endif()

# add the subdirectories
add_subdirectory(src/SFML)

Expand Down Expand Up @@ -510,9 +519,6 @@ if(SFML_BUILD_EXAMPLES AND NOT SFML_OS_ANDROID)
add_subdirectory(examples)
endif()

# add an option for building the test suite
sfml_set_option(SFML_BUILD_TEST_SUITE FALSE BOOL "TRUE to build the SFML test suite, FALSE to ignore it")

# add an option for enabling coverage reporting
sfml_set_option(SFML_ENABLE_COVERAGE FALSE BOOL "TRUE to enable coverage reporting, FALSE to ignore it")

Expand Down
14 changes: 14 additions & 0 deletions src/SFML/PCH.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <SFML/System/Vector2.hpp>

#include <algorithm>
#include <array>
#include <chrono>
#include <filesystem>
#include <iostream>
Expand All @@ -62,3 +63,16 @@
#include <cstdint>
#include <cstdlib>
#include <cstring>


////////////////////////////////////////////////////////////
// Precompiled Headers (Test Suite Only)
////////////////////////////////////////////////////////////

#ifdef SFML_BUILD_TEST_SUITE

#include <catch2/catch_test_macros.hpp>

#include <map>

#endif
7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ set_target_properties(Catch2WithMain PROPERTIES EXPORT_COMPILE_COMMANDS OFF)
get_target_property(CATCH2_INCLUDE_DIRS Catch2 INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(Catch2 SYSTEM INTERFACE ${CATCH2_INCLUDE_DIRS})

# enable precompiled headers
if (SFML_ENABLE_PCH)
message(VERBOSE "enabling PCH for Catch2")
target_include_directories(Catch2 PRIVATE ${PROJECT_SOURCE_DIR}/src) # necessary to find `WindowsHeader.hpp` on Windows
target_precompile_headers(Catch2 PRIVATE ${PROJECT_SOURCE_DIR}/src/SFML/PCH.hpp)
endif()

add_library(sfml-test-main STATIC
TestUtilities/SystemUtil.hpp
TestUtilities/SystemUtil.cpp
Expand Down

0 comments on commit 05109fc

Please sign in to comment.