From 2dc8050ce33cd3100b360cccf2e43d61344b1c4d Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 26 Sep 2022 22:22:25 +0200 Subject: [PATCH] Adding CMake again :) --- CMakeLists.txt | 42 ++++++ cmake/Macros.cmake | 7 + cmake/SpectreConfig.cmake.in | 31 +++++ engine.cmake | 224 ++++++++++++++++++++++++++++++++ examples/CMakeLists.txt | 7 + examples/display/CMakeLists.txt | 12 ++ examples/events/CMakeLists.txt | 7 + examples/input/CMakeLists.txt | 7 + examples/text/CMakeLists.txt | 7 + vendor/FreeType2/CMakeLists.txt | 40 ++++++ 10 files changed, 384 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/Macros.cmake create mode 100644 cmake/SpectreConfig.cmake.in create mode 100644 engine.cmake create mode 100644 examples/CMakeLists.txt create mode 100644 examples/display/CMakeLists.txt create mode 100644 examples/events/CMakeLists.txt create mode 100644 examples/input/CMakeLists.txt create mode 100644 examples/text/CMakeLists.txt create mode 100644 vendor/FreeType2/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1b32dec --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,42 @@ +# ------------------------------------------------------------ +# +# Spectre main Cmake config +# +# ------------------------------------------------------------ +cmake_minimum_required(VERSION 3.15) +cmake_policy(SET CMP0091 NEW) + + +# set the project name +project(Spectre + VERSION 0.0.1 + DESCRIPTION "" + HOMEPAGE_URL "") + +set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake" ) + +include(GNUInstallDirs) + +# Compiler +# ------------------------------- + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED True) +set(CMAKE_CXX_EXTENSIONS OFF) + +if (MSVC) + add_definitions("/EHsc -D_CRT_SECURE_NO_WARNINGS") + + # Staticly link with MSVCR + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +endif (MSVC) + + +# Variables +# ------------------------------- + +# Include engine +include(engine.cmake) + +# Include examples +add_subdirectory(examples) \ No newline at end of file diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake new file mode 100644 index 0000000..3419cd0 --- /dev/null +++ b/cmake/Macros.cmake @@ -0,0 +1,7 @@ + +function(spectre_example NAME) + add_executable(example_${NAME} ${ARGN}) + target_link_libraries(example_${NAME} PRIVATE Spectre) + set_target_properties(example_${NAME} PROPERTIES VS_GLOBAL_IgnoreImportLibrary "true") + #set_target_properties(${NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") +endfunction() \ No newline at end of file diff --git a/cmake/SpectreConfig.cmake.in b/cmake/SpectreConfig.cmake.in new file mode 100644 index 0000000..3b3cf18 --- /dev/null +++ b/cmake/SpectreConfig.cmake.in @@ -0,0 +1,31 @@ +# This script provides the spectre as an import target +# ---------------------------------------------------------- +# +# Use find_package() so cmake will find spectre: +# +# find_package(spectre) # No specific version +# find_package(spectre REQUIRED) # No specific version, but the library must be found. +# find_package(spectre 0.1) # any 0.1.x, but the library is optional. +# find_package(spectre 0.1.0) # 0.1.0 or greater, but the library is optional. +# +# Then you just link your target with spectre: +# +# target_link_libraries( ${PROGRAM_EXE} PUBLIC spectre ) +# +# if you do not specify REQUIRED. you must check the variable spectre_FOUND +# and and only link to it if it's defined: +# +# if (spectre_FOUND) +# ... +# target_link_libraries( ${PROGRAM_EXE} PUBLIC spectre ) +# .. +# endif() + +@PACKAGE_INIT@ + +find_package(OpenGL) + +set_and_check( SPECTRE_ASSETS "@PACKAGE_ASSETS_DIR@" ) + +include("${CMAKE_CURRENT_LIST_DIR}/SpectreTargets.cmake") +check_required_components(Spectre) \ No newline at end of file diff --git a/engine.cmake b/engine.cmake new file mode 100644 index 0000000..ed62b4e --- /dev/null +++ b/engine.cmake @@ -0,0 +1,224 @@ +# ------------------------------------------------------------ +# +# Engine library build config +# +# ------------------------------------------------------------ + +# Source +# ------------------------------------------------------------ + +set( ENGINE_SRC + # Core + source/Core/String.cpp + + # System + source/System/ByteOrder.cpp + source/System/Event.cpp + source/System/EventListener.cpp + source/System/File.cpp + source/System/Log.cpp + source/System/MessageHandler.cpp + source/System/MessageQueue.cpp + source/System/Path.cpp + source/System/Stopwatch.cpp + + # Platform + source/Platform/PlatformApplication.cpp + source/Platform/PlatformDisplay.cpp + + # Math + source/Math/Color.cpp + source/Math/Logarithm.cpp + source/Math/Time.cpp + source/Math/Transform.cpp + source/Math/Math.cpp + + # Input + source/Input/InputDevice.cpp + source/Input/InputModule.cpp + source/Input/Keyboard.cpp + source/Input/Mouse.cpp + + # Display + source/Display/Display.cpp + source/Display/DisplayDescription.cpp + source/Display/DisplayMode.cpp + source/Display/GLContext.cpp + + # GfxDriver + source/GfxDriver/ShaderProgram.cpp + + # Graphics + source/Graphics/BatchRenderer2D.cpp + source/Graphics/DefaultRenderer2D.cpp + source/Graphics/Renderable2D.cpp + source/Graphics/Renderer2D.cpp + source/Graphics/RenderState.cpp + source/Graphics/Sprite.cpp + source/Graphics/Text.cpp + source/Graphics/Texture.cpp + source/Graphics/Transformable.cpp + source/Graphics/Vertex2D.cpp + source/Graphics/Graphics.cpp + + # Graphics - Font + source/Graphics/Font/Engine/FreeTypeEngine.cpp + source/Graphics/Font/Engine/FreeTypeError.cpp + source/Graphics/Font/Engine/FreeTypeLib.cpp + source/Graphics/Font/FontDescription.cpp + source/Graphics/Font.cpp + + # Graphics - Image + source/Graphics/Image/IcoFormat.cpp + source/Graphics/ImageLoader.cpp + source/Graphics/PixelFormat.cpp + source/Graphics/Image.cpp + + # Graphics - GL + source/Graphics/GL/glad.c + source/Graphics/GL/CheckError.cpp + + # Scene + source/Scene/Camera2D.cpp + + # Game + source/Game/FPSCounter.cpp + source/Game/GameTime.cpp + source/Game.cpp +) + +set(ENGINE_GFXDRIVER_OPENGL_SRC + source/GfxDriver/OpenGL/OpenGLDrv.cpp + source/GfxDriver/OpenGL/OpenGLShaderProgram.cpp +) + +set(ENGINE_PLATFORM_WIN32_SRC + source/Platform/Win32/Win32Application.cpp + source/Platform/Win32/Win32Display.cpp + source/Platform/Win32/Win32GLContext.cpp + source/Platform/Win32/Win32Input.cpp + source/Platform/Win32/Win32Internal.cpp + source/Platform/Win32/Win32Keyboard.cpp + source/Platform/Win32/Win32Misc.cpp + source/Platform/Win32/Win32Mouse.cpp + source/Platform/Win32/Win32EventQueue.cpp + source/Platform/Win32/Win32System.cpp + source/Platform/Win32/glad_wgl.c +) + +set(ENGINE_PLATFORM_UNIX_SRC + source/Platform/X11/Xlib.cpp + source/Platform/X11/UnixApplication.cpp + source/Platform/X11/X11Display.cpp + source/Platform/X11/GLXContext.cpp + source/Platform/X11/X11Input.cpp + source/Platform/X11/X11Keyboard.cpp + source/Platform/X11/X11Mouse.cpp + source/Platform/X11/X11EventQueue.cpp + source/Platform/X11/X11WindowEventHandler.cpp + source/Platform/X11/UnixMisc.cpp + source/Platform/X11/UnixSystem.cpp + source/Platform/X11/glad_glx.c +) + + +# Library +# ------------------------------------------------------------ + +add_library( Spectre STATIC ${ENGINE_SRC} ) +target_include_directories(Spectre + PUBLIC + $ + $ + PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/source +) + +if (WIN32) + target_compile_options(Spectre PRIVATE "-DSPECTRE_PLATFORM_WIN=1") +else() + target_compile_options(Spectre PRIVATE "-DSPECTRE_PLATFORM_UNIX=1") +endif() + + +# Dependancies +# ------------------------------------------------------------ + +# Select platform. +if (WIN32) + target_sources(Spectre PRIVATE ${ENGINE_PLATFORM_WIN32_SRC}) +else() + target_sources(Spectre PRIVATE ${ENGINE_PLATFORM_UNIX_SRC}) +endif (WIN32) + +# Select graphics API + +# Only OpenGL Driver for now +find_package(OpenGL REQUIRED) +target_sources(Spectre PRIVATE ${ENGINE_GFXDRIVER_OPENGL_SRC}) +target_link_libraries(Spectre PRIVATE OpenGL::GL) + +# FreeType +add_subdirectory(vendor/FreeType2) +target_sources(Spectre PRIVATE $) +target_include_directories(Spectre PRIVATE $) + +# STB +target_include_directories(Spectre PRIVATE ${CMAKE_CURRENT_LIST_DIR}/vendor/stb/include) + +# Install +# ------------------------------------------------------------ + +# Includes +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/Spectre TYPE INCLUDE) + +# Assets +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/assets DESTINATION ${CMAKE_INSTALL_DATADIR}) + + +# Install - CMake targets +# ------------------------------------------------------------ + +install(TARGETS Spectre + EXPORT SpectreTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +install(EXPORT SpectreTargets + FILE SpectreTargets.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Spectre +) + +# Build directory target +export(EXPORT SpectreTargets + FILE "${CMAKE_CURRENT_BINARY_DIR}/SpectreTargets.cmake" +) + +# CMake config +# ------------------------------------------------------------ + +# Version +include(CMakePackageConfigHelpers) +write_basic_package_version_file(SpectreConfigVersion.cmake COMPATIBILITY SameMajorVersion) + +set (ASSETS_DIR ${CMAKE_INSTALL_DATADIR}/assets) +configure_package_config_file(cmake/SpectreConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/cmake/SpectreConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Spectre + PATH_VARS ASSETS_DIR) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/SpectreConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/SpectreConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Spectre) + +# CMake config - build directory +# ------------------------------------------------------------ +set (ASSETS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/assets) +configure_package_config_file(cmake/SpectreConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/SpectreConfig.cmake + INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR} + INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR} + PATH_VARS ASSETS_DIR) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..a9890c3 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,7 @@ + +include("Macros") + +add_subdirectory(display) +add_subdirectory(events) +add_subdirectory(input) +add_subdirectory(text) \ No newline at end of file diff --git a/examples/display/CMakeLists.txt b/examples/display/CMakeLists.txt new file mode 100644 index 0000000..05e659d --- /dev/null +++ b/examples/display/CMakeLists.txt @@ -0,0 +1,12 @@ + +#find_package(Spectre REQUIRED) + +set (SOURCE + DisplayExample.cpp + main.cpp +) + +spectre_example(display + main.cpp + DisplayExample.cpp +) diff --git a/examples/events/CMakeLists.txt b/examples/events/CMakeLists.txt new file mode 100644 index 0000000..f8d92bf --- /dev/null +++ b/examples/events/CMakeLists.txt @@ -0,0 +1,7 @@ + +#find_package(Spectre REQUIRED) + +spectre_example(events + main.cpp + EventsExample.cpp +) diff --git a/examples/input/CMakeLists.txt b/examples/input/CMakeLists.txt new file mode 100644 index 0000000..e4a0184 --- /dev/null +++ b/examples/input/CMakeLists.txt @@ -0,0 +1,7 @@ + +#find_package(Spectre REQUIRED) + +spectre_example(input + main.cpp + InputExample.cpp +) diff --git a/examples/text/CMakeLists.txt b/examples/text/CMakeLists.txt new file mode 100644 index 0000000..31f56d1 --- /dev/null +++ b/examples/text/CMakeLists.txt @@ -0,0 +1,7 @@ + +#find_package(Spectre REQUIRED) + +spectre_example(text + main.cpp + Game.cpp +) diff --git a/vendor/FreeType2/CMakeLists.txt b/vendor/FreeType2/CMakeLists.txt new file mode 100644 index 0000000..d6636e0 --- /dev/null +++ b/vendor/FreeType2/CMakeLists.txt @@ -0,0 +1,40 @@ +# ------------------------------------------------------------ +# +# Spectre FreeType config +# +# ------------------------------------------------------------ + +set(FT2_SOURCE + src/autofit/autofit.c + src/base/ftbase.c + src/base/ftbbox.c + src/base/ftbdf.c + src/base/ftbitmap.c + src/base/ftcid.c + src/base/ftfstype.c + src/base/ftgasp.c + src/base/ftglyph.c + src/base/ftgxval.c + src/base/ftinit.c + src/base/ftmm.c + src/base/ftotval.c + src/base/ftpatent.c + src/base/ftpfr.c + src/base/ftstroke.c + src/base/ftsynth.c + src/base/ftsystem.c + src/base/fttype1.c + src/base/ftwinfnt.c + src/cff/cff.c + src/psaux/psaux.c + src/pshinter/pshinter.c + src/psnames/psnames.c + src/raster/raster.c + src/sfnt/sfnt.c + src/smooth/smooth.c + src/truetype/truetype.c +) + +add_library( freetype OBJECT ${FT2_SOURCE} ) +target_include_directories(freetype PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) +target_compile_definitions(freetype PRIVATE FT2_BUILD_LIBRARY)