From c8deaa7d785650df009b5e882e0e5e3d2ea1e900 Mon Sep 17 00:00:00 2001 From: Olanti Date: Sat, 23 Sep 2023 07:54:42 +0300 Subject: [PATCH] [DDA Port] Various improvements to CMake builds (#3208) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Change glob pattern to include alphabetic versions (0.A, ...) Cherry-picked from commit 35e3ee7bf1da028c87757a2f7c882dc45e3822a7 * Fix cmake not generating game version correctly Cherry-picked from commit de1a6ccc325e0682983f3f19446822e4c8e5a514 * CMake linting * format cmake files to adhere to linting rules * cmake linting workflow/action Cherry-picked from a149ceb00807a323cd7eba5fa7a3a7c8b3b0b1b2 * Apply cmake-format * Autofix CMake formatting * Apply cmake-format x2 * Remove dupe conditions from else and endif * Split up long message lines * Remove mentions of INSTALL file. * Improve CMake build script for macOS Cherry-picked from commit 84165ee535561773058130402510657b3621edf1 * cmake: install help directory Cherry-picked from commit 7e588b20ec89abf6de6f674975f814803d9c5e7e * cmake: don't use PREFIX `PREFIX` is a reserved word in CMake and breaks compiler and library detection when set. Using `CMAKE_INSTALL_PREFIX` instead resolves this. Cherry-picked from commit: 7cbcecb18f3c9f91160a0ec45a04d61221096670 * cmake: set RELEASE variable to generate install target Cherry-picked from commit: db8f0d3de2f69c4b355afc9a6153da8abeb63f54 * Set directories on macOS in CMake build script Cherry-picked from commit: 45f6a3b77fd07563a4625b1f313d2c4cb797db0d * cmake: simplify random seed generation for tests Cherry-picked from commit ff4db050877c4cdcb9ae2e5b247eb4f70c1d3eb4 * Fix style * Allow build and run in repo folder in CMake Cherry-picked from commit: 256ef3388407e66b9edaac91ef5993a89511fad7 * Avoid ambiguity in CMake if commands Cherry-picked from commit: f9008b743357fd0eeed206437d284864783015a1 * Fix compilation on MSYS curses emulation environment Cherry-picked from commit: 69a29a0c8ca772ba4ac7b27fefbc7fc48895258e * Install cmake-format for autofix * Bump cmake_minimum_required for chkjson * Fix error in lang install dir --------- Co-authored-by: Kasper Rasmussen Co-authored-by: Jianxiang Wang (王健翔) Co-authored-by: lopho Co-authored-by: Binrui Dong Co-authored-by: J.W. Jagersma Co-authored-by: John Bytheway <52664+jbytheway@users.noreply.github.com> --- .cmake-format.yml | 43 ++ .github/workflows/autofix.yml | 5 + CMakeLists.txt | 611 +++++++++--------- Makefile | 19 + cmake_uninstall.cmake.in | 45 +- data/CMakeLists.txt | 33 +- .../docs/en/dev/guides/building/cmake.md | 4 + lang/CMakeLists.txt | 107 ++- src/CMakeLists.txt | 269 ++++---- src/chkjson/CMakeLists.txt | 39 +- src/ncurses_def.cpp | 1 + src/version.cmake | 23 +- tests/CMakeLists.txt | 57 +- tools/clang-tidy-plugin/CMakeLists.txt | 48 +- tools/format/CMakeLists.txt | 10 +- 15 files changed, 661 insertions(+), 653 deletions(-) create mode 100644 .cmake-format.yml diff --git a/.cmake-format.yml b/.cmake-format.yml new file mode 100644 index 000000000000..ca7a01af99c8 --- /dev/null +++ b/.cmake-format.yml @@ -0,0 +1,43 @@ +# options affecting formatting +format: + # how wide to allow formatted cmake files + line_width: 100 + # how many spaces to tab for indent + tab_size: 4 + # if true, separate flow control names from their parentheses + separate_ctrl_name_with_space: true # currently ignored by cmake-lint + # if true, separate function names from parentheses with a + separate_fn_name_with_space: false # currently ignored by cmake-lint + # if a statement is wrapped to more than one line, than dangle + # the closing parenthesis on its own line. + dangle_parens: false # currently ignored by cmake-lint + # Format command names consistently as 'lower' or 'upper' case + # 'canonical': like in official documentation + command_case: 'canonical' # currently ignored by cmake-lint + # Format keywords consistently as 'lower' or 'upper' case + keyword_case: 'upper' # currently ignored by cmake-lint +# options affecting comment reflow and formatting +markup: + # enable comment markup parsing and reflow + enable_markup: false +# options affecting linter +lint: + # list of lint codes to disable + # C0113: Missing COMMENT in statement which allows it + disabled_codes: ['C0113'] + # regular expression pattern describing valid function names + function_pattern: '[a-z_]+' + # regular expression pattern describing valid names for private variables + # WEIRD: strangely named "directory variable name" in lint output + private_var_pattern: '_[0-9A-Z_]+' + # regular expression pattern describing valid names for public variables (strangely named "directories"?) + # WEIRD: strangely named "directory variable name" in lint output + public_var_pattern: '[0-9A-Z]+' + # regular expression pattern describing valid macro names + macro_pattern: '[a-z_]+' + # regular expression pattern describing valid names for function/macro + # arguments and loop variables + argument_var_pattern: '[A-Z][A-Z0-9_]+' + # require no more than this many newlines between statements + max_statement_spacing: 2 + diff --git a/.github/workflows/autofix.yml b/.github/workflows/autofix.yml index 5446dbae4a90..8f240ea59ed9 100644 --- a/.github/workflows/autofix.yml +++ b/.github/workflows/autofix.yml @@ -18,6 +18,8 @@ jobs: - run: sudo apt-get install astyle + - run: sudo pip install cmakelang + - uses: denoland/setup-deno@v1 with: deno-version: v1.x @@ -28,6 +30,9 @@ jobs: - name: format markdown files run: deno fmt + - name: format CMake files + run: make cmake-format + - name: json formatting run: make style-all-json-parallel RELEASE=1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 295b46baf743..c38a126a9d33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,90 +1,107 @@ # Main project build script cmake_minimum_required(VERSION 3.16) -PROJECT(CataclysmBN) +project(CataclysmBN) -SET(CMAKE_MODULE_PATH - ${CMAKE_MODULE_PATH} - ${CMAKE_SOURCE_DIR}/CMakeModules -) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMakeModules) -INCLUDE(AstyleFormatSource) +include(AstyleFormatSource) -SET(CMAKE_TLS_VERIFY ON) +set(CMAKE_TLS_VERIFY ON) # Build options -option(TILES "Build graphical tileset version." "OFF") -option(CURSES "Build curses version." "ON") -option(SOUND "Support for in-game sounds & music." "OFF") -option(LUA "Support for in-game scripting with Lua." "OFF") -option(BACKTRACE "Support for printing stack backtraces on crash" "ON") -option(LIBBACKTRACE "Print backtrace with libbacktrace." "OFF") -option(USE_HOME_DIR "Use user's home directory for save files." "ON") -set(LANGUAGES "" CACHE STRING "Compile localization files for specified languages. List of language ids separated by semicolon. Set to 'all' or leave empty to compile all, set to 'none' to compile none.") -option(DYNAMIC_LINKING "Use dynamic linking. Or use static to remove MinGW dependency instead." "ON") +option(TILES "Build graphical tileset version." "OFF") +option(CURSES "Build curses version." "ON") +option(SOUND "Support for in-game sounds & music." "OFF") +option(LUA "Support for in-game scripting with Lua." "OFF") +option(BACKTRACE "Support for printing stack backtraces on crash" "ON") +option(LIBBACKTRACE "Print backtrace with libbacktrace." "OFF") +option(USE_HOME_DIR "Use user's home directory for save files." "ON") +option(USE_PREFIX_DATA_DIR "Use UNIX system directories for game data in release build." "ON") +set(LANGUAGES + "" + CACHE STRING "Compile localization files for specified languages. \ + List of language ids separated by semicolon. \ + Set to 'all' or leave empty to compile all, set to 'none' to compile none.") +option(DYNAMIC_LINKING "Use dynamic linking. Or use static to remove MinGW dependency instead." + "ON") option(USE_UNITY_BUILD "Use unity build." "OFF") option(USE_PCH_HEADER "Use precompiled PCH header." "OFF") -option(JSON_FORMAT "Build JSON formatter" "OFF") -option(CATA_CCACHE "Try to find and build with ccache" "ON") +option(JSON_FORMAT "Build JSON formatter" "OFF") +option(CATA_CCACHE "Try to find and build with ccache" "ON") option(CATA_CLANG_TIDY_PLUGIN "Build Cata's custom clang-tidy plugin" "OFF") -set(CATA_CLANG_TIDY_INCLUDE_DIR "" CACHE STRING "Path to internal clang-tidy headers required for plugin (e.g. ClangTidy.h)") -set(CATA_CHECK_CLANG_TIDY "" CACHE STRING "Path to check_clang_tidy.py for plugin tests") -set(GIT_BINARY "" CACHE STRING "Git binary name or path.") -set(PREFIX "" CACHE STRING "Location of Data & GFX directories") -set(LINKER "" CACHE STRING "Custom Linker to use") +set(CATA_CLANG_TIDY_INCLUDE_DIR + "" + CACHE STRING "Path to internal clang-tidy headers required for plugin (e.g. ClangTidy.h)") +set(CATA_CHECK_CLANG_TIDY + "" + CACHE STRING "Path to check_clang_tidy.py for plugin tests") +set(GIT_BINARY + "" + CACHE STRING "Git binary name or path.") +set(LINKER + "" + CACHE STRING "Custom Linker to use") include(CTest) include(GetGitRevisionDescription) -git_describe(GIT_VERSION) +git_describe(GIT_VERSION --tags --always --match "[0-9A-Z]*.[0-9A-Z]*") -MESSAGE("\n * Cataclysm: Bright Nights is a roguelike set in a post-apocalyptic world.") -MESSAGE(" _________ __ .__ ") -MESSAGE(" \\_ ___ \\ _____ _/ |_ _____ ____ | | ___.__ ______ _____ ") -MESSAGE(" / \\ \\/ \\__ \\ \\ __\\\\__ \\ _/ ___\\ | | < | | / ___/ / \\ ") -MESSAGE(" \\ \\____ / __ \\_ | | / __ \\_\\ \\___ | |__ \\___ | \\___ \\ | Y Y \\ ") -MESSAGE(" \\______ /\(____ / |__| \(____ / \\___ >|____/ / ____|/____ >|__|_| / ") -MESSAGE(" \\/ \\/ \\/ \\/ \\/ \\/ \\/ ") -MESSAGE(" --= Bright Nights =--") +message("\n * Cataclysm: Bright Nights is a roguelike set in a post-apocalyptic world.") +message(" _________ __ .__ ") +message(" \\_ ___ \\ _____ _/ |_ _____ ____ | | ___.__ ______ _____ ") +message( + " / \\ \\/ \\__ \\ \\ __\\\\__ \\ _/ ___\\ | | < | | / ___/ / \\ ") +message( + " \\ \\____ / __ \\_ | | / __ \\_\\ \\___ | |__ \\___ | \\___ \\ | Y Y \\ ") +message(" \\______ /\(____ / |__| \(____ / \\___ >|____/ / ____|/____ >|__|_| / ") +message(" \\/ \\/ \\/ \\/ \\/ \\/ \\/ ") +message(" --= Bright Nights =--") -MESSAGE("\n * https://github.com/cataclysmbnteam/Cataclysm-BN\n") +message("\n * https://github.com/cataclysmbnteam/Cataclysm-BN\n") -MESSAGE(STATUS "${PROJECT} build environment -- \n") +message(STATUS "${PROJECT} build environment -- \n") -MESSAGE(STATUS "Build realm is : ${CMAKE_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_PROCESSOR}") +message( + STATUS "Build realm is : ${CMAKE_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_PROCESSOR}") -IF(LINKER) +if (LINKER) add_link_options("-fuse-ld=${LINKER}") -ENDIF() +endif () -IF(NOT CMAKE_BUILD_TYPE) +if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) -ENDIF(NOT CMAKE_BUILD_TYPE) +endif () -ADD_DEFINITIONS(-DCMAKE) +add_definitions(-DCMAKE) -if (NOT ${GIT_VERSION} MATCHES GIT-NOTFOUND) +if (NOT "${GIT_VERSION}" MATCHES "GIT-NOTFOUND") string(REPLACE "-NOTFOUND" "" GIT_VERSION ${GIT_VERSION}) - FILE(WRITE ${CMAKE_SOURCE_DIR}/src/version.h - "// NOLINT(cata-header-guard)\n\#define VERSION \"${GIT_VERSION}\"\n") - MESSAGE(STATUS "${PROJECT_NAME} build version is : ${GIT_VERSION}\n") - ADD_DEFINITIONS(-DGIT_VERSION) -ELSE (NOT ${GIT_VERSION} MATCHES GIT-NOTFOUND) - MESSAGE("") -ENDIF(NOT ${GIT_VERSION} MATCHES GIT-NOTFOUND) + file(WRITE ${CMAKE_SOURCE_DIR}/src/version.h + "// NOLINT(cata-header-guard)\n\#define VERSION \"${GIT_VERSION}\"\n") + message(STATUS "${PROJECT_NAME} build version is : ${GIT_VERSION}\n") + add_definitions(-DGIT_VERSION) +else () + message("") +endif () #OS Check Placeholders. Will be used for BINDIST -IF (${CMAKE_SYSTEM_NAME} MATCHES Linux) - SET(_OS_LINUX_ 1) -ENDIF (${CMAKE_SYSTEM_NAME} MATCHES Linux) - -IF (${CMAKE_SYSTEM_NAME} MATCHES FreeBSD) - SET(_OS_FREEBSD_ 1) -ENDIF (${CMAKE_SYSTEM_NAME} MATCHES FreeBSD) - -IF(${CMAKE_SYSTEM_NAME} MATCHES Darwin) - SET(_OS_DARWIN_ 1) -ENDIF(${CMAKE_SYSTEM_NAME} MATCHES Darwin) +if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") + set(_OS_LINUX_ 1) +endif () + +if ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD") + set(_OS_FREEBSD_ 1) +endif () + +if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + set(_OS_DARWIN_ 1) + add_definitions(-DMACOSX) + if (TILES) + add_definitions(-DOSX_SDL2_LIBS) + endif () +endif () include(CheckCXXCompilerFlag) @@ -95,142 +112,142 @@ include(CheckCXXCompilerFlag) #SET(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} -m32") #SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} -m32") -IF (NOT DYNAMIC_LINKING) - SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.dll.a") - SET(BUILD_SHARED_LIBRARIES OFF) - check_cxx_compiler_flag (-static HAVE_STATIC_FLAG) - IF(HAVE_STATIC_FLAG) - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") - ENDIF(HAVE_STATIC_FLAG) +if (NOT DYNAMIC_LINKING) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.dll.a") + set(BUILD_SHARED_LIBRARIES OFF) + check_cxx_compiler_flag(-static HAVE_STATIC_FLAG) + if (HAVE_STATIC_FLAG) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") + endif () # Workaround for cmake link library guesser - SET(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic - SET(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS) - SET(CMAKE_SHARED_LIBRARY_C_FLAGS) # remove -fPIC - SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS) - SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS) # remove -rdynamic - SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) -ELSE (NOT DYNAMIC_LINKING) - IF(MINGW AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # Avoid depending on MinGW runtime DLLs - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") - ENDIF(MINGW AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") -ENDIF (NOT DYNAMIC_LINKING) + set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic + set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS) + set(CMAKE_SHARED_LIBRARY_C_FLAGS) # remove -fPIC + set(CMAKE_SHARED_LIBRARY_CXX_FLAGS) + set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS) # remove -rdynamic + set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) +else () + if (MINGW AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + # Avoid depending on MinGW runtime DLLs + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") + endif () +endif () # System specific actions -IF (${CMAKE_SYSTEM_NAME} MATCHES Linux OR ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD) - IF(NOT DATA_PREFIX) - SET( DATA_PREFIX ${CMAKE_INSTALL_PREFIX}/share/cataclysm-bn) - ENDIF(NOT DATA_PREFIX) - IF(NOT BIN_PREFIX) - SET( BIN_PREFIX ${CMAKE_INSTALL_PREFIX}/bin) - ENDIF(NOT BIN_PREFIX) - IF(NOT DESKTOP_ENTRY_PATH) - SET( DESKTOP_ENTRY_PATH ${CMAKE_INSTALL_PREFIX}/share/applications) - ENDIF(NOT DESKTOP_ENTRY_PATH) - IF(NOT PIXMAPS_ENTRY_PATH) - SET( PIXMAPS_ENTRY_PATH ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor) - ENDIF(NOT PIXMAPS_ENTRY_PATH) - IF(NOT PIXMAPS_UNITY_ENTRY_PATH) - SET( PIXMAPS_UNITY_ENTRY_PATH ${CMAKE_INSTALL_PREFIX}/share/icons/ubuntu-mono-dark) - ENDIF(NOT PIXMAPS_UNITY_ENTRY_PATH) - IF(NOT MANPAGE_ENTRY_PATH) - SET( MANPAGE_ENTRY_PATH ${CMAKE_INSTALL_PREFIX}/share/man) - ENDIF(NOT MANPAGE_ENTRY_PATH) -ENDIF (${CMAKE_SYSTEM_NAME} MATCHES Linux OR ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD) - -IF (${CMAKE_SYSTEM_NAME} MATCHES Windows) - IF(NOT DATA_PREFIX) - SET(DATA_PREFIX ${CMAKE_INSTALL_PREFIX}) - ENDIF(NOT DATA_PREFIX) - IF(NOT BIN_PREFIX) - SET(BIN_PREFIX ${CMAKE_INSTALL_PREFIX}) - ENDIF(NOT BIN_PREFIX) -ENDIF (${CMAKE_SYSTEM_NAME} MATCHES Windows) - - -MESSAGE(STATUS "${PROJECT_NAME} build options --\n") +if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Linux|FreeBSD|Darwin)") + if (NOT DATA_PREFIX) + set(DATA_PREFIX ${CMAKE_INSTALL_PREFIX}/share/cataclysm-bn) + endif () + if (NOT BIN_PREFIX) + set(BIN_PREFIX ${CMAKE_INSTALL_PREFIX}/bin) + endif () + if (NOT DESKTOP_ENTRY_PATH) + set(DESKTOP_ENTRY_PATH ${CMAKE_INSTALL_PREFIX}/share/applications) + endif () + if (NOT PIXMAPS_ENTRY_PATH) + set(PIXMAPS_ENTRY_PATH ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor) + endif () + if (NOT PIXMAPS_UNITY_ENTRY_PATH) + set(PIXMAPS_UNITY_ENTRY_PATH ${CMAKE_INSTALL_PREFIX}/share/icons/ubuntu-mono-dark) + endif () + if (NOT MANPAGE_ENTRY_PATH) + set(MANPAGE_ENTRY_PATH ${CMAKE_INSTALL_PREFIX}/share/man) + endif () +endif () + +if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Windows|MSYS)") + if (NOT DATA_PREFIX) + set(DATA_PREFIX ${CMAKE_INSTALL_PREFIX}) + endif () + if (NOT BIN_PREFIX) + set(BIN_PREFIX ${CMAKE_INSTALL_PREFIX}) + endif () +endif () + +message(STATUS "${PROJECT_NAME} build options --\n") # Preset variables -IF(NOT LANGUAGES) - SET(LANGUAGES all) -ENDIF(NOT LANGUAGES) - -IF (GIT_BINARY) - SET(GIT_EXECUTABLE ${GIT_BINARY}) -ELSE (GIT_BINARY) - FIND_PACKAGE(Git) - IF (NOT GIT_FOUND) - MESSAGE(WARNING "Git binary not found. Build version will be set to NULL. Install Git package or use -DGIT_BINARY to set path to git binary.") - ENDIF (NOT GIT_FOUND) -ENDIF (GIT_BINARY) - -IF (PREFIX) - ADD_DEFINITIONS(-DPREFIX=${PREFIX}) -ENDIF (PREFIX) +if (NOT LANGUAGES) + set(LANGUAGES all) +endif () + +if (GIT_BINARY) + set(GIT_EXECUTABLE ${GIT_BINARY}) +else () + find_package(Git) + if (NOT GIT_FOUND) + message(WARNING "Git binary not found. Build version will be set to NULL. \ + Install Git package or use -DGIT_BINARY to set path to git binary.") + endif () +endif () # Can't compile curses and tiles build's at same time -IF(TILES) - SET(CURSES OFF) -ENDIF(TILES) +if (TILES) + set(CURSES OFF) +endif () # Set build types and display info -IF(CMAKE_BUILD_TYPE STREQUAL Debug) - MESSAGE("\n") - MESSAGE(STATUS "Build ${PROJECT} in development mode --\n") - MESSAGE(STATUS "Binaries will be located in: " ${CMAKE_SOURCE_DIR}) - SET(CMAKE_VERBOSE_MAKEFILE ON) +if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + set(RELEASE 0) + message("\n") + message(STATUS "Build ${PROJECT} in development mode --\n") + message(STATUS "Binaries will be located in: " ${CMAKE_SOURCE_DIR}) + set(CMAKE_VERBOSE_MAKEFILE ON) # Since CataclysmDDA does not respect PREFIX for development builds # and has funny path handlers, we should create resulting Binaries # in the source directory - SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_SOURCE_DIR} - CACHE PATH "Single Directory for all Executables." - ) - SET(BIN_PREFIX ${CMAKE_SOURCE_DIR}) -ELSE (CMAKE_BUILD_TYPE STREQUAL Debug) - MESSAGE(STATUS "CMAKE_INSTALL_PREFIX : ${CMAKE_INSTALL_PREFIX}") - MESSAGE(STATUS "BIN_PREFIX : ${BIN_PREFIX}") - MESSAGE(STATUS "DATA_PREFIX : ${DATA_PREFIX}") - MESSAGE(STATUS "DESKTOP_ENTRY_PATH : ${DESKTOP_ENTRY_PATH}") - MESSAGE(STATUS "PIXMAPS_ENTRY_PATH : ${PIXMAPS_ENTRY_PATH}") - MESSAGE(STATUS "PIXMAPS_UNITY_ENTRY_PATH : ${PIXMAPS_UNITY_ENTRY_PATH}") - MESSAGE(STATUS "MANPAGE_ENTRY_PATH : ${MANPAGE_ENTRY_PATH}\n") - ADD_DEFINITIONS(-DRELEASE) - # Use PREFIX as storage of data,gfx, etc.. Useful only on *nix OS. - IF (PREFIX AND NOT WIN32) - ADD_DEFINITIONS(-DDATA_DIR_PREFIX) - ENDIF (PREFIX AND NOT WIN32) -ENDIF (CMAKE_BUILD_TYPE STREQUAL Debug) - -MESSAGE(STATUS "GIT_BINARY : ${GIT_EXECUTABLE}") -MESSAGE(STATUS "DYNAMIC_LINKING : ${DYNAMIC_LINKING}") - -MESSAGE(STATUS "TILES : ${TILES}") -MESSAGE(STATUS "CURSES : ${CURSES}") -MESSAGE(STATUS "SOUND : ${SOUND}") -MESSAGE(STATUS "LUA : ${LUA}") -MESSAGE(STATUS "BACKTRACE : ${BACKTRACE}") -MESSAGE(STATUS "LIBBACKTRACE : ${LIBBACKTRACE}") -MESSAGE(STATUS "USE_HOME_DIR : ${USE_HOME_DIR}\n") - -MESSAGE(STATUS "UNITY_BUILD : ${USE_UNITY_BUILD}") -MESSAGE(STATUS "PCH_HEADER : ${USE_PCH_HEADER}") -MESSAGE(STATUS "LANGUAGES : ${LANGUAGES}\n") - -IF(LINKER) - MESSAGE(STATUS "LINKER : ${LINKER}\n") -ENDIF() - -MESSAGE(STATUS "See INSTALL file for details and more info --\n") - -IF(MSVC) - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - add_definitions(-D_AMD64_) - else() - add_definitions(-D_X86_) - endif() -ELSE() - SET(CATA_WARNINGS + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY + ${CMAKE_SOURCE_DIR} + CACHE PATH "Single Directory for all Executables.") + set(BIN_PREFIX ${CMAKE_SOURCE_DIR}) +else () + set(RELEASE 1) + message(STATUS "CMAKE_INSTALL_PREFIX : ${CMAKE_INSTALL_PREFIX}") + message(STATUS "BIN_PREFIX : ${BIN_PREFIX}") + message(STATUS "DATA_PREFIX : ${DATA_PREFIX}") + message(STATUS "DESKTOP_ENTRY_PATH : ${DESKTOP_ENTRY_PATH}") + message(STATUS "PIXMAPS_ENTRY_PATH : ${PIXMAPS_ENTRY_PATH}") + message(STATUS "PIXMAPS_UNITY_ENTRY_PATH : ${PIXMAPS_UNITY_ENTRY_PATH}") + message(STATUS "MANPAGE_ENTRY_PATH : ${MANPAGE_ENTRY_PATH}\n") + add_definitions(-DRELEASE) + # Use CMAKE_INSTALL_PREFIX as storage of data,gfx, etc.. Useful only on *nix OS. + if (CMAKE_INSTALL_PREFIX + AND NOT WIN32 + AND USE_PREFIX_DATA_DIR) + add_definitions(-DPREFIX=${CMAKE_INSTALL_PREFIX}) + add_definitions(-DDATA_DIR_PREFIX) + endif () +endif () + +message(STATUS "GIT_BINARY : ${GIT_EXECUTABLE}") +message(STATUS "DYNAMIC_LINKING : ${DYNAMIC_LINKING}") + +message(STATUS "TILES : ${TILES}") +message(STATUS "CURSES : ${CURSES}") +message(STATUS "SOUND : ${SOUND}") +message(STATUS "LUA : ${LUA}") +message(STATUS "BACKTRACE : ${BACKTRACE}") +message(STATUS "LIBBACKTRACE : ${LIBBACKTRACE}") +message(STATUS "USE_HOME_DIR : ${USE_HOME_DIR}\n") + +message(STATUS "UNITY_BUILD : ${USE_UNITY_BUILD}") +message(STATUS "PCH_HEADER : ${USE_PCH_HEADER}") +message(STATUS "LANGUAGES : ${LANGUAGES}\n") + +if (LINKER) + message(STATUS "LINKER : ${LINKER}\n") +endif () + +message(STATUS "See CMake compiling guide for details and more info --\n") + +if (MSVC) + if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + add_definitions(-D_AMD64_) + else () + add_definitions(-D_X86_) + endif () +else () + set(CATA_WARNINGS "-Werror -Wall -Wextra \ -Wformat-signedness \ -Wlogical-op \ @@ -245,148 +262,158 @@ ELSE() -Wzero-as-null-pointer-constant \ -Wno-unknown-warning-option \ -Wno-range-loop-analysis") - IF (NOT ${CMAKE_SYSTEM_NAME} MATCHES Windows) - SET(CATA_WARNINGS "${CATA_WARNINGS} -Wredundant-decls") - ENDIF() - SET(CATA_OTHER_FLAGS "${CATA_OTHER_FLAGS} -fsigned-char") + if (NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Windows") + set(CATA_WARNINGS "${CATA_WARNINGS} -Wredundant-decls") + endif () + set(CATA_OTHER_FLAGS "${CATA_OTHER_FLAGS} -fsigned-char") # Compact the whitespace in the warning string string(REGEX REPLACE "[\t ]+" " " CATA_WARNINGS "${CATA_WARNINGS}") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CATA_WARNINGS} ${CATA_OTHER_FLAGS}") - SET(CMAKE_CXX_FLAGS_DEBUG "-Og -g") -ENDIF() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CATA_WARNINGS} ${CATA_OTHER_FLAGS}") + set(CMAKE_CXX_FLAGS_DEBUG "-Og -g") +endif () -SET(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 17) # Force out-of-source build -IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) - MESSAGE(FATAL_ERROR - "This project requires an out of source build. Remove the file 'CMakeCache.txt' found in this directory before continuing, create a separate build - directory and run 'cmake [options] ' from there.\nSee INSTALL file for details and more info\n" - ) -ENDIF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) +if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") + message( + FATAL_ERROR + "This project requires an out of source build. \ + Remove the file 'CMakeCache.txt' found in this directory before continuing, \ + create a separate build directory and run 'cmake [options] ' from there. \ + See CMake compiling guide for details and more info.") +endif () #SET(THREADS_USE_PTHREADS_WIN32 True) -SET(CMAKE_THREAD_PREFER_PTHREAD True) -FIND_PACKAGE(Threads REQUIRED) +set(CMAKE_THREAD_PREFER_PTHREAD True) +find_package(Threads REQUIRED) # Check for build types and libraries -IF(TILES) +if (TILES) # Find SDL, SDL_ttf & SDL_image for graphical install - MESSAGE(STATUS "Searching for SDL2 library --") - FIND_PACKAGE(SDL2) - IF(NOT SDL2_FOUND) - MESSAGE(FATAL_ERROR - "This project requires SDL2 to be installed to be compiled in graphical mode. Please install the SDL2 development libraries, or try compiling - without the -DTILES=1 for a text only compilation.\nSee INSTALL file for details and more info\n" - ) - ENDIF(NOT SDL2_FOUND) - - IF (NOT DYNAMIC_LINKING) - # SDL, SDL_Image, SDL_ttf deps are required for static build - MESSAGE(STATUS "Searching for SDL deps libraries --") - FIND_PACKAGE(Freetype REQUIRED) - FIND_PACKAGE(PNG REQUIRED) - FIND_PACKAGE(JPEG REQUIRED) - FIND_PACKAGE(ZLIB REQUIRED) - FIND_PACKAGE(BZip2 REQUIRED) - ENDIF (NOT DYNAMIC_LINKING) - - MESSAGE(STATUS "Searching for SDL2_TTF library --") - FIND_PACKAGE(SDL2_ttf) - IF(NOT SDL2_TTF_FOUND) - MESSAGE(FATAL_ERROR - "This project requires SDL2_ttf to be installed to be compiled in graphical mode. Please install the SDL2_ttf development libraries, or try - compiling without the -DTILES=1 for a text only compilation.\nSee INSTALL file for details and moreinfo\n" - ) - ENDIF(NOT SDL2_TTF_FOUND) - - MESSAGE(STATUS "Searching for SDL2_image library --\n") - FIND_PACKAGE(SDL2_image) - IF(NOT SDL2_IMAGE_FOUND) - MESSAGE(FATAL_ERROR - "This project requires SDL2_image to be installed to be compiled in graphical mode. Please install the SDL2_image development libraries, or try - compiling without the -DTILES=1 for a text only compilation.\nSee INSTALL file for details and more info\n" - ) - ENDIF(NOT SDL2_IMAGE_FOUND) - ADD_DEFINITIONS(-DTILES) -ENDIF(TILES) - -IF(CURSES) + message(STATUS "Searching for SDL2 library --") + find_package(SDL2) + if (NOT SDL2_FOUND) + message( + FATAL_ERROR + "This project requires SDL2 to be installed to be compiled in graphical mode. \ + Please install the SDL2 development libraries, or try compiling \ + without the -DTILES=1 for a text only compilation. \ + See CMake compiling guide for details and more info.") + endif () + + if (NOT DYNAMIC_LINKING) + # SDL, SDL_Image, SDL_ttf deps are required for static build + message(STATUS "Searching for SDL deps libraries --") + find_package(Freetype REQUIRED) + find_package(PNG REQUIRED) + find_package(JPEG REQUIRED) + find_package(ZLIB REQUIRED) + find_package(BZip2 REQUIRED) + endif () + + message(STATUS "Searching for SDL2_TTF library --") + find_package(SDL2_ttf) + if (NOT SDL2_TTF_FOUND) + message( + FATAL_ERROR + "This project requires SDL2_ttf to be installed to be compiled in graphical mode. \ + Please install the SDL2_ttf development libraries, or try compiling \ + without the -DTILES=1 for a text only compilation. \ + See CMake compiling guide for details and more info.") + endif () + + message(STATUS "Searching for SDL2_image library --\n") + find_package(SDL2_image) + if (NOT SDL2_IMAGE_FOUND) + message( + FATAL_ERROR + "This project requires SDL2_image to be installed to be compiled in graphical mode. \ + Please install the SDL2_image development libraries, or try compiling \ + without the -DTILES=1 for a text only compilation. \ + See CMake compiling guide for details and more info.") + endif () + add_definitions(-DTILES) +endif () + +if (CURSES) # Find the ncurses library for a text based compile - MESSAGE(STATUS "Searching for Curses library --\n") - SET(CURSES_NEED_NCURSES TRUE) - SET(CURSES_NEED_WIDE TRUE) - FIND_PACKAGE(Curses) - IF(NOT CURSES_FOUND) - MESSAGE(FATAL_ERROR - "This project requires ncurses to be installed to be compiled in text only mode. Please install the ncurses development libraries, or try compiling - with the -DTILES=1 for a graphical compilation.\nSee INSTALL file for details and more info\n" - ) - ENDIF(NOT CURSES_FOUND) -ENDIF(CURSES) - -IF(SOUND) + message(STATUS "Searching for Curses library --\n") + set(CURSES_NEED_NCURSES TRUE) + set(CURSES_NEED_WIDE TRUE) + find_package(Curses) + if (NOT CURSES_FOUND) + message( + FATAL_ERROR + "This project requires ncurses to be installed to be compiled in text only mode. \ + Please install the ncurses development libraries, or try compiling \ + with the -DTILES=1 for a graphical compilation. \ + See CMake compiling guide for details and more info.") + endif () + if (NOT DYNAMIC_LINKING) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNCURSES_STATIC") + endif () +endif () + +if (SOUND) # You need TILES to be able to use SOUND - IF(NOT TILES) - MESSAGE(FATAL_ERROR - "You must enable graphical support with -DTILES=1 to be able to enable sound support.\nSee INSTALL file for details and more info\n" - ) - ENDIF(NOT TILES) + if (NOT TILES) + message( + FATAL_ERROR + "You must enable graphical support with -DTILES=1 to be able to enable sound support. \ + See CMake compiling guide for details and more info.") + endif () # Sound requires SDL_mixer library - MESSAGE(STATUS "Searching for SDL2_mixer library --\n") - FIND_PACKAGE(SDL2_mixer) - IF(NOT SDL2_MIXER_FOUND) - MESSAGE(FATAL_ERROR - "You need the SDL2_mixer development library to be able to compile with sound enabled.\nSee INSTALL file for details and more info\n" - ) - ENDIF(NOT SDL2_MIXER_FOUND) -ENDIF(SOUND) - -IF(BACKTRACE) - ADD_DEFINITIONS(-DBACKTRACE) - IF(LIBBACKTRACE) - ADD_DEFINITIONS(-DLIBBACKTRACE) - ENDIF(LIBBACKTRACE) -ENDIF(BACKTRACE) + message(STATUS "Searching for SDL2_mixer library --\n") + find_package(SDL2_mixer) + if (NOT SDL2_MIXER_FOUND) + message( + FATAL_ERROR + "You need the SDL2_mixer development library to be able to compile with sound enabled. \ + See CMake compiling guide for details and more info.") + endif () +endif () + +if (BACKTRACE) + add_definitions(-DBACKTRACE) + if (LIBBACKTRACE) + add_definitions(-DLIBBACKTRACE) + endif () +endif () # Ok. Now create build and install recipes -IF(USE_HOME_DIR) - ADD_DEFINITIONS(-DUSE_HOME_DIR) -ENDIF(USE_HOME_DIR) +if (USE_HOME_DIR) + add_definitions(-DUSE_HOME_DIR) +endif () add_subdirectory(src) add_subdirectory(data) add_subdirectory(lang) if (NOT MSVC) add_subdirectory(src/chkjson) -endif() +endif () add_subdirectory(tests) if (JSON_FORMAT) add_subdirectory(tools/format) -endif() +endif () if (CATA_CLANG_TIDY_PLUGIN) add_subdirectory(tools/clang-tidy-plugin) -endif() +endif () -CONFIGURE_FILE( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" - IMMEDIATE @ONLY -) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) -ADD_CUSTOM_TARGET(uninstall - "${CMAKE_COMMAND}" - -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" -) +add_custom_target(uninstall "${CMAKE_COMMAND}" -P + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") find_program(CCACHE_FOUND ccache) -if(CCACHE_FOUND AND CATA_CCACHE) +if (CCACHE_FOUND AND CATA_CCACHE) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) -endif() +endif () -if(USE_UNITY_BUILD) +if (USE_UNITY_BUILD) set_property(GLOBAL PROPERTY UNITY_BUILD ON) -endif() +endif () # vim:noet diff --git a/Makefile b/Makefile index fa1832d22cf9..4a1bf0ec72bb 100644 --- a/Makefile +++ b/Makefile @@ -1211,6 +1211,25 @@ check: version $(BUILD_PREFIX)cataclysm.a clean-tests: $(MAKE) -C tests clean +cmake-format: + cmake-format -i \ + ./CMakeLists.txt \ + ./.github/vcpkg_triplets/x64-windows-static.cmake \ + ./.github/vcpkg_triplets/x64-windows.cmake \ + ./.github/vcpkg_triplets/x86-windows-static.cmake \ + ./.github/vcpkg_triplets/x86-windows.cmake \ + ./cmake_uninstall.cmake.in \ + ./CMakeLists.txt \ + ./data/CMakeLists.txt \ + ./lang/CMakeLists.txt \ + ./src/chkjson/CMakeLists.txt \ + ./src/CMakeLists.txt \ + ./src/version.cmake \ + ./tests/CMakeLists.txt \ + ./tools/clang-tidy-plugin/CMakeLists.txt \ + ./tools/format/CMakeLists.txt \ + -c .cmake-format.yml + .PHONY: tests check ctags etags clean-tests install lint -include $(SOURCES:$(SRC_DIR)/%.cpp=$(DEPDIR)/%.P) diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in index 1763f951fa74..7c6321fdfdb0 100644 --- a/cmake_uninstall.cmake.in +++ b/cmake_uninstall.cmake.in @@ -1,22 +1,25 @@ -IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") - MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") -ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") +if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + message( + FATAL_ERROR + "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") +endif () -FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) -STRING(REGEX REPLACE "\n" ";" files "${files}") -FOREACH(file ${files}) - MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") - IF(EXISTS "$ENV{DESTDIR}${file}") - EXEC_PROGRAM( - "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" - OUTPUT_VARIABLE rm_out - RETURN_VALUE rm_retval - ) - IF("${rm_retval}" STREQUAL 0) - ELSE("${rm_retval}" STREQUAL 0) - MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") - ENDIF("${rm_retval}" STREQUAL 0) - ELSE(EXISTS "$ENV{DESTDIR}${file}") - MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") - ENDIF(EXISTS "$ENV{DESTDIR}${file}") -ENDFOREACH(file) +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach (file ${files}) + message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") + if (EXISTS "$ENV{DESTDIR}${file}") + exec_program( + "@CMAKE_COMMAND@" ARGS + "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval) + if ("${rm_retval}" STREQUAL 0) + + else () + message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") + endif () + else () + message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") + endif () +endforeach (file) diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index bf98bbdd166e..6d3c79e04730 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -1,7 +1,7 @@ # Cataclysm data files cmake_minimum_required(VERSION 3.16) -SET(CATACLYSM_DATA_DIRS +set(CATACLYSM_DATA_DIRS ${CMAKE_SOURCE_DIR}/data/font ${CMAKE_SOURCE_DIR}/data/json ${CMAKE_SOURCE_DIR}/data/mods @@ -10,29 +10,20 @@ SET(CATACLYSM_DATA_DIRS ${CMAKE_SOURCE_DIR}/data/motd ${CMAKE_SOURCE_DIR}/data/credits ${CMAKE_SOURCE_DIR}/data/title -) + ${CMAKE_SOURCE_DIR}/data/help) -IF(SOUND) - SET(CATACLYSM_DATA_DIRS - ${CATACLYSM_DATA_DIRS} - ${CMAKE_SOURCE_DIR}/data/sound - ) -ENDIF(SOUND) +if (SOUND) + set(CATACLYSM_DATA_DIRS ${CATACLYSM_DATA_DIRS} ${CMAKE_SOURCE_DIR}/data/sound) +endif () -IF(TILES) - SET(CATACLYSM_DATA_DIRS - ${CATACLYSM_DATA_DIRS} - ${CMAKE_SOURCE_DIR}/gfx - ) -ENDIF(TILES) +if (TILES) + set(CATACLYSM_DATA_DIRS ${CATACLYSM_DATA_DIRS} ${CMAKE_SOURCE_DIR}/gfx) +endif () -SET(CATACLYSM_DATA_FILES - ${CMAKE_SOURCE_DIR}/data/changelog.txt - ${CMAKE_SOURCE_DIR}/data/cataicon.ico - ${CMAKE_SOURCE_DIR}/LICENSE.txt -) +set(CATACLYSM_DATA_FILES ${CMAKE_SOURCE_DIR}/data/changelog.txt + ${CMAKE_SOURCE_DIR}/data/cataicon.ico ${CMAKE_SOURCE_DIR}/LICENSE.txt) -IF(RELEASE) +if (RELEASE) install(DIRECTORY ${CATACLYSM_DATA_DIRS} DESTINATION ${DATA_PREFIX}) install(FILES ${CATACLYSM_DATA_FILES} DESTINATION ${DATA_PREFIX}) -ENDIF(RELEASE) +endif () diff --git a/doc/src/content/docs/en/dev/guides/building/cmake.md b/doc/src/content/docs/en/dev/guides/building/cmake.md index 393808f0cde0..5907f9519a6a 100644 --- a/doc/src/content/docs/en/dev/guides/building/cmake.md +++ b/doc/src/content/docs/en/dev/guides/building/cmake.md @@ -358,6 +358,10 @@ much faster. Override default Git binary name or path. +- USE_PREFIX_DATA_DIR=`` + +Use UNIX system directories for game data in release build. + So a CMake command for building Cataclysm-BN in release mode with tiles and sound support will look as follows, provided it is run in build directory located in the project. diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt index 8db7546cd33a..ef5cf2c0ceff 100644 --- a/lang/CMakeLists.txt +++ b/lang/CMakeLists.txt @@ -1,80 +1,63 @@ -MESSAGE(STATUS "Process LANGUAGES variable --\n") +message(STATUS "Process LANGUAGES variable --\n") -IF (LANGUAGES STREQUAL none) - MESSAGE(STATUS "Not compiling any languages.\n") +if (LANGUAGES STREQUAL none) + message(STATUS "Not compiling any languages.\n") return() -ENDIF() +endif () -FIND_PACKAGE(Gettext) +find_package(Gettext) -IF (NOT GETTEXT_FOUND) - MESSAGE(FATAL_ERROR - "Gettext not found. Install gettext package or disable - compilation of language files with: -DLANGUAGES=none \nSee INSTALL file for details and more info\n" - ) -ENDIF (NOT GETTEXT_FOUND) +if (NOT GETTEXT_FOUND) + message( + FATAL_ERROR + "Gettext not found. Install gettext package or disable \ + compilation of language files with: -DLANGUAGES=none. \ + See CMake compiling guide for details and more info.") +endif () -IF (LANGUAGES STREQUAL all) +if (LANGUAGES STREQUAL all) set(LANGUAGES "") - file (GLOB PO_FILES - ${CMAKE_SOURCE_DIR}/lang/po/*.po - ) + file(GLOB PO_FILES ${CMAKE_SOURCE_DIR}/lang/po/*.po) foreach (PO_FILE ${PO_FILES}) - get_filename_component(LANG ${PO_FILE} NAME_WE) - list(APPEND LANGUAGES ${LANG}) + get_filename_component(LANG ${PO_FILE} NAME_WE) + list(APPEND LANGUAGES ${LANG}) endforeach () list(REMOVE_DUPLICATES LANGUAGES) # End of special case -ENDIF() +endif () foreach (LANG ${LANGUAGES}) - MESSAGE(STATUS "Add translation for ${LANG}: ${LANG}.po") + message(STATUS "Add translation for ${LANG}: ${LANG}.po") endforeach () -MESSAGE("\n") +message("\n") -add_custom_target ( - translations_prepare - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) +add_custom_target(translations_prepare WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) # Auto-Compile translation on release builds only -IF (RELEASE) - add_custom_target ( - translations_compile - ALL - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - DEPENDS translations_prepare - ) -ELSE (RELEASE) - add_custom_target ( - translations_compile - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - DEPENDS translations_prepare - ) -ENDIF (RELEASE) +if (RELEASE) + add_custom_target( + translations_compile ALL + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + DEPENDS translations_prepare) +else () + add_custom_target( + translations_compile + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + DEPENDS translations_prepare) +endif () foreach (LANG ${LANGUAGES}) - add_custom_command ( - TARGET translations_prepare - PRE_BUILD - COMMAND ${CMAKE_COMMAND} - -E make_directory ${CMAKE_SOURCE_DIR}/lang/mo/${LANG}/LC_MESSAGES - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - ) - add_custom_command ( - TARGET translations_compile - PRE_BUILD - COMMAND - ${GETTEXT_MSGFMT_EXECUTABLE} -f ${CMAKE_SOURCE_DIR}/lang/po/${LANG}.po - -o ${CMAKE_SOURCE_DIR}/lang/mo/${LANG}/LC_MESSAGES/cataclysm-bn.mo - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - ) - IF(RELEASE) - IF (${CMAKE_SYSTEM_NAME} MATCHES Windows) - #install(DIRECTORY ${CMAKE_SOURCE_DIR}/lang/mo/${LANG} DESTINATION ${DATA_PREFIX}) - ELSE (${CMAKE_SYSTEM_NAME} MATCHES Windows) - install(DIRECTORY ${CMAKE_SOURCE_DIR}/lang/mo/${LANG} DESTINATION ${LOCALE_DIR}) - ENDIF (${CMAKE_SYSTEM_NAME} MATCHES Windows) - ENDIF(RELEASE) -endforeach() - + add_custom_command( + TARGET translations_prepare + PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/lang/mo/${LANG}/LC_MESSAGES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + add_custom_command( + TARGET translations_compile + PRE_BUILD + COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -f ${CMAKE_SOURCE_DIR}/lang/po/${LANG}.po -o + ${CMAKE_SOURCE_DIR}/lang/mo/${LANG}/LC_MESSAGES/cataclysm-bn.mo + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + # FIXME: check if this works + install(DIRECTORY ${CMAKE_SOURCE_DIR}/lang/mo/${LANG} DESTINATION ${DATA_PREFIX}) +endforeach () diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0bc909d7624c..df0baa3901bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,121 +1,90 @@ # Cataclysm BN client cmake_minimum_required(VERSION 3.16) -SET(MAIN_CPP ${CMAKE_SOURCE_DIR}/src/main.cpp) -SET(MESSAGES_CPP ${CMAKE_SOURCE_DIR}/src/messages.cpp) -SET(RESOURCE_RC ${CMAKE_SOURCE_DIR}/src/resource.rc) +set(MAIN_CPP ${CMAKE_SOURCE_DIR}/src/main.cpp) +set(MESSAGES_CPP ${CMAKE_SOURCE_DIR}/src/messages.cpp) +set(RESOURCE_RC ${CMAKE_SOURCE_DIR}/src/resource.rc) -FILE(GLOB CATACLYSM_BN_SOURCES - ${CMAKE_SOURCE_DIR}/src/*.cpp -) +file(GLOB CATACLYSM_BN_SOURCES ${CMAKE_SOURCE_DIR}/src/*.cpp) -LIST(REMOVE_ITEM CATACLYSM_BN_SOURCES ${MAIN_CPP} ${MESSAGES_CPP}) +list(REMOVE_ITEM CATACLYSM_BN_SOURCES ${MAIN_CPP} ${MESSAGES_CPP}) -FILE(GLOB CATACLYSM_BN_HEADERS - ${CMAKE_SOURCE_DIR}/src/*.h -) +file(GLOB CATACLYSM_BN_HEADERS ${CMAKE_SOURCE_DIR}/src/*.h) -IF(LUA) - FILE(GLOB LUA_C_SOURCES - ${CMAKE_SOURCE_DIR}/src/lua/*.c - ) -ELSE(LUA) - SET(LUA_C_SOURCES "") -ENDIF(LUA) +if (LUA) + file(GLOB LUA_C_SOURCES ${CMAKE_SOURCE_DIR}/src/lua/*.c) +else () + set(LUA_C_SOURCES "") +endif () # Get GIT version strings -ADD_CUSTOM_TARGET( +add_custom_target( get_version DEPENDS ${CMAKE_SOURCE_DIR}/src/version.h - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) -ADD_CUSTOM_COMMAND( +add_custom_command( OUTPUT ${CMAKE_SOURCE_DIR}/src/version.h - COMMAND ${CMAKE_COMMAND} - -D SRC=${CMAKE_SOURCE_DIR}/src/version.h.in - -D DST=${CMAKE_SOURCE_DIR}/src/version.h - -D GIT_EXECUTABLE=${GIT_EXECUTABLE} - -P ${CMAKE_SOURCE_DIR}/src/version.cmake - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) + COMMAND + ${CMAKE_COMMAND} -D SRC=${CMAKE_SOURCE_DIR}/src/version.h.in -D + DST=${CMAKE_SOURCE_DIR}/src/version.h -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -P + ${CMAKE_SOURCE_DIR}/src/version.cmake + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) # Build tiles version if requested -IF(TILES) - add_library(cataclysm-tiles-common OBJECT - ${CATACLYSM_BN_SOURCES} - ${CATACLYSM_BN_HEADERS} - ${LUA_C_SOURCES} - ) +if (TILES) + add_library(cataclysm-tiles-common OBJECT ${CATACLYSM_BN_SOURCES} ${CATACLYSM_BN_HEADERS} + ${LUA_C_SOURCES}) target_include_directories(cataclysm-tiles-common INTERFACE ${CMAKE_SOURCE_DIR}/src) - IF(USE_PCH_HEADER) - target_precompile_headers(cataclysm-tiles-common PRIVATE ${CMAKE_SOURCE_DIR}/pch/main-pch.hpp) - ENDIF() - - IF(WIN32) - ADD_DEFINITIONS(-DUSE_WINMAIN) - ADD_EXECUTABLE(cataclysm-tiles WIN32 - ${MAIN_CPP} - ${MESSAGES_CPP} - ${RESOURCE_RC} - ) - ELSE(WIN32) - ADD_EXECUTABLE(cataclysm-tiles - ${MAIN_CPP} - ${MESSAGES_CPP} - ) - ENDIF(WIN32) - - IF(LUA) + if (USE_PCH_HEADER) + target_precompile_headers(cataclysm-tiles-common PRIVATE + ${CMAKE_SOURCE_DIR}/pch/main-pch.hpp) + endif () + + if (WIN32) + add_definitions(-DUSE_WINMAIN) + add_executable(cataclysm-tiles WIN32 ${MAIN_CPP} ${MESSAGES_CPP} ${RESOURCE_RC}) + else () + add_executable(cataclysm-tiles ${MAIN_CPP} ${MESSAGES_CPP}) + endif () + + if (LUA) target_compile_definitions(cataclysm-tiles-common PUBLIC LUA) target_include_directories(cataclysm-tiles-common PUBLIC ${CMAKE_SOURCE_DIR}/src) target_include_directories(cataclysm-tiles-common PUBLIC ${CMAKE_SOURCE_DIR}/src/lua) - ENDIF(LUA) + endif () - ADD_DEPENDENCIES(cataclysm-tiles-common get_version) + add_dependencies(cataclysm-tiles-common get_version) target_link_libraries(cataclysm-tiles cataclysm-tiles-common) target_compile_definitions(cataclysm-tiles-common PUBLIC TILES) - IF(CMAKE_USE_PTHREADS_INIT) + if (CMAKE_USE_PTHREADS_INIT) target_compile_options(cataclysm-tiles-common PUBLIC "-pthread") - ENDIF(CMAKE_USE_PTHREADS_INIT) + endif () - IF(CMAKE_THREAD_LIBS_INIT) + if (CMAKE_THREAD_LIBS_INIT) target_link_libraries(cataclysm-tiles-common ${CMAKE_THREAD_LIBS_INIT}) - ENDIF(CMAKE_THREAD_LIBS_INIT) + endif () - IF(NOT DYNAMIC_LINKING) + if (NOT DYNAMIC_LINKING) # SDL, SDL_Image, SDL_ttf deps are required for static build - target_include_directories(cataclysm-tiles-common PUBLIC - ${FREETYPE_INCLUDE_DIRS} - ${PNG_INCLUDE_DIRS} - ${JPEG_INCLUDE_DIR} - ${ZLIB_INCLUDE_DIRS} - ${BZIP2_INCLUDE_DIR} - ) - target_link_libraries(cataclysm-tiles-common - ${FREETYPE_LIBRARIES} - ${PNG_LIBRARIES} - ${JPEG_LIBRARIES} - ${ZLIB_LIBRARIES} - ${BZIP2_LIBRARIES} - ) - ENDIF(NOT DYNAMIC_LINKING) - - target_include_directories(cataclysm-tiles-common PUBLIC - ${SDL2_INCLUDE_DIR} - ${SDL2_IMAGE_INCLUDE_DIRS} - ${SDL2_TTF_INCLUDE_DIRS} - ) - target_link_libraries(cataclysm-tiles-common - ${SDL2_LIBRARY} - ${SDL2_IMAGE_LIBRARIES} - ${SDL2_TTF_LIBRARIES} - ) - - IF(SOUND) + target_include_directories( + cataclysm-tiles-common + PUBLIC ${FREETYPE_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} ${JPEG_INCLUDE_DIR} + ${ZLIB_INCLUDE_DIRS} ${BZIP2_INCLUDE_DIR}) + target_link_libraries(cataclysm-tiles-common ${FREETYPE_LIBRARIES} ${PNG_LIBRARIES} + ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BZIP2_LIBRARIES}) + endif () + + target_include_directories( + cataclysm-tiles-common PUBLIC ${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIRS} + ${SDL2_TTF_INCLUDE_DIRS}) + target_link_libraries(cataclysm-tiles-common ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARIES} + ${SDL2_TTF_LIBRARIES}) + + if (SOUND) target_compile_definitions(cataclysm-tiles-common PUBLIC SDL_SOUND) target_include_directories(cataclysm-tiles-common PUBLIC ${OGGVORBIS_INCLUDE_DIR}) target_link_libraries(cataclysm-tiles-common ${OGG_LIBRARY}) @@ -123,9 +92,9 @@ IF(TILES) target_link_libraries(cataclysm-tiles-common ${VORBISFILE_LIBRARY}) target_include_directories(cataclysm-tiles-common PUBLIC ${SDL2_MIXER_INCLUDE_DIRS}) target_link_libraries(cataclysm-tiles-common ${SDL2_MIXER_LIBRARIES}) - ENDIF(SOUND) + endif () - IF(WIN32) + if (WIN32) # Global settings for Windows targets (at end) target_link_libraries(cataclysm-tiles-common gdi32.lib) target_link_libraries(cataclysm-tiles-common winmm.lib) @@ -134,67 +103,57 @@ IF(TILES) target_link_libraries(cataclysm-tiles-common oleaut32.lib) target_link_libraries(cataclysm-tiles-common version.lib) - IF(BACKTRACE) + if (BACKTRACE) target_link_libraries(cataclysm-tiles-common dbghelp.lib) - ENDIF(BACKTRACE) - ENDIF(WIN32) + endif () + endif () - IF(LIBBACKTRACE) + if (LIBBACKTRACE) target_link_libraries(cataclysm-tiles-common backtrace) - ENDIF(LIBBACKTRACE) + endif () - IF(RELEASE) + if (RELEASE) install(TARGETS cataclysm-tiles DESTINATION ${BIN_PREFIX}) - ENDIF(RELEASE) -ENDIF(TILES) + endif () +endif () # Build curses version if requested -IF(CURSES) - add_library(cataclysm-common OBJECT - ${CATACLYSM_BN_SOURCES} - ${CATACLYSM_BN_HEADERS} - ${LUA_C_SOURCES} - ) +if (CURSES) + add_library(cataclysm-common OBJECT ${CATACLYSM_BN_SOURCES} ${CATACLYSM_BN_HEADERS} + ${LUA_C_SOURCES}) target_include_directories(cataclysm-common INTERFACE ${CMAKE_SOURCE_DIR}/src) - IF(USE_PCH_HEADER) + if (USE_PCH_HEADER) target_precompile_headers(cataclysm-common PRIVATE ${CMAKE_SOURCE_DIR}/pch/main-pch.hpp) - ENDIF() - - IF(WIN32) - ADD_EXECUTABLE(cataclysm - ${MAIN_CPP} - ${MESSAGES_CPP} - ${RESOURCE_RC} - ) - ELSE(WIN32) - ADD_EXECUTABLE(cataclysm - ${MAIN_CPP} - ${MESSAGES_CPP} - ) - ENDIF(WIN32) - - IF(LUA) + endif () + + if (WIN32) + add_executable(cataclysm ${MAIN_CPP} ${MESSAGES_CPP} ${RESOURCE_RC}) + else () + add_executable(cataclysm ${MAIN_CPP} ${MESSAGES_CPP}) + endif () + + if (LUA) target_compile_definitions(cataclysm-common PUBLIC LUA) target_include_directories(cataclysm-common PUBLIC ${CMAKE_SOURCE_DIR}/src) target_include_directories(cataclysm-common PUBLIC ${CMAKE_SOURCE_DIR}/src/lua) - ENDIF(LUA) + endif () - ADD_DEPENDENCIES(cataclysm-common get_version) + add_dependencies(cataclysm-common get_version) target_link_libraries(cataclysm cataclysm-common) target_include_directories(cataclysm-common PUBLIC ${CURSES_INCLUDE_DIR}) target_link_libraries(cataclysm-common ${CURSES_LIBRARIES}) - IF(CMAKE_USE_PTHREADS_INIT) + if (CMAKE_USE_PTHREADS_INIT) target_compile_options(cataclysm-common PUBLIC "-pthread") - ENDIF(CMAKE_USE_PTHREADS_INIT) + endif () - IF(CMAKE_THREAD_LIBS_INIT) + if (CMAKE_THREAD_LIBS_INIT) target_link_libraries(cataclysm-common ${CMAKE_THREAD_LIBS_INIT}) - ENDIF(CMAKE_THREAD_LIBS_INIT) + endif () - IF(WIN32) + if (WIN32) # Global settings for Windows targets (at end) target_link_libraries(cataclysm-common gdi32.lib) target_link_libraries(cataclysm-common winmm.lib) @@ -203,21 +162,21 @@ IF(CURSES) target_link_libraries(cataclysm-common oleaut32.lib) target_link_libraries(cataclysm-common version.lib) - IF(BACKTRACE) + if (BACKTRACE) target_link_libraries(cataclysm-common dbghelp.lib) - ENDIF(BACKTRACE) - ENDIF(WIN32) + endif () + endif () - IF(LIBBACKTRACE) + if (LIBBACKTRACE) target_link_libraries(cataclysm-common backtrace) - ENDIF(LIBBACKTRACE) + endif () - IF(RELEASE) + if (RELEASE) install(TARGETS cataclysm DESTINATION ${BIN_PREFIX}) - ENDIF(RELEASE) -ENDIF(CURSES) + endif () +endif () -IF(MINGW AND NOT RELEASE) +if (MINGW AND NOT RELEASE) # Try to Install shared libraries for dev builds # Note: It is specific to MSYS2 and uses hardcoded versions so # probably it will fail if you run it :) @@ -226,13 +185,10 @@ IF(MINGW AND NOT RELEASE) find_library(RuntimeLib_GCC_S_DW2_1 "gcc_s_dw2-1") find_library(RuntimeLib_STDC_PP_6 "stdc++-6") find_library(RuntimeLib_WINPTHREAD_1 "winpthread-1") - SET(RuntimeLib_GCC_ALL - ${RuntimeLib_GCC_S_DW2_1} - ${RuntimeLib_STDC_PP_6} - ${RuntimeLib_WINPTHREAD_1} - ) + set(RuntimeLib_GCC_ALL ${RuntimeLib_GCC_S_DW2_1} ${RuntimeLib_STDC_PP_6} + ${RuntimeLib_WINPTHREAD_1}) - IF(TILES) + if (TILES) # SDL2 can have a varius deps. Here you are the MSYS2 ones... find_library(RuntimeLib_SDL2 "SDL2") find_library(RuntimeLib_SDL2_IMG "SDL2_image") @@ -248,7 +204,7 @@ IF(MINGW AND NOT RELEASE) find_library(RuntimeLib_SDL2_TTF "SDL2_ttf") find_library(RuntimeLib_ft "libfreetype-6") find_library(RuntimeLib_glib "libglib-2.0-0") - SET(RuntimeLib_SDL + set(RuntimeLib_SDL ${RuntimeLib_SDL2} ${RuntimeLib_SDL2_IMG} ${RuntimeLib_png} @@ -262,10 +218,9 @@ IF(MINGW AND NOT RELEASE) ${RuntimeLib_hb} ${RuntimeLib_SDL2_TTF} ${RuntimeLib_ft} - ${RuntimeLib_glib} - ) + ${RuntimeLib_glib}) - IF(SOUND) + if (SOUND) find_library(RuntimeLib_SDL_SND "SDL2_mixer") find_library(RuntimeLib_flak "libFLAC-8") find_library(RuntimeLib_ogg "libogg-0") @@ -277,7 +232,7 @@ IF(MINGW AND NOT RELEASE) find_library(RuntimeLib_vorb_f "libvorbisfile-3") find_library(RuntimeLib_mod "libmodplug-1") find_library(RuntimeLib_mpeg "smpeg2") - SET(RuntimeLib_SDL_SOUND + set(RuntimeLib_SDL_SOUND ${RuntimeLib_SDL_SND} ${RuntimeLib_flak} ${RuntimeLib_ogg} @@ -288,16 +243,12 @@ IF(MINGW AND NOT RELEASE) ${RuntimeLib_vorb_enc} ${RuntimeLib_vorb_f} ${RuntimeLib_mod} - ${RuntimeLib_mpeg} - ) - ENDIF(SOUND) - ENDIF(TILES) - - install(FILES ${RuntimeLib_GCC_ALL} - ${RuntimeLib_SDL} - ${RuntimeLib_SDL_SOUND} - DESTINATION ${BIN_PREFIX} - ) -ENDIF(MINGW AND NOT RELEASE) + ${RuntimeLib_mpeg}) + endif () + endif () + + install(FILES ${RuntimeLib_GCC_ALL} ${RuntimeLib_SDL} ${RuntimeLib_SDL_SOUND} + DESTINATION ${BIN_PREFIX}) +endif () # vim:noet diff --git a/src/chkjson/CMakeLists.txt b/src/chkjson/CMakeLists.txt index 7a54b93c3e9c..198d403d26b2 100644 --- a/src/chkjson/CMakeLists.txt +++ b/src/chkjson/CMakeLists.txt @@ -1,33 +1,24 @@ # JSON check utility -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.16) -SET (CHKJSON_SOURCES - ${CMAKE_SOURCE_DIR}/src/json.cpp - ${CMAKE_SOURCE_DIR}/src/chkjson/chkjson.cpp -) +set(CHKJSON_SOURCES ${CMAKE_SOURCE_DIR}/src/json.cpp ${CMAKE_SOURCE_DIR}/src/chkjson/chkjson.cpp) -SET (CHKJSON_HEADERS - ${CMAKE_SOURCE_DIR}/src/json.h -) +set(CHKJSON_HEADERS ${CMAKE_SOURCE_DIR}/src/json.h) # test chain -add_custom_target ( - check_json - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) +add_custom_target(check_json WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) -add_custom_command ( - TARGET check_json - PRE_BUILD - COMMAND chkjson - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) +add_custom_command( + TARGET check_json + PRE_BUILD + COMMAND chkjson + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) -INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/chkjson ) +include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/chkjson) # Add the actual executable -IF(WIN32) - ADD_EXECUTABLE(chkjson WIN32 EXCLUDE_FROM_ALL ${CHKJSON_SOURCES} ${CHKJSON_HEADERS}) -ELSE(WIN32) - ADD_EXECUTABLE(chkjson EXCLUDE_FROM_ALL ${CHKJSON_SOURCES} ${CHKJSON_HEADERS}) -ENDIF(WIN32) +if (WIN32) + add_executable(chkjson WIN32 EXCLUDE_FROM_ALL ${CHKJSON_SOURCES} ${CHKJSON_HEADERS}) +else () + add_executable(chkjson EXCLUDE_FROM_ALL ${CHKJSON_SOURCES} ${CHKJSON_HEADERS}) +endif () diff --git a/src/ncurses_def.cpp b/src/ncurses_def.cpp index f39b25b71566..988487a55f00 100644 --- a/src/ncurses_def.cpp +++ b/src/ncurses_def.cpp @@ -7,6 +7,7 @@ // ncurses can define some functions as macros, but we need those identifiers // to be unchanged by the preprocessor, as we use them as function names. #define NCURSES_NOMACROS +#define NCURSES_WIDECHAR 1 #if defined(__CYGWIN__) #include #else diff --git a/src/version.cmake b/src/version.cmake index 0da0e78d8ff0..ec512a5ec986 100644 --- a/src/version.cmake +++ b/src/version.cmake @@ -1,12 +1,13 @@ -IF(GIT_EXECUTABLE) - EXECUTE_PROCESS( - COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty --match "[0-9]*.[0-9]*" - OUTPUT_VARIABLE VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE - ) -ELSE(GIT_EXECUTABLE) - MESSAGE(WARNING "Git binary not found. Build version will be set to NULL. Install Git package or use -DGIT_BINARY to set path to git binary.") - SET (VERSION "NULL") -ENDIF(GIT_EXECUTABLE) +if (GIT_EXECUTABLE) + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty --match "[0-9A-Z]*.[0-9A-Z]*" + OUTPUT_VARIABLE VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) +else () + message(WARNING "Git binary not found. \ + Build version will be set to NULL. \ + Install Git package or use -DGIT_BINARY to set path to git binary.") + set(VERSION "NULL") +endif () -CONFIGURE_FILE(${SRC} ${DST} @ONLY) +configure_file(${SRC} ${DST} @ONLY) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 955d9eb62d46..3ec9fb3ac5b5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,35 +1,32 @@ -IF(BUILD_TESTING) - FILE(GLOB CATACLYSM_BN_TEST_SOURCES - ${CMAKE_SOURCE_DIR}/tests/*.cpp) +if (BUILD_TESTING) + file(GLOB CATACLYSM_BN_TEST_SOURCES ${CMAKE_SOURCE_DIR}/tests/*.cpp) - # Enabling benchmarks - ADD_DEFINITIONS(-DCATCH_CONFIG_ENABLE_BENCHMARKING) + # Enabling benchmarks + add_definitions(-DCATCH_CONFIG_ENABLE_BENCHMARKING) - IF(TILES) - add_executable(cata_test-tiles ${CATACLYSM_BN_TEST_SOURCES}) - IF(LUA) - target_compile_definitions(cata_test-tiles PUBLIC LUA) - ENDIF(LUA) - target_link_libraries(cata_test-tiles cataclysm-tiles-common) - add_test(NAME test-tiles - COMMAND sh -c - "$ --rng-seed `shuf -i 0-1000000000 -n 1`" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - ) - ENDIF(TILES) + if (TILES) + add_executable(cata_test-tiles ${CATACLYSM_BN_TEST_SOURCES}) + if (LUA) + target_compile_definitions(cata_test-tiles PUBLIC LUA) + endif () + target_link_libraries(cata_test-tiles cataclysm-tiles-common) + add_test( + NAME test-tiles + COMMAND sh -c "$ --rng-seed time" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + endif () - IF(CURSES) - add_executable(cata_test ${CATACLYSM_BN_TEST_SOURCES}) - IF(LUA) - target_compile_definitions(cata_test PUBLIC LUA) - ENDIF(LUA) - target_link_libraries(cata_test cataclysm-common) - add_test(NAME test - COMMAND sh -c - "$ --rng-seed `shuf -i 0-1000000000 -n 1`" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - ) - ENDIF(CURSES) -ENDIF(BUILD_TESTING) + if (CURSES) + add_executable(cata_test ${CATACLYSM_BN_TEST_SOURCES}) + if (LUA) + target_compile_definitions(cata_test PUBLIC LUA) + endif () + target_link_libraries(cata_test cataclysm-common) + add_test( + NAME test + COMMAND sh -c "$ --rng-seed time" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + endif () +endif () # vim:noet diff --git a/tools/clang-tidy-plugin/CMakeLists.txt b/tools/clang-tidy-plugin/CMakeLists.txt index 17a71597a1a8..baf4cbe53f50 100644 --- a/tools/clang-tidy-plugin/CMakeLists.txt +++ b/tools/clang-tidy-plugin/CMakeLists.txt @@ -24,47 +24,43 @@ add_library( UsePointApisCheck.cpp UsePointArithmeticCheck.cpp Utils.cpp - XYCheck.cpp - ) + XYCheck.cpp) -target_include_directories( - CataAnalyzerPlugin SYSTEM PRIVATE - ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS}) +target_include_directories(CataAnalyzerPlugin SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS} + ${CLANG_INCLUDE_DIRS}) if ("${CATA_CLANG_TIDY_INCLUDE_DIR}" STREQUAL "") set(CTPS_RELEASES https://github.com/jbytheway/clang-tidy-plugin-support/releases/download) set(CTPS_VERSION llvm-12.0.0-r3) set(CTPS_SRC ${CMAKE_CURRENT_BINARY_DIR}/clang-tidy-plugin-support) - ExternalProject_Add(clang-tidy-plugin-support - URL ${CTPS_RELEASES}/${CTPS_VERSION}/clang-tidy-plugin-support-${CTPS_VERSION}.tar.xz - URL_HASH SHA256=c84aaf35b4d5bb9130b1cc309a92146ae5c62fd69db30a6254725beac9d60990 - SOURCE_DIR ${CTPS_SRC} - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "") + ExternalProject_Add( + clang-tidy-plugin-support + URL ${CTPS_RELEASES}/${CTPS_VERSION}/clang-tidy-plugin-support-${CTPS_VERSION}.tar.xz + URL_HASH SHA256=c84aaf35b4d5bb9130b1cc309a92146ae5c62fd69db30a6254725beac9d60990 + SOURCE_DIR ${CTPS_SRC} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "") add_dependencies(CataAnalyzerPlugin clang-tidy-plugin-support) - target_include_directories( - CataAnalyzerPlugin SYSTEM PRIVATE ${CTPS_SRC}/include) -else() - target_include_directories( - CataAnalyzerPlugin SYSTEM PRIVATE ${CATA_CLANG_TIDY_INCLUDE_DIR}) -endif() + target_include_directories(CataAnalyzerPlugin SYSTEM PRIVATE ${CTPS_SRC}/include) +else () + target_include_directories(CataAnalyzerPlugin SYSTEM PRIVATE ${CATA_CLANG_TIDY_INCLUDE_DIR}) +endif () -target_compile_definitions( - CataAnalyzerPlugin PRIVATE ${LLVM_DEFINITIONS}) +target_compile_definitions(CataAnalyzerPlugin PRIVATE ${LLVM_DEFINITIONS}) # We need to turn off exceptions and RTTI to match the LLVM build. # I feel there ought to be a way to extract these flags from the # LLVMConfig.cmake as we have done for e.g. LLVM_INCLUDE_DIRS above, but I # haven't found one. -if(MSVC) -else() - target_compile_options( - CataAnalyzerPlugin PRIVATE -fno-exceptions -fno-rtti) -endif() +if (MSVC) + +else () + target_compile_options(CataAnalyzerPlugin PRIVATE -fno-exceptions -fno-rtti) +endif () configure_file(test/lit.site.cfg.in test/lit.site.cfg @ONLY) configure_file(test/.clang-tidy test/.clang-tidy COPYONLY) diff --git a/tools/format/CMakeLists.txt b/tools/format/CMakeLists.txt index 465eeaae64be..15c585880581 100644 --- a/tools/format/CMakeLists.txt +++ b/tools/format/CMakeLists.txt @@ -1,11 +1,7 @@ include(ExternalProject) -add_executable( - json_formatter - format.cpp - ${CMAKE_SOURCE_DIR}/src/json.cpp - ) +add_executable(json_formatter format.cpp ${CMAKE_SOURCE_DIR}/src/json.cpp) -ADD_DEFINITIONS(-DCATA_IN_TOOL) +add_definitions(-DCATA_IN_TOOL) -INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src ) +include_directories(${CMAKE_SOURCE_DIR}/src)