cmake_minimum_required(VERSION 3.16 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(BUILD_CLIENT)
	file(GLOB_RECURSE CLIENT_SOURCES "src/game/**.cpp")
endif()
if(BUILD_SERVER)
	file(GLOB_RECURSE SERVER_SOURCES "src/server/**.cpp")
endif()
file(GLOB_RECURSE COMMON_SOURCES "src/common/**.cpp")
file(GLOB_RECURSE VENDOR_SOURCES "src/vendor/**.cpp")

add_executable(${PROJECT_NAME} ${CLIENT_SOURCES} ${SERVER_SOURCES} ${COMMON_SOURCES} ${VENDOR_SOURCES} src/main.cpp)

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}")

if(NOT GLEW_INCLUDE_DIRS OR NOT GLEW_LIBRARIES)
	find_package(GLEW REQUIRED)
endif()
include_directories("${GLEW_INCLUDE_DIRS}")
target_link_libraries(${PROJECT_NAME} "${GLEW_LIBRARIES}")

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(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(WIN32)
	target_link_libraries(${PROJECT_NAME} "ws2_32")
endif()

if(UNIX)
	target_link_libraries(${PROJECT_NAME} "dl")
endif()

find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} "${CMAKE_THREAD_LIBS_INIT}")

