Files
PolyGun/CMakeLists.txt
2023-05-02 16:16:56 +02:00

153 lines
3.9 KiB
CMake

cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
project(polygun)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED true)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake")
include_directories(deps)
include_directories("${CMAKE_SOURCE_DIR}/src")
include_directories("${CMAKE_BINARY_DIR}")
configure_file("config.hpp.in" "config.hpp")
option(BUILD_CLIENT "Build client" ON)
option(BUILD_SERVER "Build server" ON)
if(APPLE)
set(RENDERER_GL_DEFAULT OFF)
else()
set(RENDERER_GL_DEFAULT ON)
endif()
option(RENDERER_GL "Enable OpenGL renderer" ${RENDERER_GL_DEFAULT})
if(NOT BUILD_CLIENT)
set(RENDERER_GL OFF)
endif()
option(LIBRARY_GLFW3_STATIC "Enable tweaks when using static GLFW3" OFF)
if(BUILD_CLIENT)
file(GLOB_RECURSE CLIENT_SOURCES "src/game/**.cpp")
file(GLOB_RECURSE VENDOR_SOURCES "src/vendor/**.cpp")
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()
if(RENDERER_GL)
file(GLOB_RECURSE RENDERER_GL_SOURCES "src/game/renderer/gl/**.cpp")
endif()
file(GLOB_RECURSE COMMON_SOURCES "src/common/**.cpp")
if(BUILD_SERVER AND NOT BUILD_CLIENT)
set(PROJECT_NAME "polygun_server")
endif()
if(NOT BUILD_CLIENT AND NOT BUILD_CLIENT)
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}
${VENDOR_SOURCES}
${RENDERER_GL_SOURCES}
src/main.cpp
)
if(BUILD_CLIENT)
if(NOT GLFW3_INCLUDE_DIR OR NOT GLFW3_LIBRARY)
find_package(GLFW3 REQUIRED)
endif()
include_directories("${GLFW3_INCLUDE_DIR}")
target_link_libraries(${PROJECT_NAME} "${GLFW3_LIBRARY}")
if(LIBRARY_GLFW3_STATIC)
if(X11_LIBRARIES)
set(X11_FOUND TRUE)
else()
find_package(X11)
endif()
if(X11_FOUND)
target_link_libraries(${PROJECT_NAME} "${X11_LIBRARIES}")
else()
if(WAYLAND_LIBRARIES)
set(WAYLAND_FOUND TRUE)
else()
find_package(Wayland)
endif()
if(WAYLAND_FOUND)
target_link_libraries(${PROJECT_NAME} "${WAYLAND_LIBRARIES}")
else()
message(FATAL_ERROR "While statically linking GLFW3 you have to provide X11 or Wayland libraries")
endif()
endif()
endif()
if(RENDERER_GL)
if(NOT OPENGL_INCLUDE_DIR OR NOT OPENGL_LIBRARIES)
find_package(OpenGL REQUIRED)
endif()
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} "${OPENGL_LIBRARIES}")
endif()
if(NOT GLM_INCLUDE_DIRS)
find_package(GLM REQUIRED)
endif()
include_directories("${GLM_INCLUDE_DIRS}")
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)
target_link_libraries(${PROJECT_NAME} "dl")
endif()
endif()
if(WIN32)
target_link_libraries(${PROJECT_NAME} "ws2_32")
endif()
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} "${CMAKE_THREAD_LIBS_INIT}")