PolyGun/CMakeLists.txt

438 lines
14 KiB
CMake

# PolyGun
# Copyright (c) 2023 kacperks https://kacperks.cubesoftware.xyz
# 2023 mrkubax10 <mrkubax10@onet.pl>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
project(polygun)
if(SERENITYOS)
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED true)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/mk/cmake")
if(NOT BUILD_FLAG_SUPPRESS_WARNING_MODE AND NOT MSVC)
# Compile with highest warning mode by default
set(DEFAULT_COMPILE_OPTIONS -Wall -Wpedantic -Werror)
endif()
include_directories("${CMAKE_SOURCE_DIR}/src")
include_directories("${CMAKE_BINARY_DIR}")
option(BUILD_CLIENT "Build client" ON)
option(BUILD_SERVER "Build server" ON)
option(BUILD_TOOLS "Build tools" OFF)
if(APPLE OR SERENITYOS)
set(RENDERER_GL_DEFAULT OFF)
else()
set(RENDERER_GL_DEFAULT ON)
endif()
option(RENDERER_GL "Enable OpenGL renderer" ${RENDERER_GL_DEFAULT})
if(SERENITYOS)
set(RENDERER_LEGACY_GL_DEFAULT ON)
else()
set(RENDERER_LEGACY_GL_DEFAULT OFF)
endif()
# Please note that LEGACY_GL renderer should be only used on hardware/operating systems that do not support OpenGL 2.0+
option(RENDERER_LEGACY_GL "Enable legacy OpenGL renderer" ${RENDERER_LEGACY_GL_DEFAULT})
if(NOT BUILD_CLIENT)
set(RENDERER_GL OFF)
set(RENDERER_LEGACY_GL OFF)
endif()
if(WIN32)
set(WINDOW_WIN32_DEFAULT ON)
else()
set(WINDOW_WIN32_DEFAULT OFF)
endif()
option(WINDOW_WIN32 "Enable Win32 window creation (Windows only)" ${WINDOW_WIN32_DEFAULT})
if(UNIX AND NOT APPLE AND NOT SERENITYOS)
if(X11_INCLUDE_DIRS AND X11_LIBRARIES)
set(WINDOW_X11_DEFAULT ON)
else()
find_package(X11 QUIET)
if(X11_FOUND)
set(WINDOW_X11_DEFAULT ON)
else()
set(WINDOW_X11_DEFAULT OFF)
endif()
endif()
endif()
option(WINDOW_X11 "Enable X11 window creation" ${WINDOW_X11_DEFAULT})
if(UNIX AND NOT APPLE AND NOT SERENITYOS)
if(WaylandClient_INCLUDE_DIR AND WaylandClient_LIBRARY)
set(WINDOW_WAYLAND_DEFAULT ON)
else()
find_package(WaylandClient QUIET)
if(WaylandClient_FOUND)
set(WINDOW_WAYLAND_DEFAULT ON)
else()
set(WINDOW_WAYLAND_DEFAULT OFF)
endif()
endif()
endif()
option(WINDOW_WAYLAND "Enable Wayland window creation" ${WINDOW_WAYLAND_DEFAULT})
if(SERENITYOS)
set(WINDOW_SERENITYOS_DEFAULT ON)
execute_process(COMMAND patch INPUT_FILE mk/fixes/serenityos/01_angelscript_no_malloc_h.diff)
add_definitions("-D__serenityos__")
endif()
option(WINDOW_SERENITYOS "Enable SerenityOS window creation" ${WINDOW_SERENITYOS_DEFAULT})
if(HAIKU)
set(WINDOW_HAIKU_DEFAULT ON)
else()
set(WINDOW_HAIKU_DEFAULT OFF)
endif()
option(WINDOW_HAIKU "Enable Haiku window creation" ${WINDOW_HAIKU_DEFAULT})
option(ENABLE_BACKTRACE_PRINTING "Enable backtrace printing" OFF)
if(ENABLE_BACKTRACE_PRINTING)
if(MSVC)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
endif()
endif()
if(BUILD_CLIENT)
set(CLIENT_SOURCES
src/game/audio/audio.cpp
src/game/audio/buffer.cpp
src/game/audio/oggvorbis_decoder.cpp
src/game/audio/source.cpp
src/game/audio/streaming_source.cpp
src/game/control/keyboard_controller.cpp
src/game/control/mouse_camera_controller.cpp
src/game/engine/content_registry.cpp
src/game/engine/engine.cpp
src/game/engine/game_config.cpp
src/game/engine/greedy_meshing.cpp
src/game/engine/node_side.cpp
src/game/engine/normal_meshing.cpp
src/game/engine/ray.cpp
src/game/engine/resource_manager.cpp
src/game/engine/screen_manager.cpp
src/game/engine/texture_atlas.cpp
src/game/engine/thread_helper.cpp
src/game/gui/box.cpp
src/game/gui/button.cpp
src/game/gui/chat.cpp
src/game/gui/combo_box.cpp
src/game/gui/component.cpp
src/game/gui/constraint.cpp
src/game/gui/container.cpp
src/game/gui/gui_master.cpp
src/game/gui/image.cpp
src/game/gui/item_gallery.cpp
src/game/gui/label.cpp
src/game/gui/layout.cpp
src/game/gui/line_edit.cpp
src/game/gui/message_box.cpp
src/game/gui/style_change_listener.cpp
src/game/gui/style.cpp
src/game/gui/text_edit.cpp
src/game/hud/editmode_hud.cpp
src/game/hud/hud.cpp
src/game/hud/normal_hud.cpp
src/game/renderer/font.cpp
src/game/renderer/gui_renderer.cpp
src/game/renderer/master_renderer.cpp
src/game/renderer/mesh_renderer.cpp
src/game/renderer/ortho_camera.cpp
src/game/renderer/surface.cpp
src/game/renderer/texture.cpp
src/game/screens/game_session_screen.cpp
src/game/screens/main_menu_screen.cpp
src/game/screens/options_screen.cpp
src/game/window/keyboard.cpp
src/game/window/mouse.cpp
src/game/window/window.cpp
src/game/world/chunk_manager.cpp
src/game/world/client_chunk.cpp
src/game/world/local_player.cpp
src/game/world/physic_manager.cpp
src/game/world/player_manager.cpp
)
if(RENDERER_GL)
list(APPEND CLIENT_SOURCES
src/game/renderer/gl/gl_context.cpp
src/game/renderer/gl/gl_gui_renderer.cpp
src/game/renderer/gl/gl_master_renderer.cpp
src/game/renderer/gl/gl_mesh.cpp
src/game/renderer/gl/gl_mesh_renderer.cpp
src/game/renderer/gl/gl_shader.cpp
src/game/renderer/gl/gl_texture.cpp
src/game/renderer/gl/opengl.cpp
)
endif()
if(RENDERER_LEGACY_GL)
list(APPEND CLIENT_SOURCES
src/game/renderer/gl/gl_context.cpp
src/game/renderer/gl/gl_texture.cpp
src/game/renderer/gl/opengl.cpp
src/game/renderer/legacy_gl/legacy_gl_gui_renderer.cpp
src/game/renderer/legacy_gl/legacy_gl_master_renderer.cpp
src/game/renderer/legacy_gl/legacy_gl_mesh.cpp
src/game/renderer/legacy_gl/legacy_gl_mesh_renderer.cpp
)
endif()
if(WINDOW_WIN32)
list(APPEND CLIENT_SOURCES
src/game/window/win32/win32_window.cpp
)
if(RENDERER_GL OR RENDERER_LEGACY_GL)
list(APPEND CLIENT_SOURCES
src/game/renderer/gl/win32_gl_context.cpp
)
endif()
endif()
if(WINDOW_X11)
list(APPEND CLIENT_SOURCES
src/game/window/x11/dynamic_x11.cpp
src/game/window/x11/x11_window.cpp
)
if(RENDERER_GL OR RENDERER_LEGACY_GL)
list(APPEND CLIENT_SOURCES
src/game/renderer/gl/x11_gl_context.cpp
src/game/window/x11/dynamic_glx.cpp
)
endif()
endif()
if(WINDOW_WAYLAND)
list(APPEND CLIENT_SOURCES
src/game/window/wayland_window.cpp
)
if(RENDERER_GL OR RENDERER_LEGACY_GL)
list(APPEND CLIENT_SOURCES
src/game/renderer/gl/egl_gl_context.cpp
)
endif()
execute_process(COMMAND wayland-scanner client-header INPUT_FILE ${CMAKE_SOURCE_DIR}/mk/wayland/relative-pointer-unstable-v1.xml OUTPUT_FILE ${CMAKE_BINARY_DIR}/wayland-relative-pointer-unstable-v1.h)
execute_process(COMMAND wayland-scanner private-code INPUT_FILE ${CMAKE_SOURCE_DIR}/mk/wayland/relative-pointer-unstable-v1.xml OUTPUT_FILE ${CMAKE_BINARY_DIR}/wayland-relative-pointer-unstable-v1.c)
execute_process(COMMAND wayland-scanner client-header INPUT_FILE ${CMAKE_SOURCE_DIR}/mk/wayland/pointer-constraints-unstable-v1.xml OUTPUT_FILE ${CMAKE_BINARY_DIR}/wayland-pointer-constraints-unstable-v1.h)
execute_process(COMMAND wayland-scanner private-code INPUT_FILE ${CMAKE_SOURCE_DIR}/mk/wayland/pointer-constraints-unstable-v1.xml OUTPUT_FILE ${CMAKE_BINARY_DIR}/wayland-pointer-constraints-unstable-v1.c)
list(APPEND CLIENT_SOURCES
${CMAKE_BINARY_DIR}/wayland-relative-pointer-unstable-v1.c
${CMAKE_BINARY_DIR}/wayland-pointer-constraints-unstable-v1.c
)
endif()
if(WINDOW_SERENITYOS)
list(APPEND CLIENT_SOURCES
src/game/window/serenityos_window.cpp
)
if(RENDERER_LEGACY_GL)
list(APPEND CLIENT_SOURCES
src/game/renderer/gl/serenityos_gl_context.cpp
)
endif()
endif()
if(WINDOW_HAIKU)
list(APPEND CLIENT_SOURCES
src/game/window/haiku_window.cpp
)
if(RENDERER_GL OR RENDERER_LEGACY_GL)
list(APPEND CLIENT_SOURCES
src/game/renderer/gl/haiku_gl_context.cpp
)
endif()
endif()
endif()
if(BUILD_SERVER)
file(GLOB_RECURSE SERVER_SOURCES "src/server/**.cpp")
include(CheckCXXSourceCompiles)
check_cxx_source_compiles(
"
#include <csignal>
#include <cstring>
int main(){
const char* sig = strsignal(SIGINT);
return 0;
}
"
HAVE_STRSIGNAL_CHECK
)
if(HAVE_STRSIGNAL_CHECK)
option(HAVE_STRSIGNAL "STRSIGNAL" ON)
endif()
endif()
configure_file("config.hpp.in" "config.hpp")
if(BUILD_TOOLS)
add_executable("extract_strings"
tools/extract_strings.cpp
src/common/xml/xml_node.cpp
src/common/xml/lexer.cpp
src/common/xml/parser.cpp
src/common/logger.cpp
)
target_compile_options(extract_strings PRIVATE ${DEFAULT_COMPILE_OPTIONS})
add_executable("t3d_to_polymap"
tools/t3d_to_polymap.cpp
src/common/binary_utils.cpp
)
target_compile_options(t3d_to_polymap PRIVATE ${DEFAULT_COMPILE_OPTIONS})
endif()
file(GLOB_RECURSE COMMON_SOURCES "src/common/**.cpp")
if(NOT ENABLE_BACKTRACE_PRINTING)
list(REMOVE_ITEM COMMON_SOURCES ${CMAKE_SOURCE_DIR}/src/common/backtrace_handler.cpp)
endif()
if(BUILD_SERVER AND NOT BUILD_CLIENT)
set(PROJECT_NAME "polygun_server")
endif()
if(NOT BUILD_CLIENT AND NOT BUILD_SERVER)
message(FATAL_ERROR "You need to select at least one configuration (BUILD_CLIENT and/or BUILD_SERVER)")
endif()
add_executable(${PROJECT_NAME}
${CLIENT_SOURCES}
${SERVER_SOURCES}
${COMMON_SOURCES}
src/main.cpp
)
target_compile_options(${PROJECT_NAME} PRIVATE ${DEFAULT_COMPILE_OPTIONS})
if(BUILD_CLIENT)
if(RENDERER_GL OR RENDERER_LEGACY_GL)
set(RENDERER_GL_LIBRARIES OpenGL::GL)
if(SERENITYOS)
set(OPENGL_INCLUDE_DIR "/usr/include/LibGL")
set(RENDERER_GL_LIBRARIES "gl;gfx")
set(OPENGL_LIBRARIES "gl")
elseif(UNIX AND NOT HAIKU)
set(RENDERER_GL_LIBRARIES "libOpenGL.so")
endif()
if(NOT OPENGL_INCLUDE_DIR OR NOT OPENGL_LIBRARIES)
set(RENDERER_GL_COMPONENTS OpenGL)
if(WINDOW_WAYLAND)
list(APPEND RENDERER_GL_COMPONENTS ";EGL")
list(APPEND RENDERER_GL_LIBRARIES ";OpenGL::EGL")
if(NOT WaylandEGL_INCLUDE_DIR OR NOT WaylandEGL_LIBRARY)
find_package(WaylandEGL REQUIRED)
endif()
include_directories(${WaylandEGL_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${WaylandEGL_LIBRARY})
endif()
find_package(OpenGL REQUIRED COMPONENTS ${RENDERER_GL_COMPONENTS})
endif()
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${RENDERER_GL_LIBRARIES})
endif()
if(WINDOW_X11)
if(NOT X11_INCLUDE_DIRS OR NOT X11_LIBRARIES)
find_package(X11 REQUIRED)
endif()
include_directories(${X11_INCLUDE_DIRS})
endif()
if(WINDOW_WAYLAND)
if(NOT WaylandClient_INCLUDE_DIR OR NOT WaylandClient_LIBRARY)
find_package(WaylandClient REQUIRED)
endif()
include_directories(${WaylandClient_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${WaylandClient_LIBRARY})
if(NOT WaylandCursor_INCLUDE_DIR OR NOT WaylandCursor_LIBRARY)
find_package(WaylandCursor REQUIRED)
endif()
include_directories(${WaylandCursor_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${WaylandCursor_LIBRARY})
if(NOT Libdecor_INCLUDE_DIR OR NOT Libdecor_LIBRARY)
find_package(Libdecor REQUIRED)
endif()
include_directories(${Libdecor_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${Libdecor_LIBRARY})
if(NOT XKBCommon_INCLUDE_DIR OR NOT XKBCommon_LIBRARY)
find_package(XKBCommon REQUIRED)
endif()
include_directories(${XKBCommon_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${XKBCommon_LIBRARY})
endif()
if(WINDOW_HAIKU)
target_link_libraries(${PROJECT_NAME} "be" "game")
endif()
if(NOT OPENAL_INCLUDE_DIR OR NOT OPENAL_LIBRARY)
find_package(OpenAL REQUIRED)
endif()
include_directories("${OPENAL_INCLUDE_DIR}")
target_link_libraries(${PROJECT_NAME} "${OPENAL_LIBRARY}")
if(NOT OGG_INCLUDE_DIR OR NOT OGG_LIBRARY OR NOT VORBIS_INCLUDE_DIR OR NOT VORBIS_LIBRARY)
find_package(OggVorbis REQUIRED)
endif()
include_directories("${OGG_INCLUDE_DIR}")
include_directories("${VORBIS_INCLUDE_DIR}")
target_link_libraries(${PROJECT_NAME} "${VORBIS_LIBRARY}")
target_link_libraries(${PROJECT_NAME} "${OGG_LIBRARY}")
if(NOT PNG_INCLUDE_DIRS OR NOT PNG_LIBRARIES)
find_package(PNG REQUIRED)
endif()
include_directories("${PNG_INCLUDE_DIRS}")
target_link_libraries(${PROJECT_NAME} "${PNG_LIBRARIES}")
if(NOT ZLIB_INCLUDE_DIRS OR NOT ZLIB_LIBRARIES)
find_package(ZLIB REQUIRED)
endif()
include_directories("${ZLIB_INCLUDE_DIRS}")
target_link_libraries(${PROJECT_NAME} "${ZLIB_LIBRARIES}")
if(UNIX AND NOT HAIKU)
target_link_libraries(${PROJECT_NAME} "dl")
endif()
endif()
if(BUILD_SERVER)
add_subdirectory("${CMAKE_SOURCE_DIR}/external/angelscript/angelscript/projects/cmake")
include_directories("${CMAKE_SOURCE_DIR}/external/angelscript/angelscript/include")
include_directories("${CMAKE_SOURCE_DIR}/external/angelscript/add_on")
target_link_libraries(${PROJECT_NAME} "angelscript")
add_library("angelscript_addons" STATIC
external/angelscript/add_on/scriptstdstring/scriptstdstring.cpp
external/angelscript/add_on/scriptstdstring/scriptstdstring_utils.cpp
)
target_link_libraries(${PROJECT_NAME} "angelscript_addons")
endif()
if(WIN32)
target_link_libraries(${PROJECT_NAME} "ws2_32")
endif()
if(SERENITYOS)
target_link_libraries(${PROJECT_NAME} "gcc_s" "gui" "threading" "core")
endif()
if(HAIKU)
target_link_libraries(${PROJECT_NAME} "network")
endif()
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} "${CMAKE_THREAD_LIBS_INIT}")