Skip to content
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
51 changes: 37 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ project(PracticalToolsForSimpleDesign)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (MSVC)
if(MSVC)
set(TARGET_COMPILE_OPTIONS
/W4
)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/build)
else()
set(TARGET_COMPILE_OPTIONS
-Wall -Wextra -pedantic
)
endif()

if (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

if(WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# see https://github.com/ntut-open-source-club/practical-tools-for-simple-design/issues/22
set(CMAKE_RC_FLAGS="-C 1252")
endif()
Expand Down Expand Up @@ -127,18 +126,39 @@ target_include_directories(PTSD SYSTEM PRIVATE
target_include_directories(PTSD PRIVATE
${INCLUDE_DIR}
)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(PTSD PRIVATE PTSD_ASSETS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/assets")

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(PTSD_ASSETS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/assets" CACHE STRING "Path to assets directory")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(PTSD_ASSETS_DIR "./assets" CACHE STRING "Path to assets directory")
add_custom_target(PTSD_assets
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/assets
${CMAKE_BINARY_DIR}/assets
)
add_dependencies(PTSD PTSD_assets)

option(COPY_PTSD_CONFIG "Copy config.json to build directory" OFF)
if(COPY_PTSD_CONFIG)
add_custom_target(PTSD_Config
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/config.json
${CMAKE_BINARY_DIR}/config.json
)
add_dependencies(PTSD PTSD_Config)
else()
message(AUTHOR_WARNING
"COPY_PTSD_CONFIG is set to OFF. The default configurations will be used.")
endif()
else()
# TODO
message(AUTHOR_WARNING "relative PTSD_ASSETS_DIR is WIP, Please use `-DCMAKE_BUILD_TYPE=Debug` build for now.")
target_compile_definitions(PTSD PRIVATE PTSD_ASSETS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/assets")
message(AUTHOR_WARNING
"Unknown build type: ${CMAKE_BUILD_TYPE}. Please ensure that You have passed PTSD_ASSETS_DIR to CMake.")
endif()
if (${PTSD_ENABLE_PCH})
target_precompile_headers(PTSD PRIVATE
include/pch.hpp
)

if(NOT PROJECT_IS_TOP_LEVEL)
set(PTSD_ASSETS_DIR ${PTSD_ASSETS_DIR} PARENT_SCOPE)
endif()
target_compile_definitions(PTSD PRIVATE PTSD_ASSETS_DIR="${PTSD_ASSETS_DIR}")

target_compile_options(PTSD PRIVATE
${TARGET_COMPILE_OPTIONS}
Expand Down Expand Up @@ -192,6 +212,9 @@ target_link_libraries(AudioTest
PTSD
GTest::gtest_main
)

target_compile_definitions(AudioTest PRIVATE ASSETS_DIR="${PTSD_ASSETS_DIR}")

target_include_directories(AudioTest SYSTEM PRIVATE
${INCLUDE_DIR}
${DEPENDENCY_INCLUDE_DIRS}
Expand Down
2 changes: 1 addition & 1 deletion example/src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void App::Start() {
LOG_TRACE("Start");

m_Giraffe->SetDrawable(
std::make_shared<Util::Image>("../assets/sprites/giraffe.png"));
std::make_shared<Util::Image>(ASSETS_DIR"/sprites/giraffe.png"));
m_Giraffe->SetZIndex(5);
m_Giraffe->Start();

Expand Down
16 changes: 8 additions & 8 deletions example/src/Cat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
Cat::Cat()
: m_Animation(std::make_shared<Util::Animation>(
std::vector<std::string>{
"../assets/sprites/cat/cat-0.bmp",
"../assets/sprites/cat/cat-1.bmp",
"../assets/sprites/cat/cat-2.bmp",
"../assets/sprites/cat/cat-3.bmp",
"../assets/sprites/cat/cat-4.bmp",
"../assets/sprites/cat/cat-5.bmp",
"../assets/sprites/cat/cat-6.bmp",
"../assets/sprites/cat/cat-7.bmp",
ASSETS_DIR"/sprites/cat/cat-0.bmp",
ASSETS_DIR"/sprites/cat/cat-1.bmp",
ASSETS_DIR"/sprites/cat/cat-2.bmp",
ASSETS_DIR"/sprites/cat/cat-3.bmp",
ASSETS_DIR"/sprites/cat/cat-4.bmp",
ASSETS_DIR"/sprites/cat/cat-5.bmp",
ASSETS_DIR"/sprites/cat/cat-6.bmp",
ASSETS_DIR"/sprites/cat/cat-7.bmp",
},
true, 50, true, 1000)) {
m_Transform.translation = {-200, 200};
Expand Down
2 changes: 1 addition & 1 deletion example/src/Giraffe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

void Giraffe::Start() {
m_GiraffeText =
std::make_shared<GiraffeText>("../assets/fonts/Inter.ttf", 50);
std::make_shared<GiraffeText>(ASSETS_DIR"/fonts/Inter.ttf", 50);
m_GiraffeText->SetZIndex(this->GetZIndex() - 1);
m_GiraffeText->Start();
this->AddChild(m_GiraffeText);
Expand Down
8 changes: 4 additions & 4 deletions test/Interactive/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AudioTest : public ::testing::Test {
};

TEST_F(AudioTest, BGM_TEST) {
auto bgm = Util::BGM("../assets/audio/testbgm.mp3");
auto bgm = Util::BGM(ASSETS_DIR"/audio/testbgm.mp3");

bgm.Play();
EXCEPT_INPUT_YES("Do you hear the bgm?");
Expand All @@ -87,7 +87,7 @@ TEST_F(AudioTest, BGM_TEST) {
}

TEST_F(AudioTest, SFX_TEST) {
auto sfx = Util::SFX("../assets/audio/Click.wav");
auto sfx = Util::SFX(ASSETS_DIR"/audio/Click.wav");

sfx.Play();
EXCEPT_INPUT_YES("Do you hear the sfx?");
Expand All @@ -102,8 +102,8 @@ TEST_F(AudioTest, SFX_TEST) {
}

TEST_F(AudioTest, BGM_SFX_TEST) {
auto bgm = Util::BGM("../assets/audio/testbgm.mp3");
auto sfx = Util::SFX("../assets/audio/Click.wav");
auto bgm = Util::BGM(ASSETS_DIR"/audio/testbgm.mp3");
auto sfx = Util::SFX(ASSETS_DIR"/audio/Click.wav");

bgm.SetVolume(100);
sfx.SetVolume(100);
Expand Down