From 12a78c014720b73df5d64bc5ec5414293d6be16a Mon Sep 17 00:00:00 2001 From: Walther Zwart Date: Sun, 4 Feb 2018 21:05:33 +0100 Subject: [PATCH 1/4] Fixed google test dependency --- UnitTests/CMakeLists.txt | 31 ++++++------------------------- UnitTests/Main.cpp | 7 ------- 2 files changed, 6 insertions(+), 32 deletions(-) delete mode 100644 UnitTests/Main.cpp diff --git a/UnitTests/CMakeLists.txt b/UnitTests/CMakeLists.txt index 6acd571..2f29d2d 100644 --- a/UnitTests/CMakeLists.txt +++ b/UnitTests/CMakeLists.txt @@ -1,39 +1,20 @@ -# -# GTest -# +enable_testing() -set (GTEST_SDK_ROOT "C:/Users/Neurodancer/source/repos/googletest-release-1.8.0/googletest") +# google advises to compile gtest from source with the project +add_subdirectory("/usr/src/googletest/googletest" gtest) -set (GTEST_INCLUDE_DIRS - "${GTEST_SDK_ROOT}/include") - -set (GTEST_LIBRARY_DEBUG - "${GTEST_SDK_ROOT}/msvc/x64/Debug/gtestd.lib") -set (GTEST_LIBRARY_RELEASE - "${GTEST_SDK_ROOT}/msvc/x64/Release/gtest.lib") - - - -# -# Unit tests -# - -set (UNIT_TEST_SOURCES - Main.cpp +set (UNIT_TEST_SOURCES PointerContainerTests.cpp ShipTests.cpp VectorsTests.cpp) add_executable (UnitTests ${UNIT_TEST_SOURCES}) - -target_include_directories (UnitTests PRIVATE - ${GTEST_INCLUDE_DIRS}) +add_test (UnitTests UnitTests) target_link_libraries (UnitTests GameLib ${OPENGL_LIBRARIES} - debug ${GTEST_LIBRARY_DEBUG} - optimized ${GTEST_LIBRARY_RELEASE} + gtest_main ${ADDITIONAL_LIBRARIES}) if(MSVC) diff --git a/UnitTests/Main.cpp b/UnitTests/Main.cpp deleted file mode 100644 index d1be1ff..0000000 --- a/UnitTests/Main.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "gtest/gtest.h" - -int main(int argc, char** argv) -{ - testing::InitGoogleTest(&argc, argv); - RUN_ALL_TESTS(); -} \ No newline at end of file From 86723cd4f984a1e600bbbaf4e0e442de2db287a8 Mon Sep 17 00:00:00 2001 From: Walther Zwart Date: Sun, 4 Feb 2018 21:14:04 +0100 Subject: [PATCH 2/4] Made dependencies work on linux --- CMakeLists.txt | 68 ++++++-------------------------------- GameLib/CMakeLists.txt | 19 ++++------- ShipSandbox/CMakeLists.txt | 10 ++---- 3 files changed, 20 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10fff86..f3575f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,63 +14,16 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Release builds, just use the same library for both. #################################################### -# -# Picojson -# - -set (PICOJSON_SDK_ROOT "C:/Users/Neurodancer/source/SDK/PicoJSON") - -set (PICOJSON_INCLUDE_DIRS - "${PICOJSON_SDK_ROOT}/include") - - -# -# WxWidgets -# - -set (WXWIDGETS_SDK_ROOT "C:/Users/Neurodancer/source/repos/wxWidgets") - -set (WXWIDGETS_INCLUDE_DIRS - "${WXWIDGETS_SDK_ROOT}/include" - "${WXWIDGETS_SDK_ROOT}/include/msvc" - "${WXWIDGETS_SDK_ROOT}/lib/vc_x64_lib/mswu") - -link_directories("${WXWIDGETS_SDK_ROOT}/lib/vc_x64_lib") - -set (WXWIDGETS_WXMSW_LIBRARY_DEBUG - "${WXWIDGETS_SDK_ROOT}/lib/vc_x64_lib/wxmsw31ud_core.lib") -set (WXWIDGETS_WXBASE_LIBRARY_DEBUG - "${WXWIDGETS_SDK_ROOT}/lib/vc_x64_lib/wxbase31ud.lib") -set (WXWIDGETS_WXMSW_LIBRARY_RELEASE - "${WXWIDGETS_SDK_ROOT}/lib/vc_x64_lib/wxmsw31u_core.lib") -set (WXWIDGETS_WXBASE_LIBRARY_RELEASE - "${WXWIDGETS_SDK_ROOT}/lib/vc_x64_lib/wxbase31u.lib") - - -# -# DevIL -# - -set (DEVIL_SDK_ROOT "C:/Users/Neurodancer/source/SDK/DevIL") - -set (DEVIL_INCLUDE_DIRS "${DEVIL_SDK_ROOT}/include") - -set (DEVIL_DEVIL_LIBRARY_DEBUG - "${DEVIL_SDK_ROOT}/lib/x64/Debug/DevIL.lib") -set (DEVIL_ILU_LIBRARY_DEBUG - "${DEVIL_SDK_ROOT}/lib/x64/Debug/ILU.lib") -set (DEVIL_DEVIL_LIBRARY_RELEASE - "${DEVIL_SDK_ROOT}/lib/x64/Release/DevIL.lib") -set (DEVIL_ILU_LIBRARY_RELEASE - "${DEVIL_SDK_ROOT}/lib/x64/Release/ILU.lib") +find_path(PICOJSON_INCLUDE_DIRS + NAMES picojson/picojson.h + HINTS "C:/Users/Neurodancer/source/SDK/PicoJSON") -set (DEVIL_RUNTIME_LIBRARIES_DEBUG - "${DEVIL_SDK_ROOT}/lib/x64/Debug/DevIL.dll" - "${DEVIL_SDK_ROOT}/lib/x64/Debug/ILU.dll") -set (DEVIL_RUNTIME_LIBRARIES_RELEASE - "${DEVIL_SDK_ROOT}/lib/x64/Release/DevIL.dll" - "${DEVIL_SDK_ROOT}/lib/x64/Release/ILU.dll") +#set(wxWidgets_ROOT_DIR "C:/Users/Neurodancer/source/repos/wxWidgets") +find_package(wxWidgets REQUIRED base gl core) +# Not sure how to tell FindDevIL.cmake to search in a specific path +# set (DEVIL_SDK_ROOT "C:/Users/Neurodancer/source/SDK/DevIL") +find_package(DevIL REQUIRED) #################################################### # Flags @@ -99,8 +52,9 @@ if (MSVC) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /fp:fast /Ox /GS-") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:MSVCRT") -elseif(CMAKE_COMPILER_IS_GNUXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 -O3 -ffast-math -fno-math-errno -funsafe-math-optimizations -ffinite-math-only -fno-trapping-math") +elseif(CMAKE_COMPILER_IS_GNUCXX) + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 -O3 -ffast-math -fno-math-errno -funsafe-math-optimizations -ffinite-math-only -fno-trapping-math") + set(CMAKE_CXX_STANDARD 17) endif() diff --git a/GameLib/CMakeLists.txt b/GameLib/CMakeLists.txt index 6910bb9..22561a7 100644 --- a/GameLib/CMakeLists.txt +++ b/GameLib/CMakeLists.txt @@ -49,20 +49,13 @@ source_group("Physics" FILES ${PHYSICS_SOURCES}) add_library (GameLib ${GAME_SOURCES} ${PHYSICS_SOURCES}) -target_include_directories(GameLib PUBLIC - ${PICOJSON_INCLUDE_DIRS}) - -target_include_directories(GameLib PRIVATE - ${DEVIL_INCLUDE_DIRS}) - -target_include_directories(GameLib INTERFACE - ..) +target_include_directories(GameLib PUBLIC ${PICOJSON_INCLUDE_DIRS}) +target_include_directories(GameLib PRIVATE ${IL_INCLUDE_DIR}) +target_include_directories(GameLib INTERFACE ..) target_link_libraries (GameLib ${OPENGL_LIBRARIES} - debug ${DEVIL_DEVIL_LIBRARY_DEBUG} - debug ${DEVIL_ILU_LIBRARY_DEBUG} - optimized ${DEVIL_DEVIL_LIBRARY_RELEASE} - optimized ${DEVIL_ILU_LIBRARY_RELEASE} + ${IL_LIBRARIES} + ${ILU_LIBRARIES} + ${ILUT_LIBRARIES} ${ADDITIONAL_LIBRARIES}) - diff --git a/ShipSandbox/CMakeLists.txt b/ShipSandbox/CMakeLists.txt index 6ad1dec..d80ca8f 100644 --- a/ShipSandbox/CMakeLists.txt +++ b/ShipSandbox/CMakeLists.txt @@ -24,16 +24,12 @@ source_group("Resources" FILES ${RESOURCE_FILES}) add_executable (ShipSandbox ${SHIP_SANDBOX_SOURCES} ${RESOURCE_FILES}) -target_include_directories (ShipSandbox PRIVATE - ${WXWIDGETS_INCLUDE_DIRS}) - +target_include_directories(ShipSandbox PRIVATE ${wxWidgets_INCLUDE_DIRS}) +target_compile_definitions(ShipSandbox PRIVATE "${wxWidgets_DEFINITIONS}") target_link_libraries (ShipSandbox GameLib ${OPENGL_LIBRARIES} - debug ${WXWIDGETS_WXMSW_LIBRARY_DEBUG} - optimized ${WXWIDGETS_WXMSW_LIBRARY_RELEASE} - debug ${WXWIDGETS_WXBASE_LIBRARY_DEBUG} - optimized ${WXWIDGETS_WXBASE_LIBRARY_RELEASE} + ${wxWidgets_LIBRARIES} ${ADDITIONAL_LIBRARIES}) if (MSVC) From e95066bdf57720cca046c576c9349660c88bd6f1 Mon Sep 17 00:00:00 2001 From: Walther Zwart Date: Sun, 4 Feb 2018 21:22:45 +0100 Subject: [PATCH 3/4] Fixed missing includes --- GameLib/Scheduler.h | 1 + ShipSandbox/LoggingDialog.cpp | 1 + ShipSandbox/MainFrame.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/GameLib/Scheduler.h b/GameLib/Scheduler.h index 915a9c0..716cb38 100644 --- a/GameLib/Scheduler.h +++ b/GameLib/Scheduler.h @@ -10,6 +10,7 @@ #include #include #include +#include class Scheduler { diff --git a/ShipSandbox/LoggingDialog.cpp b/ShipSandbox/LoggingDialog.cpp index 972dbfb..af7a03c 100644 --- a/ShipSandbox/LoggingDialog.cpp +++ b/ShipSandbox/LoggingDialog.cpp @@ -7,6 +7,7 @@ #include +#include #include wxBEGIN_EVENT_TABLE(LoggingDialog, wxDialog) diff --git a/ShipSandbox/MainFrame.cpp b/ShipSandbox/MainFrame.cpp index 4549612..7f46994 100644 --- a/ShipSandbox/MainFrame.cpp +++ b/ShipSandbox/MainFrame.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include From acc625225359008919abcd8cadf3e448ae11d7ed Mon Sep 17 00:00:00 2001 From: Walther Zwart Date: Sun, 4 Feb 2018 21:29:47 +0100 Subject: [PATCH 4/4] Removed unnecessary wstrings --- CMakeLists.txt | 1 + GameLib/Game.cpp | 8 ++++---- GameLib/Game.h | 2 +- GameLib/Utils.cpp | 8 ++++---- GameLib/Utils.h | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f3575f3..e44af5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ if (MSVC) elseif(CMAKE_COMPILER_IS_GNUCXX) #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 -O3 -ffast-math -fno-math-errno -funsafe-math-optimizations -ffinite-math-only -fno-trapping-math") set(CMAKE_CXX_STANDARD 17) + add_definitions("-D_UNICODE") endif() diff --git a/GameLib/Game.cpp b/GameLib/Game.cpp index 909daea..3020172 100644 --- a/GameLib/Game.cpp +++ b/GameLib/Game.cpp @@ -23,7 +23,7 @@ std::unique_ptr Game::Create() { - auto materials = LoadMaterials(L"Data/materials.json"); + auto materials = LoadMaterials("Data/materials.json"); auto oceanDepth = LoadOceanDepth(L"Data/depth.png"); std::unique_ptr world = std::make_unique(); @@ -157,14 +157,14 @@ void Game::Render( glFlush(); } -std::vector> Game::LoadMaterials(std::wstring const & filepath) +std::vector> Game::LoadMaterials(std::string const & filepath) { std::vector> materials; picojson::value root = Utils::ParseJSONFile(filepath); if (!root.is()) { - throw GameException(L"File \"" + filepath + L"\" does not contain a JSON array"); + throw GameException("File \"" + filepath + "\" does not contain a JSON array"); } picojson::array rootArray = root.get(); @@ -172,7 +172,7 @@ std::vector> Game::LoadMaterials(std::wstring co { if (!rootElem.is()) { - throw GameException(L"File \"" + filepath + L"\" does not contain a JSON array of objects"); + throw GameException("File \"" + filepath + "\" does not contain a JSON array of objects"); } materials.emplace_back(Material::Create(rootElem.get())); diff --git a/GameLib/Game.h b/GameLib/Game.h index 2c74494..504e8bd 100644 --- a/GameLib/Game.h +++ b/GameLib/Game.h @@ -53,7 +53,7 @@ class Game { } - static std::vector> LoadMaterials(std::wstring const & filepath); + static std::vector> LoadMaterials(std::string const & filepath); static std::vector LoadOceanDepth(std::wstring const & filepath); private: diff --git a/GameLib/Utils.cpp b/GameLib/Utils.cpp index 4d8b101..ec7f5a8 100644 --- a/GameLib/Utils.cpp +++ b/GameLib/Utils.cpp @@ -17,13 +17,13 @@ namespace /* anonymous */ { - std::string GetTextFileContents(std::wstring const & filename) + std::string GetTextFileContents(std::string const & filename) { std::ifstream file(filename.c_str(), std::ios::in); if (!file.is_open()) { - throw GameException(L"Cannot open file \"" + filename + L"\""); + throw GameException("Cannot open file \"" + filename + "\""); } std::stringstream ss; @@ -45,7 +45,7 @@ std::wstring Utils::ConvertAsciiString(std::string const & asciiStr) return wstr; } -picojson::value Utils::ParseJSONFile(std::wstring const & filename) +picojson::value Utils::ParseJSONFile(std::string const & filename) { std::string fileContents = GetTextFileContents(filename); @@ -53,7 +53,7 @@ picojson::value Utils::ParseJSONFile(std::wstring const & filename) std::string parseError = picojson::parse(jsonContent, fileContents); if (!parseError.empty()) { - throw GameException(L"Error parsing JSON file \"" + filename + L"\": " + ConvertAsciiString(parseError)); + throw GameException("Error parsing JSON file \"" + filename + "\": " + parseError); } return jsonContent; diff --git a/GameLib/Utils.h b/GameLib/Utils.h index 0a2dc00..001f9af 100644 --- a/GameLib/Utils.h +++ b/GameLib/Utils.h @@ -20,7 +20,7 @@ class Utils static std::wstring ConvertAsciiString(std::string const & asciiStr); - static picojson::value ParseJSONFile(std::wstring const & filename); + static picojson::value ParseJSONFile(std::string const & filename); template static T const & GetOptionalJsonMember( @@ -78,4 +78,4 @@ class Utils return memberIt->second.get(); } -}; \ No newline at end of file +};