From f1d45fc8a77673929340c649955f62d9d38f8d3b Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Sun, 5 Sep 2021 19:49:09 +1000 Subject: [PATCH] Various CMake improvements Updated to MSVCToolpackVkV10 Updated CMakeLists to have Hints for find_package calls. Various other CMake improvements and C++ improvements. --- .gitignore | 9 +-- CMakeLists.txt | 14 +++- src/extraTest/Levels_test.cpp | 4 +- src/hg/FrontEnd/RunningGameScene.cpp | 2 - src/hg/FrontEnd/VulkanRenderer.h | 8 +-- .../SimpleConfiguredTriggerSystem.cpp | 4 +- src/hg/Util/StdHashCompare.h | 4 +- src/hg/Util/memory_pool.h | 1 + src/hg/Util/multi_thread_allocator.h | 1 + src/hg/Util/scalable_allocator.h | 7 +- unitysrc/CMakeLists.txt | 69 +++++++++++++------ 11 files changed, 79 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index b34d9ec5..9fd5a66f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ /ext/bin -/ext/boost -/ext/glfw -/ext/GSL +/ext/Boost +/ext/glfw3 +/ext/Microsoft.GSL /ext/SFML -/ext/tbb +/ext/TBB +/ext/Contents.txt /ide/msvc2015/HourglassII/x64 /ide/msvc2015/HourglassII/HourglassII/x64 diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a594f0e..cc552fa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,13 @@ -cmake_minimum_required (VERSION 3.12) +cmake_minimum_required(VERSION 3.20...3.20 FATAL_ERROR) -project ("HourglassII") -add_subdirectory ("unitysrc") +project( + "HourglassII" + LANGUAGES CXX +) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +add_subdirectory("unitysrc") diff --git a/src/extraTest/Levels_test.cpp b/src/extraTest/Levels_test.cpp index 8b35b480..b18aa2a4 100644 --- a/src/extraTest/Levels_test.cpp +++ b/src/extraTest/Levels_test.cpp @@ -79,7 +79,7 @@ bool testLevelsLoad() { //TODO -- make this test only run in an "expensive tests" run (rather than hardcoding 'test_levels_load = false') //TODO -- get rid of hard-coded progress display. bool testPassed = true; - for (auto const entry : boost::make_iterator_range(boost::filesystem::directory_iterator("levels/"), + for (auto const& entry : boost::make_iterator_range(boost::filesystem::directory_iterator("levels/"), boost::filesystem::directory_iterator())) { if (is_directory(entry.status()) @@ -128,7 +128,7 @@ bool testLevels() { //TODO -- make this test only run in an "expensive tests" run //TODO -- get rid of hard-coded progress display. bool testPassed = true; - for (auto const entry : boost::make_iterator_range(boost::filesystem::directory_iterator("levels/"), + for (auto const& entry : boost::make_iterator_range(boost::filesystem::directory_iterator("levels/"), boost::filesystem::directory_iterator())) { ; diff --git a/src/hg/FrontEnd/RunningGameScene.cpp b/src/hg/FrontEnd/RunningGameScene.cpp index 4a629243..85bfb884 100644 --- a/src/hg/FrontEnd/RunningGameScene.cpp +++ b/src/hg/FrontEnd/RunningGameScene.cpp @@ -51,8 +51,6 @@ #include -#include - #include #include diff --git a/src/hg/FrontEnd/VulkanRenderer.h b/src/hg/FrontEnd/VulkanRenderer.h index c0d50ed6..6dd158c8 100644 --- a/src/hg/FrontEnd/VulkanRenderer.h +++ b/src/hg/FrontEnd/VulkanRenderer.h @@ -73,10 +73,10 @@ namespace hg { class VulkanRenderer { public: VulkanRenderer() : - sceneMutex() - ,scene() - ,frameKeepAlives(MAX_FRAMES_IN_FLIGHT) - ,sceneKeepAlives() + sceneMutex() + ,scene() + ,frameKeepAlives(MAX_FRAMES_IN_FLIGHT) + ,sceneKeepAlives() {} void updateSwapChainData( VkRenderPass const renderPass, diff --git a/src/hg/PhysicsEngine/TriggerSystem/SimpleConfiguredTriggerSystem.cpp b/src/hg/PhysicsEngine/TriggerSystem/SimpleConfiguredTriggerSystem.cpp index 11074030..8db4f892 100644 --- a/src/hg/PhysicsEngine/TriggerSystem/SimpleConfiguredTriggerSystem.cpp +++ b/src/hg/PhysicsEngine/TriggerSystem/SimpleConfiguredTriggerSystem.cpp @@ -2003,7 +2003,7 @@ namespace hg { // Check persistence assert(proto->triggerID < std::size(triggerArrivals)); auto const &triggerArrival{triggerArrivals[proto->triggerID]}; - if (not (0 < std::size(triggerArrival) && triggerArrival[0] == 1)) { + if (! (0 < std::size(triggerArrival) && triggerArrival[0] == 1)) { exploded = true; active = false; return; @@ -2051,7 +2051,7 @@ namespace hg { void ElevatorFrameStateImpl::fillTrigger(mp::std::map> &outputTriggers) const { // Exploded elevators are -1, make sure that whatever modifies their trigger state keeps this in mind. - outputTriggers[proto->triggerID] = mt::std::vector{not exploded}; + outputTriggers[proto->triggerID] = mt::std::vector{! exploded}; } boost::optional ElevatorFrameStateImpl::effect(Guy const &guy) { if (!active) { diff --git a/src/hg/Util/StdHashCompare.h b/src/hg/Util/StdHashCompare.h index d26d153a..0e430f84 100644 --- a/src/hg/Util/StdHashCompare.h +++ b/src/hg/Util/StdHashCompare.h @@ -6,11 +6,11 @@ namespace hg { template struct StdHashCompare final { - bool equal(T const &j, T const &k) const + static bool equal(T const &j, T const &k) { return std::equal_to()(j, k); } - std::size_t hash(T const &k) const + static std::size_t hash(T const &k) { return std::hash()(k); } diff --git a/src/hg/Util/memory_pool.h b/src/hg/Util/memory_pool.h index b0a50b74..34b3edeb 100644 --- a/src/hg/Util/memory_pool.h +++ b/src/hg/Util/memory_pool.h @@ -3,6 +3,7 @@ #include "hg/mt/std/vector" #include #include +#include #include namespace hg { diff --git a/src/hg/Util/multi_thread_allocator.h b/src/hg/Util/multi_thread_allocator.h index 8e4ef647..a25ea496 100644 --- a/src/hg/Util/multi_thread_allocator.h +++ b/src/hg/Util/multi_thread_allocator.h @@ -8,6 +8,7 @@ #include #include +#include #include #include "scalable_allocator.h" diff --git a/src/hg/Util/scalable_allocator.h b/src/hg/Util/scalable_allocator.h index a660ec59..9d011379 100644 --- a/src/hg/Util/scalable_allocator.h +++ b/src/hg/Util/scalable_allocator.h @@ -1,5 +1,6 @@ #ifndef HG_TBB_ALLOCATOR_H #define HG_TBB_ALLOCATOR_H +#include #include #include namespace hg { @@ -26,7 +27,7 @@ class tbb_scalable_allocator typedef typename tbb_alloc::reference reference; typedef typename tbb_alloc::const_reference const_reference; - pointer allocate(size_type n, void const *u = nullptr) { return alloc.allocate(n, u); } + pointer allocate(size_type n) { return alloc.allocate(n); } void deallocate(pointer p, size_type n) { alloc.deallocate(p, n); } size_type max_size() const { return alloc.max_size(); } @@ -56,8 +57,8 @@ class tbb_scalable_allocator typedef Alloc::type tbb_alloc; tbb_alloc alloc; public: - typedef tbb_alloc::pointer pointer; - typedef tbb_alloc::const_pointer const_pointer; + //typedef tbb_alloc::pointer pointer; + //typedef tbb_alloc::const_pointer const_pointer; typedef void *void_pointer; typedef void const *const_void_pointer; typedef tbb_alloc::value_type value_type; diff --git a/unitysrc/CMakeLists.txt b/unitysrc/CMakeLists.txt index 282f7993..272107f7 100644 --- a/unitysrc/CMakeLists.txt +++ b/unitysrc/CMakeLists.txt @@ -1,25 +1,55 @@ -cmake_minimum_required (VERSION 3.12) - -#set(SFML_DIR "${PROJECT_SOURCE_DIR}/ext/SFML/lib/cmake/SFML") #maybe - -set(CXXGSL_INCLUDE_DIRS "" CACHE FILEPATH "The location of the C++ Guidelines Support Library headers") +set(HOURGLASSII_EXT_DIR "${PROJECT_SOURCE_DIR}/ext") set(SFML_STATIC_LIBRARIES TRUE) -find_package(SFML 2.5.1 COMPONENTS graphics audio REQUIRED) +find_package( + SFML 2.5.1 + REQUIRED + COMPONENTS graphics audio + CONFIG + HINTS "${HOURGLASSII_EXT_DIR}" +) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) -find_package(Boost 1.72.0 COMPONENTS filesystem thread serialization REQUIRED) +find_package( + Boost 1.77.0 + REQUIRED + COMPONENTS headers filesystem thread serialization + CONFIG + HINTS "${HOURGLASSII_EXT_DIR}" +) -find_package(TBB REQUIRED) +find_package( + TBB 2020.3.0 #Latest is now oneAPI TBB 2021.3.0; Not using this yet because oneAPI TBB (v2020.1...2020.3) appears to be incompatible with C++20 mode on MSVC 2019 (v16.11.2) + REQUIRED + CONFIG + HINTS "${HOURGLASSII_EXT_DIR}" +) + +find_package( + glfw3 3.3.4 + REQUIRED + CONFIG + HINTS "${HOURGLASSII_EXT_DIR}" +) -find_package(glfw3 CONFIG REQUIRED) +find_package( + Microsoft.GSL 3.1.0 #Lastest is 3.1.0; but there are much more recent changes in the main branch of the git repository + REQUIRED + CONFIG + HINTS "${HOURGLASSII_EXT_DIR}" +) find_package(Vulkan REQUIRED) add_executable(HourglassII WIN32 MACOSX_BUNDLE) +set_target_properties(sfml-graphics sfml-audio sfml-system PROPERTIES + MAP_IMPORTED_CONFIG_MINSIZEREL Release + MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release +) + #TODO: Separate into Debug and Release, and per-platform config? target_compile_definitions(HourglassII PRIVATE @@ -43,10 +73,6 @@ target_include_directories(HourglassII PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../src/ ) -set_target_properties(HourglassII PROPERTIES - CXX_STANDARD 20 - CXX_STANDARD_REQUIRED ON) - target_sources(HourglassII PRIVATE ${CMAKE_CURRENT_LIST_DIR}/extraTest_UnitySrc.cpp @@ -72,19 +98,18 @@ target_compile_options(HourglassII /Zc:inline /Zc:throwingNew) -target_link_libraries(HourglassII sfml-graphics sfml-audio) -target_link_libraries(HourglassII Boost::headers Boost::filesystem Boost::thread Boost::serialization) -target_link_libraries(HourglassII TBB::tbb TBB::tbbmalloc) -target_link_libraries(HourglassII glfw) -target_link_libraries(HourglassII Vulkan::Vulkan) - -target_include_directories(HourglassII PRIVATE ${CXXGSL_INCLUDE_DIRS}) +target_link_libraries(HourglassII PRIVATE sfml-graphics sfml-audio) +target_link_libraries(HourglassII PRIVATE Boost::headers Boost::filesystem Boost::thread Boost::serialization) +target_link_libraries(HourglassII PRIVATE TBB::tbb TBB::tbbmalloc) +target_link_libraries(HourglassII PRIVATE glfw) +target_link_libraries(HourglassII PRIVATE Vulkan::Vulkan) +target_link_libraries(HourglassII PRIVATE Microsoft.GSL::GSL) set(GLSL_VALIDATOR "$ENV{VULKAN_SDK}/Bin/glslangValidator.exe") file(GLOB_RECURSE GLSL_SOURCE_FILES "${CMAKE_SOURCE_DIR}/shadersrc/*.glsl" - ) +) message(${GLSL_SOURCE_FILES}) @@ -105,7 +130,7 @@ endforeach() file(GLOB_RECURSE DATA_SOURCE_FILES "${CMAKE_SOURCE_DIR}/data/*" - ) +) STRING(LENGTH "${CMAKE_SOURCE_DIR}/" CMAKE_SOURCE_DIR_LEN)