@@ -2,3 +2,4 @@ | |||
.tags | |||
compile_commands.json | |||
.clangd | |||
.cache |
@@ -1,103 +0,0 @@ | |||
cmake_minimum_required(VERSION 3.0) | |||
project(swan) | |||
find_package(SDL2 REQUIRED) | |||
find_package(PNG) | |||
option(USE_CLANG_TIDY "Use clang-tidy for additional checks" OFF) | |||
if(USE_CLANG_TIDY) | |||
set(CMAKE_CXX_CLANG_TIDY | |||
clang-tidy | |||
"--header-filter=(libswan|libcygnet|core.mod|src)/.*" | |||
--checks=-*,bugprone-*,cert-*,performance-*,clang-analyzer-*,-cert-dcl16-c,-cert-err58-cpp,-clang-analyzer-optin.cplusplus.VirtualCall) | |||
endif() | |||
# Ninja runs commands with buffered stdio so the compiler won't show colors by default, | |||
# but Ninja will strip out color codes if Ninja's stdout isn't a tty so unconditionally | |||
# enabling color diagnostics is safe | |||
if(CMAKE_GENERATOR STREQUAL "Ninja") | |||
add_compile_options(-fdiagnostics-color=always) | |||
endif() | |||
add_compile_options(-std=c++2a -Wall -Wextra -Wpedantic -Wno-unused-parameter) | |||
set(libraries | |||
third-party imgui fmt cpptoml msgpack | |||
SDL2::SDL2 SDL2_image dl z) | |||
if(CMAKE_BUILD_TYPE STREQUAL Sanitize OR CMAKE_BUILD_TYPE STREQUAL "") | |||
message(STATUS "Build mode: Sanitize") | |||
add_compile_options(-g -DDEBUG -fsanitize=address -fsanitize=undefined) | |||
add_link_options(-fsanitize=address -fsanitize=undefined) | |||
elseif(CMAKE_BUILD_TYPE STREQUAL Debug) | |||
message(STATUS "Build mode: Debug") | |||
add_compile_options(-g -DDEBUG) | |||
elseif(CMAKE_BUILD_TYPE STREQUAL Optimize) | |||
message(STATUS "Build mode: Optimize") | |||
add_compile_options(-O3 -g -DDEBUG) | |||
elseif(CMAKE_BUILD_TYPE STREQUAL Tracy) | |||
message(STATUS "Build mode: Tracy") | |||
add_compile_options(-O3 -flto -DNDEBUG -g -DTRACY_ENABLE -DTRACY_ON_DEMAND) | |||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto") | |||
list(APPEND libraries tracy) | |||
elseif(CMAKE_BUILD_TYPE STREQUAL Release) | |||
message(STATUS "Build mode: Release") | |||
add_compile_options(-O3 -flto -g -DNDEBUG) | |||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto") | |||
else() | |||
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be Sanitize, Debug, DebugRelease, Tracy or Release.") | |||
endif() | |||
# We want to be able to use C++20 designated initializers, | |||
# but Clang doesn't support them yet. | |||
# Remove once Clang 9.1 or something comes out. | |||
add_compile_options(-Wno-c99-extensions) | |||
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_PREFIX}/lib64;${CMAKE_INSTALL_PREFIX}/swan/libswan;${CMAKE_INSTALL_PREFIX}/swan/libcygnet;${CMAKE_INSTALL_PREFIX}/swan/third-party") | |||
add_library(swan-common INTERFACE) | |||
target_include_directories(swan-common | |||
INTERFACE "include") | |||
add_subdirectory(third-party) | |||
add_subdirectory(tracy-tools) | |||
add_subdirectory(libswan) | |||
add_subdirectory(libcygnet) | |||
add_subdirectory(core.mod) | |||
add_executable(swan | |||
src/main.cc) | |||
target_link_libraries(swan libswan libcygnet ${libraries}) | |||
add_dependencies(swan core.mod) | |||
add_executable(perlin-test EXCLUDE_FROM_ALL | |||
src/perlin-test.cc) | |||
target_link_libraries(perlin-test libswan PNG::PNG ${libraries}) | |||
add_executable(lighting-test EXCLUDE_FROM_ALL | |||
src/lighting-test.cc) | |||
target_link_libraries(lighting-test libswan PNG::PNG ${libraries}) | |||
add_executable(cygnet-test EXCLUDE_FROM_ALL | |||
src/cygnet-test.cc) | |||
target_link_libraries(cygnet-test libcygnet ${libraries}) | |||
set(assets | |||
assets/icon.png | |||
assets/music/happy-1.wav) | |||
foreach(a ${assets}) | |||
configure_file("${a}" "${a}" COPYONLY) | |||
endforeach(a) | |||
install(TARGETS swan DESTINATION swan) | |||
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets DESTINATION swan) | |||
add_custom_target(check DEPENDS check_libswan) | |||
add_custom_target(cloc | |||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | |||
COMMAND cloc core.mod src libcygnet libswan) |
@@ -1,26 +0,0 @@ | |||
add_library(core.mod SHARED | |||
src/main.cc | |||
src/DefaultWorldGen.cc | |||
src/entities/PlayerEntity.cc | |||
src/entities/ItemStackEntity.cc) | |||
set_target_properties(core.mod PROPERTIES OUTPUT_NAME mod PREFIX "") | |||
target_link_libraries(core.mod libswan ${libraries}) | |||
set(assets | |||
assets/entity/player-still.png | |||
assets/entity/player-still.toml | |||
assets/entity/player-running.png | |||
assets/entity/player-running.toml | |||
assets/tile/grass.png | |||
assets/tile/stone.png | |||
assets/tile/dirt.png | |||
assets/tile/leaves.png | |||
assets/tile/tree-trunk.png | |||
assets/tile/torch.png | |||
assets/misc/background-cave.png) | |||
foreach(a ${assets}) | |||
configure_file("${a}" "${a}" COPYONLY) | |||
endforeach(a) | |||
install(TARGETS core.mod DESTINATION swan/core.mod) | |||
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets DESTINATION swan/core.mod) |
@@ -0,0 +1,11 @@ | |||
core_mod = shared_library('mod', | |||
'src/main.cc', | |||
'src/DefaultWorldGen.cc', | |||
'src/entities/PlayerEntity.cc', | |||
'src/entities/ItemStackEntity.cc', | |||
name_prefix: '', | |||
install: true, | |||
install_dir: 'core.mod', | |||
dependencies: [libswan, libperlinnoise]) | |||
install_subdir('assets', install_dir: 'core.mod') |
@@ -2,7 +2,7 @@ | |||
#include <swan/swan.h> | |||
#include <PerlinNoise/PerlinNoise.hpp> | |||
#include <PerlinNoise.hpp> | |||
class DefaultWorldGen: public Swan::WorldGen { | |||
public: |
@@ -1,37 +0,0 @@ | |||
cmake_minimum_required(VERSION 3.0) | |||
project(swan-dist) | |||
include(ExternalProject) | |||
set(prefix ${PROJECT_BINARY_DIR}/prefix) | |||
set(common | |||
-DCMAKE_INSTALL_PREFIX=${prefix} | |||
-DCMAKE_PREFIX_PATH=${prefix}) | |||
ExternalProject_Add(sfml | |||
GIT_REPOSITORY https://github.com/SFML/SFML.git | |||
GIT_TAG 2.5.1 | |||
GIT_SHALLOW true | |||
GIT_PROGRESS true | |||
CMAKE_ARGS | |||
-DCMAKE_BUILD_TYPE=Release | |||
${common}) | |||
ExternalProject_Add(imgui-sfml | |||
GIT_REPOSITORY https://github.com/eliasdaler/imgui-sfml.git | |||
GIT_TAG v2.1 | |||
GIT_SHALLOW true | |||
GIT_PROGRESS true | |||
CMAKE_ARGS | |||
-DCMAKE_BUILD_TYPE=Release | |||
-DIMGUI_DIR=${PROJECT_SOURCE_DIR}/../third_party/imgui | |||
-DBUILD_SHARED_LIBS=true | |||
${common} | |||
DEPENDS sfml) | |||
ExternalProject_Add(swan | |||
SOURCE_DIR ${PROJECT_SOURCE_DIR}/.. | |||
CMAKE_ARGS | |||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | |||
${common} | |||
DEPENDS sfml imgui-sfml) |
@@ -1,14 +0,0 @@ | |||
add_library(libcygnet SHARED | |||
src/GlWrappers.cc | |||
src/Renderer.cc | |||
src/ResourceManager.cc | |||
src/shaders.cc | |||
src/TileAtlas.cc | |||
src/util.cc | |||
src/Window.cc) | |||
target_include_directories(libcygnet | |||
PUBLIC "include" | |||
PRIVATE "include/cygnet") | |||
target_link_libraries(libcygnet swan-common GLESv2 ${libraries}) | |||
install(TARGETS libcygnet DESTINATION swan/libcygnet) |
@@ -0,0 +1,13 @@ | |||
libcygnet = declare_dependency( | |||
include_directories: 'include', | |||
link_with: library('cygnet', | |||
'src/GlWrappers.cc', | |||
'src/Renderer.cc', | |||
'src/ResourceManager.cc', | |||
'src/shaders.cc', | |||
'src/TileAtlas.cc', | |||
'src/util.cc', | |||
'src/Window.cc', | |||
dependencies: [common, libtracy, libthreads, libsdl2, libgles2], | |||
install: true, | |||
include_directories: 'include/cygnet')) |
@@ -1,36 +0,0 @@ | |||
add_library(libswan SHARED | |||
src/traits/BodyTrait.cc | |||
src/traits/InventoryTrait.cc | |||
src/traits/PhysicsTrait.cc | |||
src/Animation.cc | |||
src/assets.cc | |||
src/Chunk.cc | |||
src/Clock.cc | |||
src/drawutil.cc | |||
src/Entity.cc | |||
src/Game.cc | |||
src/gfxutil.cc | |||
src/ItemStack.cc | |||
src/LightServer.cc | |||
src/OS.cc | |||
src/World.cc | |||
src/WorldPlane.cc) | |||
target_include_directories(libswan | |||
PUBLIC "include" | |||
PRIVATE "include/swan") | |||
set_target_properties(libswan PROPERTIES OUTPUT_NAME swan) | |||
target_link_libraries(libswan swan-common libcygnet ${libraries}) | |||
install(TARGETS libswan DESTINATION swan/libswan) | |||
add_executable(test_libswan EXCLUDE_FROM_ALL | |||
test/lib/test.cc | |||
test/util.t.cc | |||
test/ItemStack.t.cc) | |||
target_link_libraries(test_libswan libswan) | |||
target_include_directories(test_libswan | |||
PRIVATE "include/swan") | |||
add_custom_target(check_libswan | |||
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_libswan | |||
DEPENDS test_libswan) |
@@ -1,7 +1,7 @@ | |||
#pragma once | |||
// We want every file to be able to easily add Tracy zones | |||
#include <tracy/Tracy.hpp> | |||
#include <Tracy.hpp> | |||
#include <swan-common/Vector2.h> | |||
#include <swan-common/constants.h> |
@@ -0,0 +1,27 @@ | |||
libswan_deps = [ | |||
common, libcygnet, libtracy, libthreads, libsdl2, libsdl2_image, | |||
libcpptoml, libdl, libz] | |||
libswan = declare_dependency( | |||
include_directories: 'include', | |||
dependencies: libswan_deps, | |||
link_with: library('swan', | |||
'src/traits/BodyTrait.cc', | |||
'src/traits/InventoryTrait.cc', | |||
'src/traits/PhysicsTrait.cc', | |||
'src/Animation.cc', | |||
'src/assets.cc', | |||
'src/Chunk.cc', | |||
'src/Clock.cc', | |||
'src/drawutil.cc', | |||
'src/Entity.cc', | |||
'src/Game.cc', | |||
'src/gfxutil.cc', | |||
'src/ItemStack.cc', | |||
'src/LightServer.cc', | |||
'src/OS.cc', | |||
'src/World.cc', | |||
'src/WorldPlane.cc', | |||
dependencies: libswan_deps, | |||
install: true, | |||
include_directories: 'include/swan')) |
@@ -0,0 +1,25 @@ | |||
project('swan', 'cpp', | |||
default_options: ['cpp_std=c++2a']) | |||
libdl = meson.get_compiler('cpp').find_library('dl') | |||
libz = meson.get_compiler('cpp').find_library('z') | |||
libgles2 = meson.get_compiler('cpp').find_library('GLESv2') | |||
libsdl2 = dependency('sdl2') | |||
libsdl2_image = dependency('SDL2_image') | |||
libthreads = dependency('threads') | |||
subdir('third-party') | |||
common = declare_dependency( | |||
include_directories: 'include', | |||
dependencies: libmsgpack) | |||
subdir('libcygnet') | |||
subdir('libswan') | |||
subdir('core.mod') | |||
executable('swan', 'src/main.cc', | |||
install: true, | |||
install_rpath: get_option('libdir'), | |||
dependencies: [libswan, libcygnet, common, libimgui, libsdl2, libsdl2_image]) | |||
install_subdir('assets', install_dir: '') |
@@ -9,7 +9,7 @@ | |||
#include <SDL2/SDL_image.h> | |||
#include <string.h> | |||
#include <imgui.h> | |||
#include <imgui_sdl/imgui_sdl.h> | |||
#include <imgui_sdl.h> | |||
#include <cygnet/Renderer.h> | |||
#include <cygnet/Window.h> | |||
@@ -0,0 +1,34 @@ | |||
libcpptoml = declare_dependency( | |||
include_directories: 'cpptoml/include') | |||
libfmt = declare_dependency( | |||
include_directories: 'fmt/include', | |||
link_with: library('fmt', | |||
'fmt/src/format.cc', | |||
'fmt/src/os.cc', | |||
include_directories: 'fmt/include')) | |||
libimgui = declare_dependency( | |||
include_directories: ['imgui', 'imgui-plot/include', 'imgui_sdl'], | |||
link_with: library('imgui', | |||
'imgui/imgui_demo.cpp', | |||
'imgui/imgui_draw.cpp', | |||
'imgui/imgui_widgets.cpp', | |||
'imgui/imgui.cpp', | |||
'imgui_sdl/imgui_sdl.cpp', | |||
'imgui-plot/src/imgui_plot.cpp', | |||
include_directories: ['imgui', 'imgui-plot/include', 'imgui_sdl'], | |||
dependencies: libsdl2, | |||
cpp_args: ['-Wno-sign-compare', '-Wno-deprecated-enum-enum-conversion'])) | |||
libmsgpack = declare_dependency( | |||
include_directories: 'msgpack-c/include') | |||
libperlinnoise = declare_dependency( | |||
include_directories: 'PerlinNoise') | |||
libtracy = declare_dependency( | |||
include_directories: 'tracy', | |||
link_with: library('tracy', | |||
'tracy/TracyClient.cpp', | |||
dependencies: libthreads)) |