💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.7 KiB

cmake_minimum_required(VERSION 3.25)
option(APPLICATION_NAME "Application name" "Antkeeper")
option(APPLICATION_VERSION "Application version string" "0.0.0")
option(APPLICATION_AUTHOR "Application author" "C. J. Howard")
# Slugify application name
string(TOLOWER ${APPLICATION_NAME} APPLICATION_SLUG)
string(REPLACE " " "-" APPLICATION_SLUG ${APPLICATION_SLUG})
project(${APPLICATION_SLUG} VERSION ${APPLICATION_VERSION} LANGUAGES CXX)
set(APPLICATION_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(APPLICATION_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(APPLICATION_VERSION_PATCH ${PROJECT_VERSION_PATCH})
# Find dependency packages
find_package(dr_wav REQUIRED CONFIG)
find_package(stb REQUIRED CONFIG)
find_package(tinyexr REQUIRED CONFIG)
find_package(glad REQUIRED CONFIG)
find_package(EnTT REQUIRED CONFIG)
find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED CONFIG)
find_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
find_package(freetype REQUIRED CONFIG)
# Determine dependencies
set(STATIC_LIBS
dr_wav
stb
tinyexr
glad
SDL2::SDL2-static
SDL2::SDL2main
OpenAL::OpenAL
${physfs}
freetype)
set(SHARED_LIBS
${OPENGL_gl_LIBRARY})
# Generate configuration header file
configure_file(${PROJECT_SOURCE_DIR}/src/config.hpp.in
${PROJECT_BINARY_DIR}/src/config.hpp)
# Collect source files
file(GLOB_RECURSE SOURCE_FILES
${PROJECT_SOURCE_DIR}/src/*.cpp)
# Remove platform-specific source files
set(EXCLUDE_DIR "${PROJECT_SOURCE_DIR}/src/platform/")
foreach(TMP_PATH ${SOURCE_FILES})
string(FIND ${TMP_PATH} ${EXCLUDE_DIR} EXCLUDE_DIR_FOUND)
if (NOT ${EXCLUDE_DIR_FOUND} EQUAL -1)
list(REMOVE_ITEM SOURCE_FILES ${TMP_PATH})
endif ()
endforeach(TMP_PATH)
if(MSVC)
# Add platform-specific source files
list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/platform/windows/nvidia.cpp")
# Generate Windows icon resource file
set(ICON_FILE "${PROJECT_SOURCE_DIR}/../antkeeper-data/src/icons/antkeeper.ico")
if(EXISTS "${ICON_FILE}")
configure_file(${PROJECT_SOURCE_DIR}/src/platform/windows/icon.rc.in ${PROJECT_BINARY_DIR}/src/platform/windows/icon.rc)
list(APPEND SOURCE_FILES "${PROJECT_BINARY_DIR}/src/platform/windows/icon.rc")
endif()
# Generate Windows version-information resource file
configure_file(${PROJECT_SOURCE_DIR}/src/platform/windows/version.rc.in ${PROJECT_BINARY_DIR}/src/platform/windows/version.rc)
list(APPEND SOURCE_FILES "${PROJECT_BINARY_DIR}/src/platform/windows/version.rc")
# Make executable DPI-aware on Windows
list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/platform/windows/dpi-aware.manifest")
endif()
# Add executable target
set(EXECUTABLE_TARGET ${APPLICATION_SLUG}-executable)
add_executable(${EXECUTABLE_TARGET} ${SOURCE_FILES})
set_target_properties(${EXECUTABLE_TARGET} PROPERTIES OUTPUT_NAME ${APPLICATION_SLUG})
if(MSVC)
# Select the static multithreaded MSVC runtime library
set_property(TARGET ${EXECUTABLE_TARGET} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
# Add compile definitions
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE DEBUG)
else()
target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE NDEBUG)
endif()
# Set C++ standard
set_target_properties(${EXECUTABLE_TARGET} PROPERTIES
CXX_STANDARD 23
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)
# Set link flags to show console window on debug builds and hide it on release builds
if(MSVC)
#set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libvcruntime.lib")
set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\"")
endif(MSVC)
# Set include directories
target_include_directories(${EXECUTABLE_TARGET}
PUBLIC
${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src)
# Link to dependencies
target_link_libraries(${EXECUTABLE_TARGET} ${STATIC_LIBS} ${SHARED_LIBS})
# Install executable
if(PACKAGE_PLATFORM MATCHES "linux")
install(TARGETS ${EXECUTABLE_TARGET} DESTINATION bin)
elseif(PACKAGE_PLATFORM MATCHES "win")
# Install executable
install(TARGETS ${EXECUTABLE_TARGET} DESTINATION .)
# Install SDL2 DLLs
#if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_DEBUG)
#else()
# get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_RELEASE)
#endif()
#install(FILES ${SDL2_DLL} DESTINATION .)
# Install OpenAL DLL
#if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_DEBUG)
#else()
# get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_RELEASE)
#endif()
#install(FILES ${OPENAL_DLL} DESTINATION .)
endif()