Files
c-evo-evo/CMakeLists.txt
T
2026-10-27 14:57:47 +01:00

171 lines
6.3 KiB
CMake

# This file is part of cevo-evo.
#
# This software is governed by the CeCILL license under French law and
# abiding by the rules of distribution of free software. You can use,
# modify and/or redistribute the software under the terms of the CeCILL
# license as circulated by CEA, CNRS and INRIA at the following URL
# "http://www.cecill.info".
#
# As a counterpart to the access to the source code and rights to copy,
# modify and redistribute granted by the license, users are provided only
# with a limited warranty and the software's author, the holder of the
# economic rights, and the successive licensors have only limited
# liability.
#
# In this respect, the user's attention is drawn to the risks associated
# with loading, using, modifying and/or developing or reproducing the
# software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also
# therefore means that it is reserved for developers and experienced
# professionals having in-depth computer knowledge. Users are therefore
# encouraged to load and test the software's suitability as regards their
# requirements in conditions enabling the security of their systems and/or
# data to be ensured and, more generally, to use and operate it in the
# same conditions as regards security.
#
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL license and that you accept its terms.
cmake_minimum_required(VERSION 3.16)
project(cevo-evo VERSION 0.1 LANGUAGES CXX)
option(CEVO_WITH_APP "Build the game application (widget/media + cevo-evo executable)" ON)
option(CEVO_WITH_AI "Build and install the bundled stdai AI plugin (turn off to rely on a third-party AI module instead)" ON)
if(NOT CEVO_WITH_APP AND NOT CEVO_WITH_AI)
message(FATAL_ERROR "Nothing to build: enable at least one of CEVO_WITH_APP or CEVO_WITH_AI")
endif()
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ai/stdai has no Qt dependency, so only require Qt when building the app.
if(CEVO_WITH_APP)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Multimedia Xml LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Multimedia Xml LinguistTools)
endif()
include(GNUInstallDirs)
# Extra install dirs, following GNUInstallDirs' own CACHE PATH convention
# (relative to CMAKE_INSTALL_PREFIX unless given as an absolute path).
set(CMAKE_INSTALL_AIDIR "${CMAKE_INSTALL_LIBDIR}/cevo-evo/ai" CACHE PATH
"AI plugin modules (e.g. stdai) - where the game looks for loadable AI brains")
set(CMAKE_INSTALL_RESOURCEDIR "${CMAKE_INSTALL_DATADIR}/cevo-evo" CACHE PATH
"Game resources (graphics, music, sounds, resource translations)")
foreach(_cevo_dir AIDIR RESOURCEDIR)
if(IS_ABSOLUTE "${CMAKE_INSTALL_${_cevo_dir}}")
set(CMAKE_INSTALL_FULL_${_cevo_dir} "${CMAKE_INSTALL_${_cevo_dir}}")
else()
set(CMAKE_INSTALL_FULL_${_cevo_dir} "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_${_cevo_dir}}")
endif()
endforeach()
# ai/ is the generic AI-plugin interface: needed by the app (to load AI
# modules at runtime) and by the bundled stdai plugin (as its base classes).
if(CEVO_WITH_APP OR CEVO_WITH_AI)
add_subdirectory(ai)
endif()
# stdai is a dynamically-loaded AI plugin (see ai/stdai/CMakeLists.txt): built
# here but deliberately NOT linked into the cevo-evo target below.
if(CEVO_WITH_AI)
add_subdirectory(ai/stdai)
endif()
if(CEVO_WITH_APP)
add_subdirectory(widget)
add_subdirectory(media)
add_subdirectory(common)
add_subdirectory(game)
add_subdirectory(resources)
set(TS_FILES cevo-evo_en_US.ts)
set(PROJECT_SOURCES
main.cpp
game/mainwindow.cpp
game/mainwindow.h
game/mainwindow.ui
game/Brain.cpp
game/Brain.h
game/Log.cpp
game/Log.h
game/Log.ui
game/Messg.cpp
game/Messg.h
game/Messg.ui
${TS_FILES}
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(cevo-evo
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET cevo-evo APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
else()
if(ANDROID)
add_library(cevo-evo SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(cevo-evo
${PROJECT_SOURCES}
)
endif()
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif()
target_link_libraries(cevo-evo PRIVATE Qt${QT_VERSION_MAJOR}::Widgets dpiwidgets cevowidgets uosmedia cevocommon cevogame cevoai)
# dpiwidgets/cevowidgets/uosmedia are installed to lib/cevo-evo (not the
# default library directory), so the installed binary needs an explicit
# rpath to find them at runtime.
set_target_properties(cevo-evo PROPERTIES
INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}/cevo-evo"
)
# Default, compile-time-known locations the game looks for its AI plugins
# and its resources (graphics/music/sounds/translations) at runtime.
target_compile_definitions(cevo-evo PRIVATE
CEVO_AI_DIR="${CMAKE_INSTALL_FULL_AIDIR}"
CEVO_RESOURCE_DIR="${CMAKE_INSTALL_FULL_RESOURCEDIR}"
)
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.cevo-evo)
endif()
set_target_properties(cevo-evo PROPERTIES
${BUNDLE_ID_OPTION}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
install(TARGETS cevo-evo
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(cevo-evo)
endif()
endif() # CEVO_WITH_APP