2023-02-07 21:18:17 +01:00
cmake_minimum_required(VERSION 3.5)
2023-05-18 20:24:09 +02:00
project(openmohaa)
2023-01-29 21:00:43 +01:00
2023-02-01 00:29:02 +01:00
include(TargetArch.cmake)
target_architecture(TARGET_ARCH)
2024-10-07 20:51:23 +02:00
set(USE_INTERNAL_LIBS ON)
if(USE_SYSTEM_LIBS)
set(USE_INTERNAL_LIBS OFF)
endif()
option(USE_INTERNAL_JPEG "If set, use bundled libjpeg." ${USE_INTERNAL_LIBS})
option(USE_INTERNAL_MAD "If set, use bundled libmad." ${USE_INTERNAL_LIBS})
option(USE_INTERNAL_ZLIB "If set, use bundled zlib." ${USE_INTERNAL_LIBS})
2023-01-30 18:39:52 +01:00
if(TARGET_GAME_TYPE)
2023-07-02 20:06:15 +02:00
message(SEND_ERROR "TARGET_GAME_TYPE is now unsupported, it is now done at runtime.")
2023-01-30 18:39:52 +01:00
endif()
2023-07-02 20:06:15 +02:00
2023-08-25 22:57:23 +02:00
set(TARGET_BASE_GAME "./")
2023-08-15 12:57:36 +02:00
set(CMAKE_DEBUG_POSTFIX "-dbg")
2023-01-30 18:39:52 +01:00
2024-10-14 20:34:19 +02:00
#
# Microsoft compiler specific parameters
#
2023-01-30 18:39:52 +01:00
if(MSVC)
2023-02-07 21:18:17 +01:00
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
2023-12-07 18:32:10 +01:00
# Treat no return type as error
add_compile_options(/we4715)
endif()
2024-10-14 20:34:19 +02:00
#
# Clang and GCC specific parameters
#
if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
2023-02-01 00:29:02 +01:00
add_compile_options(-Wno-comment)
2023-12-07 18:32:10 +01:00
# Treat no return type as error
add_compile_options(-Werror=return-type)
endif()
2024-10-14 20:34:19 +02:00
#
# Clang specific parameters
#
2023-12-07 18:32:10 +01:00
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
2023-02-01 00:29:02 +01:00
# Ignore warnings for code like 'assert("Assert string")'
add_compile_options(-Wno-pointer-bool-conversion)
2023-01-30 18:39:52 +01:00
endif()
2024-10-14 20:34:19 +02:00
#
# GCC specific parameters
#
2023-09-09 17:54:04 +02:00
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Add this option on gcc to prevent functions from having the STB_GNU_UNIQUE binding
# Otherwise, it would prevent libraries from being unloaded
# which will cause undefined behavior and crashes due to memory corruption
add_compile_options(-fno-gnu-unique)
endif()
2023-08-19 02:19:09 +02:00
if(DEBUG_MEMORY)
add_definitions(-D_DEBUG_MEM)
endif()
2023-05-24 01:07:45 +02:00
IF("${TARGET_ARCH}" STREQUAL "i386")
2023-02-01 22:45:04 +01:00
set(TARGET_ARCH_SUFFIX "x86")
ELSE()
set(TARGET_ARCH_SUFFIX ${TARGET_ARCH})
ENDIF()
2023-01-29 21:00:43 +01:00
2024-09-22 14:56:02 +02:00
set(TARGET_BIN_SUFFIX ".${TARGET_ARCH}")
2023-07-02 20:06:15 +02:00
message(STATUS "Architecture detected: ${TARGET_ARCH}, suffix set to ${TARGET_ARCH_SUFFIX}.")
2023-02-01 00:29:02 +01:00
IF(WIN32)
set(TARGET_PLATFORM_PREFIX "")
message(STATUS "Using Win32 naming convention")
ELSEIF(UNIX)
2023-02-01 22:45:04 +01:00
set(TARGET_PLATFORM_PREFIX "")
2023-02-01 00:29:02 +01:00
message(STATUS "Using Unix naming convention")
ELSE()
set(TARGET_PLATFORM_PREFIX "")
ENDIF()
2023-02-05 14:15:24 +01:00
IF(CMAKE_BUILD_TYPE MATCHES Debug)
2024-10-27 15:24:22 +01:00
add_compile_definitions(_DEBUG)
2023-05-24 00:49:28 +02:00
2023-08-26 20:22:39 +02:00
# NOTE: The following may mess up function importation
2023-05-29 01:49:10 +02:00
#if(UNIX)
# # Enable all exports so all functions name can be seen during executable crash
# set(CMAKE_ENABLE_EXPORTS ON)
# message(STATUS "Enabling exports on Unix for backtrace")
#endif()
2024-10-27 15:24:22 +01:00
ELSE()
# Non-debug builds
add_compile_definitions(NDEBUG)
2023-02-05 14:15:24 +01:00
ENDIF()
2024-10-09 19:24:34 +02:00
if(APPLE)
# macOS doesn't search the executable path by default
# so, locate libraries like SDL in the executable path
set(CMAKE_INSTALL_RPATH "@executable_path")
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
2024-10-25 22:01:49 +02:00
if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")
# Set the visibility to hidden on macOS to prevent shared libraries from
# using functions in the executable
# it's ok to hide them because the backtrace on macOS will still print the name of the functions
add_compile_options(-fvisibility=hidden)
endif()
2024-10-09 19:24:34 +02:00
endif()
2024-11-21 19:23:38 +01:00
#
# Setup the installation directory
#
if(WIN32)
# By default, both DLLs and EXEs are in the same directory
set(CMAKE_DEFAULT_INSTALL_RUNTIME_DIR bin)
set(BIN_INSTALL_SUBDIR ".")
set(LIB_INSTALL_SUBDIR ".")
else()
# Unix
set(CMAKE_DEFAULT_INSTALL_RUNTIME_DIR lib)
set(BIN_INSTALL_SUBDIR ${CMAKE_PROJECT_NAME})
set(LIB_INSTALL_SUBDIR ${CMAKE_PROJECT_NAME})
endif()
2023-04-30 01:45:26 +02:00
2024-11-21 19:23:38 +01:00
# By default, put both binaries and shared libraries in the same directory
# the game uses internal shared libraries that must be in the same folder as the binaries
set(CMAKE_INSTALL_BINDIR ${CMAKE_DEFAULT_INSTALL_RUNTIME_DIR} CACHE PATH "Binary dir")
set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Library dir")
include(GNUInstallDirs)
#
# Common stuff
#
2023-06-17 01:44:38 +02:00
add_subdirectory("code/qcommon")
add_subdirectory("code/gamespy")
2023-04-30 01:45:26 +02:00
2024-11-21 19:23:38 +01:00
#
2023-06-17 01:44:38 +02:00
# Application
2024-11-21 19:23:38 +01:00
#
2023-06-17 01:44:38 +02:00
add_subdirectory("code/sys")
2023-04-30 20:37:50 +02:00
2024-11-21 19:23:38 +01:00
##
2023-06-17 01:44:38 +02:00
## Server app
2024-11-21 19:23:38 +01:00
##
2023-06-17 01:44:38 +02:00
add_subdirectory("code/server")
2023-01-30 18:39:52 +01:00
2023-06-17 01:44:38 +02:00
add_executable(omohaaded "code/null/null_client.c" "code/null/null_input.c" "code/null/null_snddma.c")
target_compile_definitions(omohaaded PRIVATE APP_MODULE DEDICATED)
2023-02-08 14:04:47 +01:00
target_compile_features(omohaaded PUBLIC cxx_nullptr)
2023-02-08 14:26:01 +01:00
target_compile_features(omohaaded PUBLIC c_variadic_macros)
2023-06-17 01:44:38 +02:00
target_link_libraries(omohaaded PRIVATE omohserver)
target_link_libraries(omohaaded PRIVATE syslib)
target_link_libraries(omohaaded PRIVATE qcommon qcommon_standalone)
2023-08-26 20:22:39 +02:00
2024-11-21 19:23:38 +01:00
# Add the gamespy dependency
2023-06-17 01:44:38 +02:00
target_include_directories(omohaaded PUBLIC "code/qcommon" "code/script" "code/gamespy" "code/server")
2024-09-22 14:56:02 +02:00
set_target_properties(omohaaded PROPERTIES OUTPUT_NAME "omohaaded${TARGET_BIN_SUFFIX}")
2023-08-15 12:57:36 +02:00
set_target_properties(omohaaded PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
2023-01-29 21:00:43 +01:00
2024-11-21 19:23:38 +01:00
INSTALL(TARGETS omohaaded DESTINATION ${CMAKE_INSTALL_BINDIR}/${BIN_INSTALL_SUBDIR})
2023-06-17 02:09:50 +02:00
if (MSVC)
target_link_options(omohaaded PRIVATE "/MANIFEST:NO")
2024-11-21 19:23:38 +01:00
INSTALL(FILES $<TARGET_PDB_FILE:omohaaded> DESTINATION ${CMAKE_INSTALL_BINDIR}/${BIN_INSTALL_SUBDIR} OPTIONAL)
2023-01-29 21:00:43 +01:00
endif()
2023-01-29 23:31:13 +01:00
2023-08-14 13:31:42 +02:00
if (NOT BUILD_NO_CLIENT)
2024-11-21 19:23:38 +01:00
##
2023-06-17 01:44:38 +02:00
## Client app
2024-11-21 19:23:38 +01:00
##
2024-11-20 15:40:01 +00:00
2024-08-21 18:35:06 +02:00
add_subdirectory("code/client")
2023-06-17 01:44:38 +02:00
add_subdirectory("code/renderer")
add_subdirectory("code/sdl")
2023-05-27 22:23:03 +02:00
#include("code/renderergl2/glsl/shaders.cmake")
#file(GLOB_RECURSE SOURCES_RENDERER "code/sdl/*.c" "code/renderercommon/*.c" "code/renderergl2/*.c" "code/renderergl2/*.cpp")
#list(FILTER SOURCES_RENDERER EXCLUDE REGEX "code/renderergl2/tr_subs.c")
#list(FILTER SOURCES_RENDERER EXCLUDE REGEX "code/renderergl2/tr_model.c")
2023-06-18 12:24:21 +02:00
add_executable(openmohaa "misc/dummy.c")
2023-06-17 01:44:38 +02:00
target_link_libraries(openmohaa PRIVATE syslib)
target_link_libraries(openmohaa PRIVATE omohserver)
target_link_libraries(openmohaa PRIVATE omohclient)
target_link_libraries(openmohaa PRIVATE omohrenderer omohsdl)
target_link_libraries(openmohaa PRIVATE qcommon qcommon_standalone)
2024-11-21 19:23:38 +01:00
# Add the gamespy dependency
2024-10-07 20:51:23 +02:00
target_include_directories(openmohaa PUBLIC "code/qcommon" "code/script" "code/gamespy" "code/server" "code/client" "code/uilib")
2024-09-22 14:56:02 +02:00
set_target_properties(openmohaa PROPERTIES OUTPUT_NAME "openmohaa${TARGET_BIN_SUFFIX}")
2023-08-15 12:57:36 +02:00
set_target_properties(openmohaa PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
2023-05-29 19:03:56 +02:00
2024-11-21 19:23:38 +01:00
if(USE_INTERNAL_JPEG)
target_include_directories(openmohaa PUBLIC "code/jpeg-8c")
target_link_libraries(openmohaa PRIVATE jpeg8)
else()
find_package(JPEG REQUIRED)
target_include_directories(openmohaa PUBLIC ${JPEG_INCLUDE_DIRS})
target_link_libraries(openmohaa PRIVATE ${JPEG_LIBRARIES})
endif()
INSTALL(TARGETS openmohaa DESTINATION ${CMAKE_INSTALL_BINDIR}/${BIN_INSTALL_SUBDIR})
2024-11-20 15:40:01 +00:00
2024-11-21 19:23:38 +01:00
if (MSVC)
target_link_options(openmohaa PRIVATE "/MANIFEST:NO")
INSTALL(FILES $<TARGET_PDB_FILE:openmohaa> DESTINATION ${CMAKE_INSTALL_BINDIR}/${BIN_INSTALL_SUBDIR} OPTIONAL)
endif()
if(UNIX AND NOT APPLE)
#
# Desktop entries installation on Unix
#
2024-11-20 15:40:01 +00:00
set(TARGET_ARCH ${TARGET_BIN_SUFFIX})
# Configure the .desktop entries with the arch suffix
configure_file(
misc/linux/org.openmoh.openmohaa.desktop.in
${CMAKE_BINARY_DIR}/misc/linux/org.openmoh.openmohaa.desktop
@ONLY
)
configure_file(
misc/linux/org.openmoh.openmohaab.desktop.in
${CMAKE_BINARY_DIR}/misc/linux/org.openmoh.openmohaab.desktop
@ONLY
)
configure_file(
misc/linux/org.openmoh.openmohaas.desktop.in
${CMAKE_BINARY_DIR}/misc/linux/org.openmoh.openmohaas.desktop
@ONLY
)
# Install .desktop entries
2024-11-21 19:23:38 +01:00
install(FILES ${CMAKE_BINARY_DIR}/misc/linux/org.openmoh.openmohaa.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES ${CMAKE_BINARY_DIR}/misc/linux/org.openmoh.openmohaab.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES ${CMAKE_BINARY_DIR}/misc/linux/org.openmoh.openmohaas.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
2024-11-20 15:40:01 +00:00
2024-11-21 19:23:38 +01:00
install(FILES misc/linux/org.openmoh.openmohaa.metainfo.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo)
2024-11-20 15:40:01 +00:00
2024-11-21 19:23:38 +01:00
install(FILES misc/openmohaa.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/symbolic/apps/ RENAME org.openmoh.openmohaa.svg)
2024-11-20 15:40:01 +00:00
endif()
2023-04-30 01:45:26 +02:00
endif()
2024-11-03 23:47:57 +01:00
2024-11-21 19:23:38 +01:00
#
2024-11-03 23:47:57 +01:00
# Launcher
2024-11-21 19:23:38 +01:00
#
2024-11-03 23:47:57 +01:00
add_subdirectory(code/Launcher)
2024-11-20 17:01:30 +00:00
2024-11-21 19:23:38 +01:00
#
2024-11-20 17:01:30 +00:00
# uninstall target
2024-11-21 19:23:38 +01:00
#
2024-11-20 17:01:30 +00:00
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()