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 8, 2024
1 parent 72d30e7 commit 524d8b9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")

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
2 changes: 2 additions & 0 deletions examples/joystick/Joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <string>
#include <unordered_map>

#include <cstdlib>


namespace
{
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 524d8b9

Please sign in to comment.