Skip to content

Commit

Permalink
Various CMake improvements
Browse files Browse the repository at this point in the history
Updated to MSVCToolpackVkV10
Updated CMakeLists to have Hints for find_package calls.
Various other CMake improvements and C++ improvements.
  • Loading branch information
Mankarse committed Sep 5, 2021
1 parent 1c4e827 commit f1d45fc
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 44 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 2 additions & 2 deletions src/extraTest/Levels_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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()))
{
;
Expand Down
2 changes: 0 additions & 2 deletions src/hg/FrontEnd/RunningGameScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@

#include <fstream>

#include <boost/bind.hpp>

#include <cstddef>
#include <utility>

Expand Down
8 changes: 4 additions & 4 deletions src/hg/FrontEnd/VulkanRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2051,7 +2051,7 @@ namespace hg {

void ElevatorFrameStateImpl::fillTrigger(mp::std::map<std::size_t, mt::std::vector<int>> &outputTriggers) const {
// Exploded elevators are -1, make sure that whatever modifies their trigger state keeps this in mind.
outputTriggers[proto->triggerID] = mt::std::vector<int>{not exploded};
outputTriggers[proto->triggerID] = mt::std::vector<int>{! exploded};
}
boost::optional<Guy> ElevatorFrameStateImpl::effect(Guy const &guy) {
if (!active) {
Expand Down
4 changes: 2 additions & 2 deletions src/hg/Util/StdHashCompare.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace hg {
template <typename T>
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<T>()(j, k);
}
std::size_t hash(T const &k) const
static std::size_t hash(T const &k)
{
return std::hash<T>()(k);
}
Expand Down
1 change: 1 addition & 0 deletions src/hg/Util/memory_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "hg/mt/std/vector"
#include <memory>
#include <cassert>
#include <cstdint>

#include <tbb/scalable_allocator.h>
namespace hg {
Expand Down
1 change: 1 addition & 0 deletions src/hg/Util/multi_thread_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <boost/preprocessor/repetition.hpp>
#include <boost/preprocessor/punctuation/paren.hpp>

#include <cstdint>
#include <tbb/scalable_allocator.h>
#include "scalable_allocator.h"

Expand Down
7 changes: 4 additions & 3 deletions src/hg/Util/scalable_allocator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef HG_TBB_ALLOCATOR_H
#define HG_TBB_ALLOCATOR_H
#include <cstdint>
#include <tbb/scalable_allocator.h>
#include <utility>
namespace hg {
Expand All @@ -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(); }

Expand Down Expand Up @@ -56,8 +57,8 @@ class tbb_scalable_allocator<void>
typedef Alloc<void>::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;
Expand Down
69 changes: 47 additions & 22 deletions unitysrc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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})

Expand All @@ -105,7 +130,7 @@ endforeach()

file(GLOB_RECURSE DATA_SOURCE_FILES
"${CMAKE_SOURCE_DIR}/data/*"
)
)

STRING(LENGTH "${CMAKE_SOURCE_DIR}/" CMAKE_SOURCE_DIR_LEN)

Expand Down

0 comments on commit f1d45fc

Please sign in to comment.