Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/linux build #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 12 additions & 57 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,8 +52,10 @@ 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)
add_definitions("-D_UNICODE")
endif()


Expand Down
19 changes: 6 additions & 13 deletions GameLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

8 changes: 4 additions & 4 deletions GameLib/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

std::unique_ptr<Game> 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<Physics::World> world = std::make_unique<Physics::World>();
Expand Down Expand Up @@ -157,22 +157,22 @@ void Game::Render(
glFlush();
}

std::vector<std::unique_ptr<Material const>> Game::LoadMaterials(std::wstring const & filepath)
std::vector<std::unique_ptr<Material const>> Game::LoadMaterials(std::string const & filepath)
{
std::vector<std::unique_ptr<Material const>> materials;

picojson::value root = Utils::ParseJSONFile(filepath);
if (!root.is<picojson::array>())
{
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<picojson::array>();
for (auto const & rootElem : rootArray)
{
if (!rootElem.is<picojson::object>())
{
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<picojson::object>()));
Expand Down
2 changes: 1 addition & 1 deletion GameLib/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Game
{
}

static std::vector<std::unique_ptr<Material const>> LoadMaterials(std::wstring const & filepath);
static std::vector<std::unique_ptr<Material const>> LoadMaterials(std::string const & filepath);
static std::vector<float> LoadOceanDepth(std::wstring const & filepath);

private:
Expand Down
1 change: 1 addition & 0 deletions GameLib/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <mutex>
#include <queue>
#include <thread>
#include <condition_variable>

class Scheduler
{
Expand Down
8 changes: 4 additions & 4 deletions GameLib/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,15 +45,15 @@ 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);

picojson::value jsonContent;
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;
Expand Down
4 changes: 2 additions & 2 deletions GameLib/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T>
static T const & GetOptionalJsonMember(
Expand Down Expand Up @@ -78,4 +78,4 @@ class Utils

return memberIt->second.get<T>();
}
};
};
10 changes: 3 additions & 7 deletions ShipSandbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ShipSandbox/LoggingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <GameLib/Log.h>

#include <wx/settings.h>
#include <cassert>

wxBEGIN_EVENT_TABLE(LoggingDialog, wxDialog)
Expand Down
1 change: 1 addition & 0 deletions ShipSandbox/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <wx/intl.h>
#include <wx/msgdlg.h>
#include <wx/panel.h>
#include <wx/settings.h>
#include <wx/sizer.h>
#include <wx/string.h>
Expand Down
31 changes: 6 additions & 25 deletions UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
7 changes: 0 additions & 7 deletions UnitTests/Main.cpp

This file was deleted.