diff --git a/.cmake-format.yml b/.cmake-format.yml deleted file mode 100644 index ca7a01af99c8..000000000000 --- a/.cmake-format.yml +++ /dev/null @@ -1,43 +0,0 @@ -# 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/.editorconfig b/.editorconfig index 5b6a27beec3c..13288f0c69c2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,6 +15,7 @@ indent_style = tab [*.{json,yml,yaml,md,markdown}] indent_size = 2 +charset = utf-8 [{.clang-tidy,.clang-format}] indent_size = 2 diff --git a/.github/vcpkg_ports/freetype/0003-Fix-UWP.patch b/.github/vcpkg_ports/freetype/0003-Fix-UWP.patch new file mode 100644 index 000000000000..4beb8d5ec7ab --- /dev/null +++ b/.github/vcpkg_ports/freetype/0003-Fix-UWP.patch @@ -0,0 +1,65 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index db48e9f..5c35276 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -328,6 +328,10 @@ else () + list(APPEND BASE_SRCS src/base/ftdebug.c) + endif () + ++if(MSVC) ++ add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS) ++endif() ++ + if (BUILD_FRAMEWORK) + list(APPEND BASE_SRCS builds/mac/freetype-Info.plist) + endif () +diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h +index 4f2eaca..1e01fe4 100644 +--- a/include/freetype/freetype.h ++++ b/include/freetype/freetype.h +@@ -1038,6 +1038,11 @@ FT_BEGIN_HEADER + * Especially for TrueType fonts see also the documentation for + * @FT_Size_Metrics. + */ ++ ++#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) ++#define generic GenericFromFreeTypeLibrary ++#endif ++ + typedef struct FT_FaceRec_ + { + FT_Long num_faces; +@@ -1910,6 +1915,9 @@ FT_BEGIN_HEADER + + } FT_GlyphSlotRec; + ++#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) ++#undef generic ++#endif + + /*************************************************************************/ + /*************************************************************************/ +diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c +index 3f8619d..edf03b6 100644 +--- a/src/base/ftobjs.c ++++ b/src/base/ftobjs.c +@@ -528,6 +528,9 @@ + return error; + } + ++#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) ++#define generic GenericFromFreeTypeLibrary ++#endif + + static void + ft_glyphslot_clear( FT_GlyphSlot slot ) +@@ -1195,6 +1198,9 @@ + FT_FREE( face ); + } + ++#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) ++#undef generic ++#endif + + static void + Destroy_Driver( FT_Driver driver ) diff --git a/.github/vcpkg_ports/freetype/brotli-static.patch b/.github/vcpkg_ports/freetype/brotli-static.patch new file mode 100644 index 000000000000..3ab8624fb46a --- /dev/null +++ b/.github/vcpkg_ports/freetype/brotli-static.patch @@ -0,0 +1,25 @@ +diff --git a/builds/cmake/FindBrotliDec.cmake b/builds/cmake/FindBrotliDec.cmake +index 46356b1fd..ed4cc2409 100644 +--- a/builds/cmake/FindBrotliDec.cmake ++++ b/builds/cmake/FindBrotliDec.cmake +@@ -35,10 +35,19 @@ find_path(BROTLIDEC_INCLUDE_DIRS + PATH_SUFFIXES brotli) + + find_library(BROTLIDEC_LIBRARIES +- NAMES brotlidec ++ NAMES brotlidec brotlidec-static NAMES_PER_DIR + HINTS ${PC_BROTLIDEC_LIBDIR} + ${PC_BROTLIDEC_LIBRARY_DIRS}) + ++get_filename_component(z_vcpkg_freetype_brotlidec_name "${BROTLIDEC_LIBRARIES}" NAME) ++if(z_vcpkg_freetype_brotlidec_name MATCHES "-static") ++ find_library(BROTLICOMMON_LIBRARIES ++ NAMES brotlicommon-static ++ HINTS ${PC_BROTLIDEC_LIBDIR} ++ ${PC_BROTLIDEC_LIBRARY_DIRS}) ++ set(BROTLIDEC_LIBRARIES "${BROTLIDEC_LIBRARIES};${BROTLICOMMON_LIBRARIES}") ++endif() ++unset(z_vcpkg_freetype_brotlidec_name) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( diff --git a/.github/vcpkg_ports/freetype/bzip2.patch b/.github/vcpkg_ports/freetype/bzip2.patch new file mode 100644 index 000000000000..a73f5c122413 --- /dev/null +++ b/.github/vcpkg_ports/freetype/bzip2.patch @@ -0,0 +1,13 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 469a141a2..eec19c7d0 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -517,7 +517,7 @@ if (BZIP2_FOUND) + if (PC_BZIP2_FOUND) + list(APPEND PKGCONFIG_REQUIRES_PRIVATE "bzip2") + else () +- list(APPEND PKGCONFIG_LIBS_PRIVATE "-lbz2") ++ list(APPEND PKGCONFIG_REQUIRES_PRIVATE "bzip2") + endif () + endif () + if (PNG_FOUND) diff --git a/.github/vcpkg_ports/freetype/error-strings.patch b/.github/vcpkg_ports/freetype/error-strings.patch new file mode 100644 index 000000000000..df1e51bdfef3 --- /dev/null +++ b/.github/vcpkg_ports/freetype/error-strings.patch @@ -0,0 +1,37 @@ +From 5672a353682a68cb76a03179739bdec0a2f5cf0e Mon Sep 17 00:00:00 2001 +From: Sean Farrell +Date: Fri, 19 Aug 2022 15:32:19 +0200 +Subject: [PATCH] Adds config support for error strings. + +--- + CMakeLists.txt | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index feb4be39a..4eea860e8 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -215,6 +215,8 @@ cmake_dependent_option(FT_REQUIRE_BROTLI + "Require support of compressed WOFF2 fonts." OFF + "NOT FT_DISABLE_BROTLI" OFF) + ++option(FT_ENABLE_ERROR_STRINGS ++ "Enable support for meaningful error descriptions" OFF) + + # Disallow in-source builds + if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") +@@ -353,6 +355,11 @@ if (BROTLIDEC_FOUND) + "/\\* +(#define +FT_CONFIG_OPTION_USE_BROTLI) +\\*/" "\\1" + FTOPTION_H "${FTOPTION_H}") + endif () ++if (FT_ENABLE_ERROR_STRINGS) ++ string(REGEX REPLACE ++ "/\\* +(#define +FT_CONFIG_OPTION_ERROR_STRINGS) +\\*/" "\\1" ++ FTOPTION_H "${FTOPTION_H}") ++endif () + + set(FTOPTION_H_NAME "${PROJECT_BINARY_DIR}/include/freetype/config/ftoption.h") + if (EXISTS "${FTOPTION_H_NAME}") +-- +2.33.0.windows.2 + diff --git a/.github/vcpkg_ports/freetype/fix-exports.patch b/.github/vcpkg_ports/freetype/fix-exports.patch new file mode 100644 index 000000000000..ee55ec63e886 --- /dev/null +++ b/.github/vcpkg_ports/freetype/fix-exports.patch @@ -0,0 +1,40 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index cb1b9a0f2..edca5d579 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -508,7 +508,6 @@ set(PKG_CONFIG_REQUIRED_PRIVATE "") + set(PKGCONFIG_LIBS_PRIVATE "") + + if (ZLIB_FOUND) +- target_link_libraries(freetype PRIVATE ${ZLIB_LIBRARIES}) ++ target_link_libraries(freetype PRIVATE ZLIB::ZLIB) +- target_include_directories(freetype PRIVATE ${ZLIB_INCLUDE_DIRS}) + list(APPEND PKGCONFIG_REQUIRES_PRIVATE "zlib") + endif () +@@ -596,12 +596,25 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) + install( + EXPORT freetype-targets + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/freetype +- FILE freetype-config.cmake + COMPONENT headers) + install( + FILES ${PROJECT_BINARY_DIR}/freetype-config-version.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/freetype + COMPONENT headers) ++ ++ if(ZLIB_FOUND) ++ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/freetype-config.cmake" ++[[include(CMakeFindDependencyMacro) ++find_dependency(ZLIB) ++include("${CMAKE_CURRENT_LIST_DIR}/freetype-targets.cmake") ++]]) ++ else() ++ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/freetype-config.cmake" ++[[include("${CMAKE_CURRENT_LIST_DIR}/freetype-targets.cmake") ++]]) ++ endif() ++ ++ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freetype-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/freetype) + endif () + + diff --git a/.github/vcpkg_ports/freetype/portfile.cmake b/.github/vcpkg_ports/freetype/portfile.cmake new file mode 100644 index 000000000000..6bba8eaf0bb0 --- /dev/null +++ b/.github/vcpkg_ports/freetype/portfile.cmake @@ -0,0 +1,85 @@ +set(FT_VERSION 2.12.1) + +vcpkg_from_sourceforge( + OUT_SOURCE_PATH SOURCE_PATH + REPO freetype/freetype2 + REF ${FT_VERSION} + FILENAME freetype-${FT_VERSION}.tar.xz + SHA512 6482de1748dc2cc01e033d21a3b492dadb1f039d13d9179685fdcf985e24d7f587cbca4c27ed8a7fdb7d9ad59612642ac5f4db062443154753295363f45c052f + PATCHES + 0003-Fix-UWP.patch + brotli-static.patch + bzip2.patch + fix-exports.patch + error-strings.patch +) + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + zlib FT_REQUIRE_ZLIB + bzip2 FT_REQUIRE_BZIP2 + error-strings FT_ENABLE_ERROR_STRINGS + png FT_REQUIRE_PNG + brotli FT_REQUIRE_BROTLI + INVERTED_FEATURES + zlib FT_DISABLE_ZLIB + bzip2 FT_DISABLE_BZIP2 + png FT_DISABLE_PNG + brotli FT_DISABLE_BROTLI +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + -DFT_DISABLE_HARFBUZZ=ON + ${FEATURE_OPTIONS} +) + +vcpkg_cmake_install() +vcpkg_copy_pdbs() +vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/freetype) + +# Rename for easy usage (VS integration; CMake and autotools will not care) +file(RENAME "${CURRENT_PACKAGES_DIR}/include/freetype2/freetype" "${CURRENT_PACKAGES_DIR}/include/freetype") +file(RENAME "${CURRENT_PACKAGES_DIR}/include/freetype2/ft2build.h" "${CURRENT_PACKAGES_DIR}/include/ft2build.h") +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/include/freetype2") +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") + +# Fix the include dir [freetype2 -> freetype] +file(READ "${CURRENT_PACKAGES_DIR}/share/freetype/freetype-targets.cmake" CONFIG_MODULE) +string(REPLACE "\${_IMPORT_PREFIX}/include/freetype2" "\${_IMPORT_PREFIX}/include" CONFIG_MODULE "${CONFIG_MODULE}") +string(REPLACE "\${_IMPORT_PREFIX}/lib/brotlicommon-static.lib" [[\$<\$>:${_IMPORT_PREFIX}/lib/brotlicommon-static.lib>;\$<\$:${_IMPORT_PREFIX}/debug/lib/brotlicommon-static.lib>]] CONFIG_MODULE "${CONFIG_MODULE}") +string(REPLACE "\${_IMPORT_PREFIX}/lib/brotlidec-static.lib" [[\$<\$>:${_IMPORT_PREFIX}/lib/brotlidec-static.lib>;\$<\$:${_IMPORT_PREFIX}/debug/lib/brotlidec-static.lib>]] CONFIG_MODULE "${CONFIG_MODULE}") +string(REPLACE "\${_IMPORT_PREFIX}/lib/brotlidec.lib" [[\$<\$>:${_IMPORT_PREFIX}/lib/brotlidec.lib>;\$<\$:${_IMPORT_PREFIX}/debug/lib/brotlidec.lib>]] CONFIG_MODULE "${CONFIG_MODULE}") +string(REPLACE "\${_IMPORT_PREFIX}/lib/brotlidec.lib" [[\$<\$>:${_IMPORT_PREFIX}/lib/brotlidec.lib>;\$<\$:${_IMPORT_PREFIX}/debug/lib/brotlidec.lib>]] CONFIG_MODULE "${CONFIG_MODULE}") +file(WRITE ${CURRENT_PACKAGES_DIR}/share/freetype/freetype-targets.cmake "${CONFIG_MODULE}") + +find_library(FREETYPE_DEBUG NAMES freetyped PATHS "${CURRENT_PACKAGES_DIR}/debug/lib/" NO_DEFAULT_PATH) +if(NOT VCPKG_BUILD_TYPE) + file(READ "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/freetype2.pc" _contents) + if(FREETYPE_DEBUG) + string(REPLACE "-lfreetype" "-lfreetyped" _contents "${_contents}") + endif() + string(REPLACE "-I\${includedir}/freetype2" "-I\${includedir}" _contents "${_contents}") + file(WRITE "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/freetype2.pc" "${_contents}") +endif() + +file(READ "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/freetype2.pc" _contents) +string(REPLACE "-I\${includedir}/freetype2" "-I\${includedir}" _contents "${_contents}") +file(WRITE "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/freetype2.pc" "${_contents}") + + +vcpkg_fixup_pkgconfig() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") + +configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" + "${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake" @ONLY) +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +vcpkg_install_copyright( + FILE_LIST + "${SOURCE_PATH}/LICENSE.TXT" + "${SOURCE_PATH}/docs/FTL.TXT" + "${SOURCE_PATH}/docs/GPLv2.TXT" +) diff --git a/.github/vcpkg_ports/freetype/usage b/.github/vcpkg_ports/freetype/usage new file mode 100644 index 000000000000..00cf65d30eaa --- /dev/null +++ b/.github/vcpkg_ports/freetype/usage @@ -0,0 +1,4 @@ +freetype is compatible with built-in CMake targets: + + find_package(Freetype REQUIRED) + target_link_libraries(main PRIVATE Freetype::Freetype) # since CMake 3.10 diff --git a/.github/vcpkg_ports/freetype/vcpkg-cmake-wrapper.cmake b/.github/vcpkg_ports/freetype/vcpkg-cmake-wrapper.cmake new file mode 100644 index 000000000000..ee332c3c6f29 --- /dev/null +++ b/.github/vcpkg_ports/freetype/vcpkg-cmake-wrapper.cmake @@ -0,0 +1,64 @@ +cmake_policy(PUSH) +cmake_policy(SET CMP0012 NEW) +cmake_policy(SET CMP0054 NEW) + +_find_package(${ARGS}) + +if("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static") + if("@FT_REQUIRE_ZLIB@") + find_package(ZLIB) + endif() + if("@FT_REQUIRE_BZIP2@") + find_package(BZip2) + endif() + if("@FT_REQUIRE_PNG@") + find_package(PNG) + endif() + if("@FT_REQUIRE_BROTLI@") + find_library(BROTLIDEC_LIBRARY_RELEASE NAMES brotlidec brotlidec-static PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" PATH_SUFFIXES lib NO_DEFAULT_PATH) + find_library(BROTLIDEC_LIBRARY_DEBUG NAMES brotlidec brotlidec-static brotlidecd brotlidec-staticd PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug" PATH_SUFFIXES lib NO_DEFAULT_PATH) + find_library(BROTLICOMMON_LIBRARY_RELEASE NAMES brotlicommon brotlicommon-static PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" PATH_SUFFIXES lib NO_DEFAULT_PATH) + find_library(BROTLICOMMON_LIBRARY_DEBUG NAMES brotlicommon brotlicommon-static brotlicommond brotlicommon-staticd PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug" PATH_SUFFIXES lib NO_DEFAULT_PATH) + include(SelectLibraryConfigurations) + select_library_configurations(BROTLIDEC) + select_library_configurations(BROTLICOMMON) + endif("@FT_REQUIRE_BROTLI@") + + if(TARGET Freetype::Freetype) + if("@FT_REQUIRE_ZLIB@") + set_property(TARGET Freetype::Freetype APPEND PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) + endif() + if("@FT_REQUIRE_BZIP2@") + set_property(TARGET Freetype::Freetype APPEND PROPERTY INTERFACE_LINK_LIBRARIES BZip2::BZip2) + endif() + if("@FT_REQUIRE_PNG@") + set_property(TARGET Freetype::Freetype APPEND PROPERTY INTERFACE_LINK_LIBRARIES PNG::PNG) + endif() + if("@FT_REQUIRE_BROTLI@") + if(BROTLIDEC_LIBRARY_DEBUG) + set_property(TARGET Freetype::Freetype APPEND PROPERTY INTERFACE_LINK_LIBRARIES "\$<\$:${BROTLIDEC_LIBRARY_DEBUG}>") + set_property(TARGET Freetype::Freetype APPEND PROPERTY INTERFACE_LINK_LIBRARIES "\$<\$:${BROTLICOMMON_LIBRARY_DEBUG}>") + endif() + if(BROTLIDEC_LIBRARY_RELEASE) + set_property(TARGET Freetype::Freetype APPEND PROPERTY INTERFACE_LINK_LIBRARIES "\$<\$>:${BROTLIDEC_LIBRARY_RELEASE}>") + set_property(TARGET Freetype::Freetype APPEND PROPERTY INTERFACE_LINK_LIBRARIES "\$<\$>:${BROTLICOMMON_LIBRARY_RELEASE}>") + endif() + endif() + endif() + + if(FREETYPE_LIBRARIES) + if("@FT_REQUIRE_ZLIB@") + list(APPEND FREETYPE_LIBRARIES ${ZLIB_LIBRARIES}) + endif() + if("@FT_REQUIRE_BZIP2@") + list(APPEND FREETYPE_LIBRARIES ${BZIP2_LIBRARIES}) + endif() + if("@FT_REQUIRE_PNG@") + list(APPEND FREETYPE_LIBRARIES ${PNG_LIBRARIES}) + endif() + if("@FT_REQUIRE_BROTLI@") + list(APPEND FREETYPE_LIBRARIES ${BROTLIDEC_LIBRARIES} ${BROTLICOMMON_LIBRARIES}) + endif() + endif() +endif() +cmake_policy(POP) diff --git a/.github/vcpkg_ports/freetype/vcpkg.json b/.github/vcpkg_ports/freetype/vcpkg.json new file mode 100644 index 000000000000..17ec99ece521 --- /dev/null +++ b/.github/vcpkg_ports/freetype/vcpkg.json @@ -0,0 +1,52 @@ +{ + "name": "freetype", + "version": "2.12.1", + "port-version": 3, + "description": "A library to render fonts.", + "homepage": "https://www.freetype.org/", + "license": "FTL OR GPL-2.0-or-later", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "default-features": [ + "bzip2", + "png", + "zlib" + ], + "features": { + "brotli": { + "description": "Support decompression of WOFF2 streams", + "dependencies": [ + "brotli" + ] + }, + "bzip2": { + "description": "Support bzip2 compressed fonts.", + "dependencies": [ + "bzip2" + ] + }, + "error-strings": { + "description": "Enable support for meaningful error descriptions." + }, + "png": { + "description": "Support PNG compressed OpenType embedded bitmaps.", + "dependencies": [ + "libpng" + ] + }, + "zlib": { + "description": "Use zlib instead of internal library for DEFLATE", + "dependencies": [ + "zlib" + ] + } + } +} diff --git a/.github/workflows/autofix.yml b/.github/workflows/autofix.yml index 2eb388f4c7f4..63b9251c012a 100644 --- a/.github/workflows/autofix.yml +++ b/.github/workflows/autofix.yml @@ -18,8 +18,6 @@ jobs: - run: sudo apt-get install astyle - - run: sudo pip install cmakelang - - uses: denoland/setup-deno@v1 with: deno-version: v1.x @@ -30,9 +28,6 @@ jobs: - name: format markdown and typescript 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/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 0bee8ce9fdb3..9265de0c9ae5 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -51,7 +51,7 @@ jobs: sudo apt-get update sudo apt-get install libncursesw5-dev clang-12 libclang-12-dev llvm-12-dev llvm-12-tools \ libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libpulse-dev ccache \ - gettext + libflac-dev gettext - name: prepare run: bash ./build-scripts/requirements.sh diff --git a/.github/workflows/matrix.yml b/.github/workflows/matrix.yml index 21108d416695..d7b7c08f4c46 100644 --- a/.github/workflows/matrix.yml +++ b/.github/workflows/matrix.yml @@ -190,7 +190,7 @@ jobs: - name: install SDL2 dependencies (ubuntu) if: ${{ env.SKIP == 'false' && runner.os == 'Linux' && matrix.tiles == 1 }} run: | - sudo apt-get install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libpulse-dev + sudo apt-get install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libpulse-dev libflac-dev - name: check compiler (mac) if: ${{ env.SKIP == 'false' && runner.os == 'macOS' }} diff --git a/.github/workflows/msvc-full-features-cmake.yml b/.github/workflows/msvc-full-features-cmake.yml new file mode 100644 index 000000000000..e6c29f56f161 --- /dev/null +++ b/.github/workflows/msvc-full-features-cmake.yml @@ -0,0 +1,96 @@ +name: Cataclysm Windows build (CMake + MSVC) + +on: + push: + branches: + - upload + paths-ignore: + - 'android/**' + - 'build-data/osx/**' + - 'doc/**' + - 'doxygen_doc/**' + - 'gfx/**' + - 'lang/**' + - 'lgtm/**' + - 'tools/**' + - '!tools/format/**' + - 'utilities/**' + - 'scripts/**' + +# We only care about the latest revision, so cancel previous instances. +concurrency: + group: msvc-cmake-build-${{ github.ref_name }} + cancel-in-progress: true + +env: + # There's not enough disk space to build both release and debug versions of + # our dependencies, so we hack the triplet file to build only release versions + # Have to use github.workspace because runner namespace isn't available yet. + VCPKG_OVERLAY_TRIPLETS: ${{ github.workspace }}\.github\vcpkg_triplets + ZSTD_CLEVEL: 17 + CMAKE_PRESET: windows-tiles-sounds-x64-msvc + +jobs: + build_catatclysm: + name: Build + runs-on: windows-2019 + if: github.event.pull_request.draft == false + + steps: + - name: checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1.3.1 + + - name: Remove Strawberry Perl from PATH + run: | + echo $env:PATH + echo ========================= + $env:PATH = $env:PATH -replace "C:\\Strawberry\\c\\bin;", "" + $env:PATH = $env:PATH -replace "C:\\Strawberry\\perl\\site\\bin;", "" + $env:PATH = $env:PATH -replace "C:\\Strawberry\\perl\\bin;", "" + "PATH=$env:PATH" | Out-File -FilePath $env:GITHUB_ENV -Append + echo ========================= + echo $env:PATH + + - name: Install stable CMake + uses: lukka/get-cmake@latest + + - name: Install vcpkg + uses: lukka/run-vcpkg@v11 + id: runvcpkg + with: + vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg' + vcpkgGitCommitId: 'c9aba300923c8ec0ab190e2bff23085209925c97' + + - name: Integrate vcpkg + run: | + vcpkg integrate install + + - uses: ammaraskar/msvc-problem-matcher@master + - name: Configure + run: | + cmake -DTESTS=ON --preset $env:CMAKE_PRESET + + - uses: ammaraskar/msvc-problem-matcher@master + - name: Build + run: | + cmake --build out/build/$env:CMAKE_PRESET --config RelWithDebInfo + + - name: Dump logs if build failed + if: failure() + run: | + echo ================================================= + Get-ChildItem "${{ runner.workspace }}/Cataclysm-BN/out/build/$env:CMAKE_PRESET" -Recurse + echo ================================================= + + - name: Compile .mo files for localization + run: | + cmake --build out/build/$env:CMAKE_PRESET --target translations_compile --config RelWithDebInfo + + - name: Run tests + run: | + .\RelWithDebInfo\cata_test-tiles.exe --rng-seed time diff --git a/.github/workflows/msvc-full-features.yml b/.github/workflows/msvc-full-features.yml index 0e86dc543ca8..753daef2fe3f 100644 --- a/.github/workflows/msvc-full-features.yml +++ b/.github/workflows/msvc-full-features.yml @@ -59,18 +59,15 @@ jobs: - name: Add msbuild to PATH uses: microsoft/setup-msbuild@v1.3.1 - - name: Restore artifacts, or run vcpkg, build and cache artifacts - uses: lukka/run-vcpkg@v10 + - name: Install stable CMake + uses: lukka/get-cmake@latest + + - name: Install vcpkg + uses: lukka/run-vcpkg@v11 id: runvcpkg with: - # run-vcpkg tries to hash vcpkg.json but complans if it finds more than one. - # That said, we also have our custom vcpkg_triplets to hash, so we keep everything the same. - appendedCacheKey: ${{ hashFiles( 'msvc-full-features/vcpkg.json', '.github/vcpkg_triplets/**' ) }}-x64 vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg' - # Keep vcpkg version here in sync with the builtin-baseline - # field in vcpkg.json. Caching happens as a post-action which runs at the end of - # the whole workflow, after vcpkg install happens during msbuild run. - vcpkgGitCommitId: 'a7b6122f6b6504d16d96117336a0562693579933' + vcpkgGitCommitId: 'c9aba300923c8ec0ab190e2bff23085209925c97' - name: Integrate vcpkg run: | diff --git a/.github/workflows/msys2-cmake.yml b/.github/workflows/msys2-cmake.yml new file mode 100644 index 000000000000..77c9a18d96de --- /dev/null +++ b/.github/workflows/msys2-cmake.yml @@ -0,0 +1,86 @@ +name: Windows build (CMake + MSYS2) + +on: + push: + branches: + - upload + paths-ignore: + - 'android/**' + - 'build-data/osx/**' + - 'doc/**' + - 'doxygen_doc/**' + - 'gfx/**' + - 'lang/**' + - 'tools/**' + - '!tools/format/**' + - 'utilities/**' + - 'scripts/**' + +# We only care about the latest revision, so cancel previous instances. +concurrency: + group: msys2-cmake-build-${{ github.ref_name }} + cancel-in-progress: true + +jobs: + build_catatclysm: + name: Build + runs-on: windows-2019 + if: github.event.pull_request.draft == false + + defaults: + run: + shell: msys2 {0} + + steps: + - name: checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: Setup MSYS2 + # Will by default install MINGW64 + uses: msys2/setup-msys2@v2 + with: + update: true + install: | + git + make + gettext + mingw-w64-x86_64-libmad + mingw-w64-x86_64-libwebp + mingw-w64-x86_64-pkg-config + mingw-w64-x86_64-SDL2 + mingw-w64-x86_64-SDL2_image + mingw-w64-x86_64-SDL2_mixer + mingw-w64-x86_64-SDL2_ttf + mingw-w64-x86_64-toolchain + mingw-w64-x86_64-cmake + + - name: Create build directory + run: mkdir build + + - name: Configure + run: | + cd build + cmake.exe \ + -DTILES=ON \ + -DSOUND=ON \ + -DLUA=ON \ + -DTESTS=ON \ + -DDYNAMIC_LINKING=ON \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_CXX_FLAGS="-w" \ + -G "Ninja" \ + .. + + - name: Build + run: | + cmake.exe --build build -j$((`nproc`+0)) + + - name: Compile translations + run: | + cmake.exe --build build --target translations_compile + + - name: Run tests + run: | + ./build/tests/cata_test-tiles.exe --rng-seed time diff --git a/.github/workflows/msys2.yml b/.github/workflows/msys2.yml index 019e2ad9393d..03cf00060a5d 100644 --- a/.github/workflows/msys2.yml +++ b/.github/workflows/msys2.yml @@ -1,4 +1,4 @@ -name: Cataclysm Windows build (MSYS2) +name: Windows build (MSYS2) on: push: @@ -15,24 +15,10 @@ on: - '!tools/format/**' - 'utilities/**' - 'scripts/**' - pull_request: - branches: - - upload - paths-ignore: - - 'android/**' - - 'build-data/osx/**' - - 'doc/**' - - 'doxygen_doc/**' - - 'gfx/**' - - 'lang/**' - - 'tools/**' - - '!tools/format/**' - - 'utilities/**' - - 'scripts/**' -# We only care about the latest revision of a PR, so cancel previous instances. +# We only care about the latest revision, so cancel previous instances. concurrency: - group: msys2-build-${{ github.event.pull_request.number || github.ref_name }} + group: msys2-build-${{ github.ref_name }} cancel-in-progress: true jobs: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 941a48e1aa62..cfa561f72db9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -182,24 +182,18 @@ jobs: commit sha: ${{ github.sha }} commit url: https://github.com/${{ github.repository }}/commit/${{ github.sha }} EOL - - name: Install dependencies (windows msvc) (1/3) + - name: Install MSBuild (windows msvc) if: runner.os == 'Windows' uses: microsoft/setup-msbuild@v1.3.1 - - name: Install dependencies (windows msvc) (2/3) - if: runner.os == 'Windows' - uses: lukka/run-vcpkg@main + - name: Install stable CMake + uses: lukka/get-cmake@latest + - name: Install vcpkg + uses: lukka/run-vcpkg@v11 id: runvcpkg with: - additionalCachedPaths: "${{ runner.workspace }}/Cataclysm-BN/msvc-full-features/vcpkg_installed" - appendedCacheKey: ${{ hashFiles( 'msvc-full-features/vcpkg.json', '.github/vcpkg_triplets/**' ) }}-${{ matrix.arch }}-1 - setupOnly: true - vcpkgDirectory: "${{ runner.workspace }}/b/vcpkg" - # We have to use at least this version of vcpkg to include fixes for - # various issues we've encountered over time. Keep it in sync with the builtin-baseline - # field in vcpkg.json. Caching happens as a post-action which runs at the end of - # the whole workflow, after vcpkg install happens during msbuild run. - vcpkgGitCommitId: "a7b6122f6b6504d16d96117336a0562693579933" - - name: Install dependencies (windows msvc) (3/3) + vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg' + vcpkgGitCommitId: 'c9aba300923c8ec0ab190e2bff23085209925c97' + - name: Integrate vcpkg if: runner.os == 'Windows' run: | vcpkg integrate install diff --git a/.gitignore b/.gitignore index 734b36c2e162..447d480e1c01 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ /objwin/ /save/ /src/version.h +/src/prefix.h /sound/ /templates/ /tools/format/json_formatter.cgi @@ -62,6 +63,11 @@ Release*/ # Distribution script results /msvc-full-features/distribution +# Temporary CMakeFiles +CMakeUserPresets.json +out/ +RelWithDebInfo*/ + # Visual Studio 2015 /msvc-full-features/*db /msvc-full-features/ipch @@ -94,7 +100,6 @@ tags # Generated translation source /lang/po/cataclysm-bn.pot -/lang/po/en.po # Compiled binary translations /lang/mo/ @@ -204,3 +209,6 @@ Xcode/ /tests/pch/tests-pch.hpp.pch /tests/catch/catch.hpp.gch /tests/catch/catch.hpp.pch + +# VERSION.txt generated by our CMakeLists.txt +VERSION.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 700800055b7a..d37b71170687 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,70 +1,56 @@ -# Main project build script -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.20) -project(CataclysmBN) +project(CataclysmBN CXX) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMakeModules) +list(APPEND CMAKE_MODULE_PATH + ${CMAKE_SOURCE_DIR}/CMakeModules) +if (NOT VCPKG_MANIFEST_MODE) + list(APPEND CMAKE_MODULE_PATH + ${CMAKE_SOURCE_DIR}/CMakeModules/Find) +endif() include(AstyleFormatSource) set(CMAKE_TLS_VERIFY ON) # Build options +include(CMakeDependentOption) 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. \ +option(USE_XDG_DIR "Use XDG directories for save and config files." "OFF") +option(USE_HOME_DIR "Use user's home directory for save and config files." "ON") +cmake_dependent_option(USE_PREFIX_DATA_DIR + "Use UNIX system directories for game data in release build." ON + "UNIX" OFF +) +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(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(TESTS "Compile Cata's tests" "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(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") +set(GETTEXT_MSGFMT_BINARY "" CACHE FILEPATH "msgfmt binary name or path.") + +if (TESTS) include(CTest) +endif() -include(GetGitRevisionDescription) -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 * https://github.com/cataclysmbnteam/Cataclysm-BN\n") - -message(STATUS "${PROJECT} build environment -- \n") - -message( - STATUS "Build realm is : ${CMAKE_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_PROCESSOR}") +message(STATUS "${PROJECT_NAME} build environment --") +message(STATUS "Build realm is: ${CMAKE_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_PROCESSOR}") if (LINKER) add_link_options("-fuse-ld=${LINKER}") @@ -76,14 +62,27 @@ endif () add_definitions(-DCMAKE) +include(GetGitRevisionDescription) +git_describe(GIT_VERSION --tags --always --match "[0-9A-Z]*.[0-9A-Z]*") 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") + message(STATUS "${PROJECT_NAME} build version is: ${GIT_VERSION}") add_definitions(-DGIT_VERSION) -else () - message("") + + # get_git_head_revision() does not work with worktrees in Windows + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE _sha1 + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(TIMESTAMP _timestamp %Y-%m-%d-%H%M) + file(WRITE VERSION.txt "\ +build type: ${BUILD_PRESET_NAME}\n\ +build number: ${_timestamp}\n\ +commit sha: ${_sha1}\n\ +commit url: https://github.com/cataclysmbnteam/Cataclysm-BN/commit/${_sha1}" + ) endif () #OS Check Placeholders. Will be used for BINDIST @@ -112,19 +111,22 @@ 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") +find_package(PkgConfig) if (NOT DYNAMIC_LINKING) - set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.dll.a") + if(NOT MSVC) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.dll.a") + endif() set(BUILD_SHARED_LIBRARIES OFF) - check_cxx_compiler_flag(-static HAVE_STATIC_FLAG) + 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_C_FLAGS) # remove -Wl,-Bdynamic set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS) - set(CMAKE_SHARED_LIBRARY_C_FLAGS) # remove -fPIC + 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_C_FLAGS) # remove -rdynamic set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) else () if (MINGW AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") @@ -133,38 +135,7 @@ else () endif () endif () -# System specific actions -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") +message(STATUS "${PROJECT_NAME} build options --") # Preset variables if (NOT LANGUAGES) @@ -176,8 +147,9 @@ if (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.") + 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 () @@ -186,67 +158,70 @@ if (TILES) set(CURSES OFF) endif () +# Can't use both home and xdg directories +if (USE_XDG_DIR) + set(USE_HOME_DIR OFF) +endif () + # Set build types and display info if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") set(RELEASE 0) - message("\n") - message(STATUS "Build ${PROJECT} in development mode --\n") + message(STATUS "Build ${PROJECT_NAME} in development mode --") message(STATUS "Binaries will be located in: " ${CMAKE_SOURCE_DIR}) set(CMAKE_VERBOSE_MAKEFILE ON) - # Since CataclysmDDA does not respect PREFIX for development builds + # Since CataclysmBN 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}) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR} CACHE PATH + "Single Directory for all Executables.") + set(CMAKE_INSTALL_BINDIR .) else () set(RELEASE 1) + add_definitions(-DRELEASE) + # Use CMAKE_INSTALL_PREFIX as storage of data,gfx, etc.. Useful only on *nix OS. + if(USE_PREFIX_DATA_DIR) + if ("${CMAKE_SYSTEM_NAME}" MATCHES "(Linux|FreeBSD|Darwin)") + set(CMAKE_INSTALL_DATAROOTDIR "${CMAKE_INSTALL_PREFIX}/share/cataclysm-bn") + add_definitions(-DPREFIX=${CMAKE_INSTALL_PREFIX}) + configure_file( + "${CMAKE_SOURCE_DIR}/src/prefix.h.in" + "${CMAKE_SOURCE_DIR}/src/prefix.h" + @ONLY) + add_definitions(-DDATA_DIR_PREFIX) + endif () + else() + set(CMAKE_INSTALL_DATADIR data) + set(CMAKE_INSTALL_DOCDIR . ) + set(CMAKE_INSTALL_LOCALEDIR lang) + set(CMAKE_INSTALL_BINDIR . ) + endif () message(STATUS "CMAKE_INSTALL_PREFIX : ${CMAKE_INSTALL_PREFIX}") - message(STATUS "BIN_PREFIX : ${BIN_PREFIX}") - message(STATUS "DATA_PREFIX : ${DATA_PREFIX}") + message(STATUS "CMAKE_INSTALL_BINDIR : ${CMAKE_INSTALL_BINDIR}") 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 () + message(STATUS "MANPAGE_ENTRY_PATH : ${MANPAGE_ENTRY_PATH}") 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 "USE_XDG_DIR : ${USE_XDG_DIR}") +message(STATUS "USE_HOME_DIR : ${USE_HOME_DIR}") message(STATUS "UNITY_BUILD : ${USE_UNITY_BUILD}") -message(STATUS "PCH_HEADER : ${USE_PCH_HEADER}") -message(STATUS "LANGUAGES : ${LANGUAGES}\n") - +message(STATUS "LANGUAGES : ${LANGUAGES}") if (LINKER) - message(STATUS "LINKER : ${LINKER}\n") + message(STATUS "LINKER : ${LINKER}") endif () -message(STATUS "See CMake compiling guide for details and more info --\n") +message(STATUS "See CMake compiling guide for details and more info --") -if (MSVC) - if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") - add_definitions(-D_AMD64_) - else () - add_definitions(-D_X86_) - endif () -else () +if (NOT MSVC) set(CATA_WARNINGS "-Werror -Wall -Wextra \ -Wformat-signedness \ @@ -261,30 +236,37 @@ else () -Wunused-macros \ -Wzero-as-null-pointer-constant \ -Wno-unknown-warning-option \ + -Wno-dangling-reference \ -Wno-range-loop-analysis") + if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + set(CATA_WARNINGS "${CATA_WARNINGS} -Wno-unknown-warning-option") + else() + set(CATA_WARNINGS "${CATA_WARNINGS} -Wno-unknown-warning") + endif() if (NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Windows") set(CATA_WARNINGS "${CATA_WARNINGS} -Wredundant-decls") endif () - set(CATA_OTHER_FLAGS "${CATA_OTHER_FLAGS} -fsigned-char") + set(CATA_OTHER_FLAGS "${CATA_OTHER_FLAGS} -fsigned-char -g1") # 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") + set(CMAKE_CXX_FLAGS_DEBUG "-Og -g2") endif () set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) # Force out-of-source build if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") - message( - FATAL_ERROR + message(FATAL_ERROR "This project requires an out of source build. \ - Remove the file 'CMakeCache.txt' found in this directory before continuing, \ + 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(THREADS_USE_PTHREADS_WIN32 True) set(CMAKE_THREAD_PREFER_PTHREAD True) find_package(Threads REQUIRED) @@ -292,62 +274,58 @@ find_package(Threads REQUIRED) 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. \ - 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) + if (NOT CMAKE_FIND_PACKAGE_PREFER_CONFIG) + set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) + # ^^ Use sdl2-config.cmake provided by the system or VCPKG + find_package(SDL2) + if(NOT SDL2_FOUND) + # Use our CMakeModules/Find/FindSDL2.cmake + set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF) + find_package(SDL2) + endif() + set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF) + endif() + if (NOT (SDL2_FOUND OR TARGET SDL2::SDL2 OR TARGET SDL2::SDL2-static)) + message(FATAL_ERROR + "This project requires SDL2 to be installed to compile in graphical mode. \ + Please install the SDL2 development libraries, \ + or try compiling without -DTILES=1 for a text-only compilation. \ + See CMake compiling guide for details and more info.") 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. \ + if (NOT (SDL2_TTF_FOUND OR TARGET SDL2::SDL2_ttf OR TARGET SDL2_ttf::SDL2_ttf-static)) + message(FATAL_ERROR + "This project requires SDL2_ttf to be installed to compile in graphical mode. \ + Please install the SDL2_ttf development libraries, \ + or try compiling without -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") + message(STATUS "Searching for SDL2_image library --") 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.") + if (NOT (SDL2_IMAGE_FOUND OR TARGET SDL2::SDL2_image OR TARGET SDL2_image::SDL2_image-static)) + message(FATAL_ERROR + "This project requires SDL2_image to be installed to compile in graphical mode. \ + Please install the SDL2_image development libraries, \ + or try compiling without -DTILES=1 for a text-only compilation. \ + See doc/COMPILING/COMPILING-CMAKE.md 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") + message(STATUS "Searching for Curses library --") 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. \ + 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 -DTILES=1 for a graphical compilation. \ See CMake compiling guide for details and more info.") endif () if (NOT DYNAMIC_LINKING) @@ -358,21 +336,22 @@ 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. \ + 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") + message(STATUS "Searching for SDL2_mixer library --") 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 () + if (NOT (SDL2_MIXER_FOUND OR TARGET SDL2_mixer::SDL2_mixer + OR TARGET SDL2_mixer::SDL2_mixer-static)) + 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) @@ -382,36 +361,79 @@ if (BACKTRACE) endif () endif () +if (NOT (LANGUAGES STREQUAL "none") AND "${GETTEXT_MSGFMT_BINARY}" STREQUAL "") + if(MSVC) + list(APPEND Gettext_ROOT C:\\msys64\\usr) + list(APPEND Gettext_ROOT C:\\Program\ Files\\Git\\usr) + endif(MSVC) + find_package(Gettext) +endif () +if (NOT GETTEXT_MSGFMT_EXECUTABLE ) + set(GETTEXT_MSGFMT_EXECUTABLE "${GETTEXT_MSGFMT_BINARY}") +endif() + # Ok. Now create build and install recipes +add_subdirectory(lang) + if (USE_HOME_DIR) add_definitions(-DUSE_HOME_DIR) endif () +if (USE_XDG_DIR) + add_definitions(-DUSE_XDG_DIR) +endif () + +find_program(CCACHE_FOUND ccache) +if (CCACHE_FOUND AND CATA_CCACHE) + set(CMAKE_C_COMPILER_LAUNCHER ccache) + set(CMAKE_CXX_COMPILER_LAUNCHER ccache) + set(CMAKE_C_LINKER_LAUNCHER ccache) + set(CMAKE_CXX_LINKER_LAUNCHER ccache) +endif () + add_subdirectory(src) add_subdirectory(data) -add_subdirectory(lang) -add_subdirectory(tests) +if(TESTS) + add_subdirectory(tests) +endif() + 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) +install(DIRECTORY doc TYPE DOC) -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) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) - set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) -endif () +if (RELEASE) + install(FILES + ${CMAKE_SOURCE_DIR}/README.md + ${CMAKE_SOURCE_DIR}/LICENSE.txt + ${CMAKE_SOURCE_DIR}/LICENSE-OFL-Terminus-Font.txt + ${CMAKE_SOURCE_DIR}/VERSION.txt + TYPE DOC) + if (TILES) + if (USE_PREFIX_DATA_DIR) + install(DIRECTORY ${CMAKE_SOURCE_DIR}/gfx + TYPE DATA) + else() + install(DIRECTORY ${CMAKE_SOURCE_DIR}/gfx + DESTINATION .) + endif() + endif() +endif() + +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") if (USE_UNITY_BUILD) set_property(GLOBAL PROPERTY UNITY_BUILD ON) endif () -# vim:noet diff --git a/CMakeModules/CMakeParseArguments.cmake b/CMakeModules/CMakeParseArguments.cmake deleted file mode 100644 index 4248176ad664..000000000000 --- a/CMakeModules/CMakeParseArguments.cmake +++ /dev/null @@ -1,160 +0,0 @@ -#.rst: -# CMakeParseArguments -# ------------------- -# -# -# -# CMAKE_PARSE_ARGUMENTS( -# args...) -# -# CMAKE_PARSE_ARGUMENTS() is intended to be used in macros or functions -# for parsing the arguments given to that macro or function. It -# processes the arguments and defines a set of variables which hold the -# values of the respective options. -# -# The argument contains all options for the respective macro, -# i.e. keywords which can be used when calling the macro without any -# value following, like e.g. the OPTIONAL keyword of the install() -# command. -# -# The argument contains all keywords for this macro -# which are followed by one value, like e.g. DESTINATION keyword of the -# install() command. -# -# The argument contains all keywords for this -# macro which can be followed by more than one value, like e.g. the -# TARGETS or FILES keywords of the install() command. -# -# When done, CMAKE_PARSE_ARGUMENTS() will have defined for each of the -# keywords listed in , and -# a variable composed of the given -# followed by "_" and the name of the respective keyword. These -# variables will then hold the respective value from the argument list. -# For the keywords this will be TRUE or FALSE. -# -# All remaining arguments are collected in a variable -# _UNPARSED_ARGUMENTS, this can be checked afterwards to see -# whether your macro was called with unrecognized parameters. -# -# As an example here a my_install() macro, which takes similar arguments -# as the real install() command: -# -# :: -# -# function(MY_INSTALL) -# set(options OPTIONAL FAST) -# set(oneValueArgs DESTINATION RENAME) -# set(multiValueArgs TARGETS CONFIGURATIONS) -# cmake_parse_arguments(MY_INSTALL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) -# ... -# -# -# -# Assume my_install() has been called like this: -# -# :: -# -# my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub) -# -# -# -# After the cmake_parse_arguments() call the macro will have set the -# following variables: -# -# :: -# -# MY_INSTALL_OPTIONAL = TRUE -# MY_INSTALL_FAST = FALSE (this option was not used when calling my_install() -# MY_INSTALL_DESTINATION = "bin" -# MY_INSTALL_RENAME = "" (was not used) -# MY_INSTALL_TARGETS = "foo;bar" -# MY_INSTALL_CONFIGURATIONS = "" (was not used) -# MY_INSTALL_UNPARSED_ARGUMENTS = "blub" (no value expected after "OPTIONAL" -# -# -# -# You can then continue and process these variables. -# -# Keywords terminate lists of values, e.g. if directly after a -# one_value_keyword another recognized keyword follows, this is -# interpreted as the beginning of the new option. E.g. -# my_install(TARGETS foo DESTINATION OPTIONAL) would result in -# MY_INSTALL_DESTINATION set to "OPTIONAL", but MY_INSTALL_DESTINATION -# would be empty and MY_INSTALL_OPTIONAL would be set to TRUE therefor. - -#============================================================================= -# Copyright 2010 Alexander Neundorf -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - - -if(__CMAKE_PARSE_ARGUMENTS_INCLUDED) - return() -endif() -set(__CMAKE_PARSE_ARGUMENTS_INCLUDED TRUE) - - -function(CMAKE_PARSE_ARGUMENTS prefix _optionNames _singleArgNames _multiArgNames) - # first set all result variables to empty/FALSE - foreach(arg_name ${_singleArgNames} ${_multiArgNames}) - set(${prefix}_${arg_name}) - endforeach() - - foreach(option ${_optionNames}) - set(${prefix}_${option} FALSE) - endforeach() - - set(${prefix}_UNPARSED_ARGUMENTS) - - set(insideValues FALSE) - set(currentArgName) - - # now iterate over all arguments and fill the result variables - foreach(currentArg ${ARGN}) - list(FIND _optionNames "${currentArg}" optionIndex) # ... then this marks the end of the arguments belonging to this keyword - list(FIND _singleArgNames "${currentArg}" singleArgIndex) # ... then this marks the end of the arguments belonging to this keyword - list(FIND _multiArgNames "${currentArg}" multiArgIndex) # ... then this marks the end of the arguments belonging to this keyword - - if(${optionIndex} EQUAL -1 AND ${singleArgIndex} EQUAL -1 AND ${multiArgIndex} EQUAL -1) - if(insideValues) - if("${insideValues}" STREQUAL "SINGLE") - set(${prefix}_${currentArgName} ${currentArg}) - set(insideValues FALSE) - elseif("${insideValues}" STREQUAL "MULTI") - list(APPEND ${prefix}_${currentArgName} ${currentArg}) - endif() - else() - list(APPEND ${prefix}_UNPARSED_ARGUMENTS ${currentArg}) - endif() - else() - if(NOT ${optionIndex} EQUAL -1) - set(${prefix}_${currentArg} TRUE) - set(insideValues FALSE) - elseif(NOT ${singleArgIndex} EQUAL -1) - set(currentArgName ${currentArg}) - set(${prefix}_${currentArgName}) - set(insideValues "SINGLE") - elseif(NOT ${multiArgIndex} EQUAL -1) - set(currentArgName ${currentArg}) - set(${prefix}_${currentArgName}) - set(insideValues "MULTI") - endif() - endif() - - endforeach() - - # propagate the result variables to the caller: - foreach(arg_name ${_singleArgNames} ${_multiArgNames} ${_optionNames}) - set(${prefix}_${arg_name} ${${prefix}_${arg_name}} PARENT_SCOPE) - endforeach() - set(${prefix}_UNPARSED_ARGUMENTS ${${prefix}_UNPARSED_ARGUMENTS} PARENT_SCOPE) - -endfunction() diff --git a/CMakeModules/CMakePushCheckState.cmake b/CMakeModules/CMakePushCheckState.cmake deleted file mode 100644 index cc5a93e24c47..000000000000 --- a/CMakeModules/CMakePushCheckState.cmake +++ /dev/null @@ -1,120 +0,0 @@ -#============================================================================= -# Copyright 2000-2022 Kitware, Inc. and Contributors -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of Kitware, Inc. nor the names of Contributors -# may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#============================================================================= - -#[=======================================================================[.rst: -CMakePushCheckState -------------------- - - - -This module defines three macros: ``CMAKE_PUSH_CHECK_STATE()`` -``CMAKE_POP_CHECK_STATE()`` and ``CMAKE_RESET_CHECK_STATE()`` These macros can -be used to save, restore and reset (i.e., clear contents) the state of -the variables ``CMAKE_REQUIRED_FLAGS``, ``CMAKE_REQUIRED_DEFINITIONS``, -``CMAKE_REQUIRED_LINK_OPTIONS``, ``CMAKE_REQUIRED_LIBRARIES``, -``CMAKE_REQUIRED_INCLUDES`` and ``CMAKE_EXTRA_INCLUDE_FILES`` used by the -various Check-files coming with CMake, like e.g. ``check_function_exists()`` -etc. -The variable contents are pushed on a stack, pushing multiple times is -supported. This is useful e.g. when executing such tests in a Find-module, -where they have to be set, but after the Find-module has been executed they -should have the same value as they had before. - -``CMAKE_PUSH_CHECK_STATE()`` macro receives optional argument ``RESET``. -Whether it's specified, ``CMAKE_PUSH_CHECK_STATE()`` will set all -``CMAKE_REQUIRED_*`` variables to empty values, same as -``CMAKE_RESET_CHECK_STATE()`` call will do. - -Usage: - -.. code-block:: cmake - - cmake_push_check_state(RESET) - set(CMAKE_REQUIRED_DEFINITIONS -DSOME_MORE_DEF) - check_function_exists(...) - cmake_reset_check_state() - set(CMAKE_REQUIRED_DEFINITIONS -DANOTHER_DEF) - check_function_exists(...) - cmake_pop_check_state() -#]=======================================================================] - -macro(CMAKE_RESET_CHECK_STATE) - - set(CMAKE_EXTRA_INCLUDE_FILES) - set(CMAKE_REQUIRED_INCLUDES) - set(CMAKE_REQUIRED_DEFINITIONS) - set(CMAKE_REQUIRED_LINK_OPTIONS) - set(CMAKE_REQUIRED_LIBRARIES) - set(CMAKE_REQUIRED_FLAGS) - set(CMAKE_REQUIRED_QUIET) - -endmacro() - -macro(CMAKE_PUSH_CHECK_STATE) - - if(NOT DEFINED _CMAKE_PUSH_CHECK_STATE_COUNTER) - set(_CMAKE_PUSH_CHECK_STATE_COUNTER 0) - endif() - - math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}+1") - - set(_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_EXTRA_INCLUDE_FILES}) - set(_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_INCLUDES}) - set(_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_DEFINITIONS}) - set(_CMAKE_REQUIRED_LINK_OPTIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_LINK_OPTIONS}) - set(_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_LIBRARIES}) - set(_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_FLAGS}) - set(_CMAKE_REQUIRED_QUIET_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_QUIET}) - - if (${ARGC} GREATER 0 AND "${ARGV0}" STREQUAL "RESET") - cmake_reset_check_state() - endif() - -endmacro() - -macro(CMAKE_POP_CHECK_STATE) - -# don't pop more than we pushed - if("${_CMAKE_PUSH_CHECK_STATE_COUNTER}" GREATER "0") - - set(CMAKE_EXTRA_INCLUDE_FILES ${_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - set(CMAKE_REQUIRED_INCLUDES ${_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - set(CMAKE_REQUIRED_DEFINITIONS ${_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - set(CMAKE_REQUIRED_LINK_OPTIONS ${_CMAKE_REQUIRED_LINK_OPTIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - set(CMAKE_REQUIRED_FLAGS ${_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - set(CMAKE_REQUIRED_QUIET ${_CMAKE_REQUIRED_QUIET_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}}) - - math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}-1") - endif() - -endmacro() diff --git a/CMakeModules/CheckLibraryExists.cmake b/CMakeModules/CheckLibraryExists.cmake deleted file mode 100644 index 67d1b47dd2af..000000000000 --- a/CMakeModules/CheckLibraryExists.cmake +++ /dev/null @@ -1,78 +0,0 @@ -#.rst: -# CheckLibraryExists -# ------------------ -# -# Check if the function exists. -# -# CHECK_LIBRARY_EXISTS (LIBRARY FUNCTION LOCATION VARIABLE) -# -# :: -# -# LIBRARY - the name of the library you are looking for -# FUNCTION - the name of the function -# LOCATION - location where the library should be found -# VARIABLE - variable to store the result -# -# -# -# The following variables may be set before calling this macro to modify -# the way the check is run: -# -# :: -# -# CMAKE_REQUIRED_FLAGS = string of compile command line flags -# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) -# CMAKE_REQUIRED_LIBRARIES = list of libraries to link - -#============================================================================= -# Copyright 2002-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - - - -macro(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE) - if(${VARIABLE} MATCHES "^${VARIABLE}$") - set(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION - "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}") - message(STATUS "Looking for ${FUNCTION} in ${LIBRARY}") - set(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY}) - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_LIBRARY_EXISTS_LIBRARIES - ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES}) - endif() - try_compile(${VARIABLE} - ${CMAKE_BINARY_DIR} - ${CMAKE_ROOT}/Modules/CheckFunctionExists.c - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES} - CMAKE_FLAGS - -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION} - -DLINK_DIRECTORIES:STRING=${LOCATION} - OUTPUT_VARIABLE OUTPUT) - - if(${VARIABLE}) - message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found") - set(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if the function ${FUNCTION} exists in the ${LIBRARY} " - "passed with the following output:\n" - "${OUTPUT}\n\n") - else() - message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found") - set(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if the function ${FUNCTION} exists in the ${LIBRARY} " - "failed with the following output:\n" - "${OUTPUT}\n\n") - endif() - endif() -endmacro() diff --git a/CMakeModules/FindSDL2.cmake b/CMakeModules/Find/FindSDL2.cmake similarity index 100% rename from CMakeModules/FindSDL2.cmake rename to CMakeModules/Find/FindSDL2.cmake diff --git a/CMakeModules/FindSDL2_image.cmake b/CMakeModules/Find/FindSDL2_image.cmake similarity index 66% rename from CMakeModules/FindSDL2_image.cmake rename to CMakeModules/Find/FindSDL2_image.cmake index d04518faaa66..f42a15176c03 100644 --- a/CMakeModules/FindSDL2_image.cmake +++ b/CMakeModules/Find/FindSDL2_image.cmake @@ -94,4 +94,46 @@ set(SDL2IMAGE_LIBRARY ${SDL2_IMAGE_LIBRARIES}) set(SDL2IMAGE_INCLUDE_DIR ${SDL2_IMAGE_INCLUDE_DIRS}) set(SDL2IMAGE_FOUND ${SDL2_IMAGE_FOUND}) -mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR) \ No newline at end of file +mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR) + +if(NOT DYNAMIC_LINKING AND PKG_CONFIG_FOUND) + if (NOT TARGET SDL2_image:SDL2_image-static) + add_library(SDL2_image::SDL2_image-static STATIC IMPORTED) + set_property(TARGET SDL2_image::SDL2_image-static + PROPERTY IMPORTED_LOCATION ${SDL2_IMAGE_LIBRARY} + ) + endif() + message(STATUS "Searching for SDL_images deps libraries --") + find_package(JPEG REQUIRED) + find_package(PNG REQUIRED) + find_package(TIFF REQUIRED) + find_library(JBIG jbig REQUIRED) + find_package(LibLZMA REQUIRED) + target_link_libraries(SDL2_image::SDL2_image-static INTERFACE + JPEG::JPEG + PNG::PNG + TIFF::TIFF + ${JBIG} + LibLZMA::LibLZMA + ${ZSTD} + ) + pkg_check_modules(WEBP REQUIRED IMPORTED_TARGET libwebp) + pkg_check_modules(ZIP REQUIRED IMPORTED_TARGET libzip) + pkg_check_modules(ZSTD REQUIRED IMPORTED_TARGET libzstd) + pkg_check_modules(DEFLATE REQUIRED IMPORTED_TARGET libdeflate) + target_link_libraries(SDL2_image::SDL2_image-static INTERFACE + PkgConfig::WEBP + PkgConfig::ZIP + PkgConfig::ZSTD + PkgConfig::DEFLATE + ) +elseif(NOT TARGET SDL2_image::SDL2_image) + add_library(SDL2_image::SDL2_image UNKNOWN IMPORTED) + set_target_properties(SDL2_image::SDL2_image PROPERTIES + IMPORTED_LOCATION ${SDL2_IMAGE_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${SDL2_IMAGE_INCLUDE_DIRS} + ) + target_link_libraries(SDL2_image::SDL2_image INTERFACE + z + ) +endif() diff --git a/CMakeModules/FindSDL2_mixer.cmake b/CMakeModules/Find/FindSDL2_mixer.cmake similarity index 71% rename from CMakeModules/FindSDL2_mixer.cmake rename to CMakeModules/Find/FindSDL2_mixer.cmake index 537719238e75..e14a1557f42b 100644 --- a/CMakeModules/FindSDL2_mixer.cmake +++ b/CMakeModules/Find/FindSDL2_mixer.cmake @@ -94,4 +94,35 @@ set(SDL2MIXER_LIBRARY ${SDL2_MIXER_LIBRARIES}) set(SDL2MIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIRS}) set(SDL2MIXER_FOUND ${SDL2_MIXER_FOUND}) -mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR) \ No newline at end of file +mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR) + +if(NOT DYNAMIC_LINKING) + if (NOT TARGET SDL2_mixer::SDL2_mixer-static) + add_library(SDL2_mixer::SDL2_mixer-static STATIC IMPORTED) + set_target_properties(SDL2_mixer::SDL2_mixer-static PROPERTIES + IMPORTED_LOCATION ${SDL2_MIXER_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${SDL2_MIXER_INCLUDE_DIRS} + ) + endif() +elseif(NOT TARGET SDL2_mixer::SDL2_mixer) + add_library(SDL2_mixer::SDL2_mixer STATIC IMPORTED) + set_target_properties(SDL2_mixer::SDL2_mixer PROPERTIES + IMPORTED_LOCATION ${SDL2_MIXER_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${SDL2_MIXER_INCLUDE_DIRS} + ) +endif() + +if(PKG_CONFIG_FOUND) + message(STATUS "Searching for SDL_mixer deps libraries --") + if(TARGET SDL2_mixer::SDL2_mixer-static) + pkg_check_modules(FLAC REQUIRED IMPORTED_TARGET flac) + target_link_libraries(SDL2_mixer::SDL2_mixer-static INTERFACE + PkgConfig::FLAC + ) + elseif(TARGET SDL2_mixer::SDL2_mixer) + pkg_check_modules(FLAC REQUIRED IMPORTED_TARGET flac) + target_link_libraries(SDL2_mixer::SDL2_mixer INTERFACE + PkgConfig::FLAC + ) + endif() +endif() diff --git a/CMakeModules/FindSDL2_ttf.cmake b/CMakeModules/Find/FindSDL2_ttf.cmake similarity index 73% rename from CMakeModules/FindSDL2_ttf.cmake rename to CMakeModules/Find/FindSDL2_ttf.cmake index 733c667593cd..1bddc196f486 100644 --- a/CMakeModules/FindSDL2_ttf.cmake +++ b/CMakeModules/Find/FindSDL2_ttf.cmake @@ -93,4 +93,31 @@ set(SDL2TTF_LIBRARY ${SDL2_TTF_LIBRARIES}) set(SDL2TTF_INCLUDE_DIR ${SDL2_TTF_INCLUDE_DIRS}) set(SDL2TTF_FOUND ${SDL2_TTF_FOUND}) -mark_as_advanced(SDL2_TTF_LIBRARY SDL2_TTF_INCLUDE_DIR) \ No newline at end of file +mark_as_advanced(SDL2_TTF_LIBRARY SDL2_TTF_INCLUDE_DIR) + +if (NOT DYNAMIC_LINKING AND PKG_CONFIG_FOUND) + if (NOT TARGET SDL2_ttf::SDL2_ttf-static) + add_library(SDL2_ttf::SDL2_ttf-static STATIC IMPORTED) + set_target_properties(SDL2_ttf::SDL2_ttf-static PROPERTIES + IMPORTED_LOCATION ${SDL2_TTF_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${SDL2_TTF_INCLUDE_DIRS} + ) + endif() + message(STATUS "Searching for SDL_ttf deps libraries --") + find_package(Freetype REQUIRED) + find_package(Harfbuzz REQUIRED) + target_link_libraries(SDL2_ttf::SDL2_ttf-static INTERFACE + Freetype::Freetype + harfbuzz::harfbuzz + ) + pkg_check_modules(BROTLI REQUIRED IMPORTED_TARGET libbrotlidec libbrotlicommon) + target_link_libraries(Freetype::Freetype INTERFACE + PkgConfig::BROTLI + ) +elseif(NOT TARGET SDL2_ttf::SDL2_ttf) + add_library(SDL2_ttf::SDL2_ttf UNKNOWN IMPORTED) + set_target_properties(SDL2_ttf::SDL2_ttf PROPERTIES + IMPORTED_LOCATION ${SDL2_TTF_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${SDL2_TTF_INCLUDE_DIRS} + ) +endif() \ No newline at end of file diff --git a/CMakeModules/FindCurses.cmake b/CMakeModules/FindCurses.cmake deleted file mode 100644 index dbd252bba695..000000000000 --- a/CMakeModules/FindCurses.cmake +++ /dev/null @@ -1,305 +0,0 @@ -#============================================================================= -# Copyright 2000-2022 Kitware, Inc. and Contributors -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of Kitware, Inc. nor the names of Contributors -# may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#============================================================================= - -#[=======================================================================[.rst: -FindCurses ----------- - -Find the curses or ncurses include file and library. - -Result Variables -^^^^^^^^^^^^^^^^ - -This module defines the following variables: - -``CURSES_FOUND`` - True if Curses is found. -``CURSES_INCLUDE_DIRS`` - The include directories needed to use Curses. -``CURSES_LIBRARIES`` - The libraries needed to use Curses. -``CURSES_CFLAGS`` - .. versionadded:: 3.16 - - Parameters which ought be given to C/C++ compilers when using Curses. -``CURSES_HAVE_CURSES_H`` - True if curses.h is available. -``CURSES_HAVE_NCURSES_H`` - True if ncurses.h is available. -``CURSES_HAVE_NCURSES_NCURSES_H`` - True if ``ncurses/ncurses.h`` is available. -``CURSES_HAVE_NCURSES_CURSES_H`` - True if ``ncurses/curses.h`` is available. - -Set ``CURSES_NEED_NCURSES`` to ``TRUE`` before the -``find_package(Curses)`` call if NCurses functionality is required. - -.. versionadded:: 3.10 - Set ``CURSES_NEED_WIDE`` to ``TRUE`` before the - ``find_package(Curses)`` call if unicode functionality is required. - -Backward Compatibility -^^^^^^^^^^^^^^^^^^^^^^ - -The following variable are provided for backward compatibility: - -``CURSES_INCLUDE_DIR`` - Path to Curses include. Use ``CURSES_INCLUDE_DIRS`` instead. -``CURSES_LIBRARY`` - Path to Curses library. Use ``CURSES_LIBRARIES`` instead. -#]=======================================================================] - -include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake) - -# we don't know anything about cursesw, so only ncurses -# may be ncursesw -if(NOT CURSES_NEED_WIDE) - set(NCURSES_LIBRARY_NAME "ncurses") - set(CURSES_FORM_LIBRARY_NAME "form") -else() - set(NCURSES_LIBRARY_NAME "ncursesw") - set(CURSES_FORM_LIBRARY_NAME "formw") - # Also, if we are searching for wide curses - we are actually searching - # for ncurses, we don't know about any other unicode version. - set(CURSES_NEED_NCURSES TRUE) -endif() - -find_library(CURSES_CURSES_LIBRARY NAMES curses) - -find_library(CURSES_NCURSES_LIBRARY NAMES "${NCURSES_LIBRARY_NAME}" ) -set(CURSES_USE_NCURSES FALSE) - -if(CURSES_NCURSES_LIBRARY AND ((NOT CURSES_CURSES_LIBRARY) OR CURSES_NEED_NCURSES)) - set(CURSES_USE_NCURSES TRUE) -endif() -# http://cygwin.com/ml/cygwin-announce/2010-01/msg00002.html -# cygwin ncurses stopped providing curses.h symlinks see above -# message. Cygwin is an ncurses package, so force ncurses on -# cygwin if the curses.h is missing -if(CURSES_NCURSES_LIBRARY AND CYGWIN) - if (CURSES_NEED_WIDE) - if(NOT EXISTS /usr/include/ncursesw/curses.h) - set(CURSES_USE_NCURSES TRUE) - endif() - else() - if(NOT EXISTS /usr/include/curses.h) - set(CURSES_USE_NCURSES TRUE) - endif() - endif() -endif() - - -# Not sure the logic is correct here. -# If NCurses is required, use the function wsyncup() to check if the library -# has NCurses functionality (at least this is where it breaks on NetBSD). -# If wsyncup is in curses, use this one. -# If not, try to find ncurses and check if this has the symbol. -# Once the ncurses library is found, search the ncurses.h header first, but -# some web pages also say that even with ncurses there is not always a ncurses.h: -# http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html -# So at first try ncurses.h, if not found, try to find curses.h under the same -# prefix as the library was found, if still not found, try curses.h with the -# default search paths. -if(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES) - include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake) - cmake_push_check_state() - set(CMAKE_REQUIRED_QUIET ${Curses_FIND_QUIETLY}) - CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}" - wsyncup "" CURSES_CURSES_HAS_WSYNCUP) - - if(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP) - CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}" - wsyncup "" CURSES_NCURSES_HAS_WSYNCUP) - if( CURSES_NCURSES_HAS_WSYNCUP) - set(CURSES_USE_NCURSES TRUE) - endif() - endif() - cmake_pop_check_state() - -endif() - -if(CURSES_USE_NCURSES) - get_filename_component(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH) - get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH) - - # Use CURSES_NCURSES_INCLUDE_PATH if set, for compatibility. - if(CURSES_NCURSES_INCLUDE_PATH) - if (CURSES_NEED_WIDE) - find_path(CURSES_INCLUDE_PATH - NAMES ncursesw/ncurses.h ncursesw/curses.h ncursesw.h cursesw.h - PATHS ${CURSES_NCURSES_INCLUDE_PATH} - NO_DEFAULT_PATH - ) - else() - find_path(CURSES_INCLUDE_PATH - NAMES ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h - PATHS ${CURSES_NCURSES_INCLUDE_PATH} - NO_DEFAULT_PATH - ) - endif() - endif() - - if (CURSES_NEED_WIDE) - set(CURSES_TINFO_LIBRARY_NAME tinfow) - find_path(CURSES_INCLUDE_PATH - NAMES ncursesw/ncurses.h ncursesw/curses.h ncursesw.h cursesw.h - HINTS "${_cursesParentDir}/include" - ) - else() - set(CURSES_TINFO_LIBRARY_NAME tinfo) - find_path(CURSES_INCLUDE_PATH - NAMES ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h - HINTS "${_cursesParentDir}/include" - ) - endif() - - # Previous versions of FindCurses provided these values. - if(NOT DEFINED CURSES_LIBRARY) - set(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}") - endif() - - CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}" - cbreak "" CURSES_NCURSES_HAS_CBREAK) - CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}" - nodelay "" CURSES_NCURSES_HAS_NODELAY) - if(NOT CURSES_NCURSES_HAS_CBREAK OR NOT CURSES_NCURSES_HAS_NODELAY) - find_library(CURSES_EXTRA_LIBRARY "${CURSES_TINFO_LIBRARY_NAME}" HINTS "${_cursesLibDir}") - find_library(CURSES_EXTRA_LIBRARY "${CURSES_TINFO_LIBRARY_NAME}" ) - - mark_as_advanced( - CURSES_EXTRA_LIBRARY - ) - endif() -else() - get_filename_component(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH) - get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH) - - #We can't find anything with CURSES_NEED_WIDE because we know - #only about ncursesw unicode curses version - if(NOT CURSES_NEED_WIDE) - find_path(CURSES_INCLUDE_PATH - NAMES curses.h - HINTS "${_cursesParentDir}/include" - ) - endif() - - # Previous versions of FindCurses provided these values. - if(NOT DEFINED CURSES_CURSES_H_PATH) - set(CURSES_CURSES_H_PATH "${CURSES_INCLUDE_PATH}") - endif() - if(NOT DEFINED CURSES_LIBRARY) - set(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}") - endif() -endif() - -# Report whether each possible header name exists in the include directory. -if(NOT DEFINED CURSES_HAVE_NCURSES_NCURSES_H) - if(CURSES_NEED_WIDE) - if(EXISTS "${CURSES_INCLUDE_PATH}/ncursesw/ncurses.h") - set(CURSES_HAVE_NCURSES_NCURSES_H "${CURSES_INCLUDE_PATH}/ncursesw/ncurses.h") - endif() - elseif(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h") - set(CURSES_HAVE_NCURSES_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h") - endif() - if(NOT DEFINED CURSES_HAVE_NCURSES_NCURSES_H) - set(CURSES_HAVE_NCURSES_NCURSES_H "CURSES_HAVE_NCURSES_NCURSES_H-NOTFOUND") - endif() -endif() -if(NOT DEFINED CURSES_HAVE_NCURSES_CURSES_H) - if(CURSES_NEED_WIDE) - if(EXISTS "${CURSES_INCLUDE_PATH}/ncursesw/curses.h") - set(CURSES_HAVE_NCURSES_CURSES_H "${CURSES_INCLUDE_PATH}/ncursesw/curses.h") - endif() - elseif(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/curses.h") - set(CURSES_HAVE_NCURSES_CURSES_H "${CURSES_INCLUDE_PATH}/ncurses/curses.h") - endif() - if(NOT DEFINED CURSES_HAVE_NCURSES_CURSES_H) - set(CURSES_HAVE_NCURSES_CURSES_H "CURSES_HAVE_NCURSES_CURSES_H-NOTFOUND") - endif() -endif() -if(NOT CURSES_NEED_WIDE) - #ncursesw can't be found for this paths - if(NOT DEFINED CURSES_HAVE_NCURSES_H) - if(EXISTS "${CURSES_INCLUDE_PATH}/ncurses.h") - set(CURSES_HAVE_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses.h") - else() - set(CURSES_HAVE_NCURSES_H "CURSES_HAVE_NCURSES_H-NOTFOUND") - endif() - endif() - if(NOT DEFINED CURSES_HAVE_CURSES_H) - if(EXISTS "${CURSES_INCLUDE_PATH}/curses.h") - set(CURSES_HAVE_CURSES_H "${CURSES_INCLUDE_PATH}/curses.h") - else() - set(CURSES_HAVE_CURSES_H "CURSES_HAVE_CURSES_H-NOTFOUND") - endif() - endif() -endif() - -find_library(CURSES_FORM_LIBRARY "${CURSES_FORM_LIBRARY_NAME}" HINTS "${_cursesLibDir}") -find_library(CURSES_FORM_LIBRARY "${CURSES_FORM_LIBRARY_NAME}" ) - -# Previous versions of FindCurses provided these values. -if(NOT DEFINED FORM_LIBRARY) - set(FORM_LIBRARY "${CURSES_FORM_LIBRARY}") -endif() - -# Need to provide the *_LIBRARIES -set(CURSES_LIBRARIES ${CURSES_LIBRARY}) - -if(CURSES_EXTRA_LIBRARY) - set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY}) -endif() - -if(CURSES_FORM_LIBRARY) - set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY}) -endif() - -# Provide the *_INCLUDE_DIRS and *_CFLAGS results. -set(CURSES_INCLUDE_DIRS ${CURSES_INCLUDE_PATH}) -set(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH}) # compatibility - -find_package(PkgConfig QUIET) -if(PKG_CONFIG_FOUND) - pkg_check_modules(NCURSES QUIET ${NCURSES_LIBRARY_NAME}) - set(CURSES_CFLAGS ${NCURSES_CFLAGS_OTHER}) -endif() - -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG - CURSES_LIBRARY CURSES_INCLUDE_PATH) - -mark_as_advanced( - CURSES_INCLUDE_PATH - CURSES_CURSES_LIBRARY - CURSES_NCURSES_LIBRARY - CURSES_FORM_LIBRARY - ) diff --git a/CMakeModules/FindPackageHandleStandardArgs.cmake b/CMakeModules/FindPackageHandleStandardArgs.cmake deleted file mode 100644 index d03041852de8..000000000000 --- a/CMakeModules/FindPackageHandleStandardArgs.cmake +++ /dev/null @@ -1,351 +0,0 @@ -#.rst: -# FindPackageHandleStandardArgs -# ----------------------------- -# -# -# -# FIND_PACKAGE_HANDLE_STANDARD_ARGS( ... ) -# -# This function is intended to be used in FindXXX.cmake modules files. -# It handles the REQUIRED, QUIET and version-related arguments to -# find_package(). It also sets the _FOUND variable. The -# package is considered found if all variables ... listed contain -# valid results, e.g. valid filepaths. -# -# There are two modes of this function. The first argument in both -# modes is the name of the Find-module where it is called (in original -# casing). -# -# The first simple mode looks like this: -# -# :: -# -# FIND_PACKAGE_HANDLE_STANDARD_ARGS( (DEFAULT_MSG|"Custom failure message") ... ) -# -# If the variables to are all valid, then -# _FOUND will be set to TRUE. If DEFAULT_MSG is given -# as second argument, then the function will generate itself useful -# success and error messages. You can also supply a custom error -# message for the failure case. This is not recommended. -# -# The second mode is more powerful and also supports version checking: -# -# :: -# -# FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME [FOUND_VAR ] -# [REQUIRED_VARS ...] -# [VERSION_VAR ] -# [HANDLE_COMPONENTS] -# [CONFIG_MODE] -# [FAIL_MESSAGE "Custom failure message"] ) -# -# -# -# In this mode, the name of the result-variable can be set either to -# either _FOUND or _FOUND using the -# FOUND_VAR option. Other names for the result-variable are not -# allowed. So for a Find-module named FindFooBar.cmake, the two -# possible names are FooBar_FOUND and FOOBAR_FOUND. It is recommended -# to use the original case version. If the FOUND_VAR option is not -# used, the default is _FOUND. -# -# As in the simple mode, if through are all valid, -# _FOUND will be set to TRUE. After REQUIRED_VARS the -# variables which are required for this package are listed. Following -# VERSION_VAR the name of the variable can be specified which holds the -# version of the package which has been found. If this is done, this -# version will be checked against the (potentially) specified required -# version used in the find_package() call. The EXACT keyword is also -# handled. The default messages include information about the required -# version and the version which has been actually found, both if the -# version is ok or not. If the package supports components, use the -# HANDLE_COMPONENTS option to enable handling them. In this case, -# find_package_handle_standard_args() will report which components have -# been found and which are missing, and the _FOUND variable -# will be set to FALSE if any of the required components (i.e. not the -# ones listed after OPTIONAL_COMPONENTS) are missing. Use the option -# CONFIG_MODE if your FindXXX.cmake module is a wrapper for a -# find_package(... NO_MODULE) call. In this case VERSION_VAR will be -# set to _VERSION and the macro will automatically check whether -# the Config module was found. Via FAIL_MESSAGE a custom failure -# message can be specified, if this is not used, the default message -# will be displayed. -# -# Example for mode 1: -# -# :: -# -# find_package_handle_standard_args(LibXml2 DEFAULT_MSG LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) -# -# -# -# LibXml2 is considered to be found, if both LIBXML2_LIBRARY and -# LIBXML2_INCLUDE_DIR are valid. Then also LIBXML2_FOUND is set to -# TRUE. If it is not found and REQUIRED was used, it fails with -# FATAL_ERROR, independent whether QUIET was used or not. If it is -# found, success will be reported, including the content of . On -# repeated Cmake runs, the same message won't be printed again. -# -# Example for mode 2: -# -# :: -# -# find_package_handle_standard_args(LibXslt FOUND_VAR LibXslt_FOUND -# REQUIRED_VARS LibXslt_LIBRARIES LibXslt_INCLUDE_DIRS -# VERSION_VAR LibXslt_VERSION_STRING) -# -# In this case, LibXslt is considered to be found if the variable(s) -# listed after REQUIRED_VAR are all valid, i.e. LibXslt_LIBRARIES and -# LibXslt_INCLUDE_DIRS in this case. The result will then be stored in -# LibXslt_FOUND . Also the version of LibXslt will be checked by using -# the version contained in LibXslt_VERSION_STRING. Since no -# FAIL_MESSAGE is given, the default messages will be printed. -# -# Another example for mode 2: -# -# :: -# -# find_package(Automoc4 QUIET NO_MODULE HINTS /opt/automoc4) -# find_package_handle_standard_args(Automoc4 CONFIG_MODE) -# -# In this case, FindAutmoc4.cmake wraps a call to find_package(Automoc4 -# NO_MODULE) and adds an additional search directory for automoc4. Here -# the result will be stored in AUTOMOC4_FOUND. The following -# FIND_PACKAGE_HANDLE_STANDARD_ARGS() call produces a proper -# success/error message. - -#============================================================================= -# Copyright 2007-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake) -include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake) - -# internal helper macro -macro(_FPHSA_FAILURE_MESSAGE _msg) - if (${_NAME}_FIND_REQUIRED) - message(FATAL_ERROR "${_msg}") - else () - if (NOT ${_NAME}_FIND_QUIETLY) - message(STATUS "${_msg}") - endif () - endif () -endmacro() - - -# internal helper macro to generate the failure message when used in CONFIG_MODE: -macro(_FPHSA_HANDLE_FAILURE_CONFIG_MODE) - # _CONFIG is set, but FOUND is false, this means that some other of the REQUIRED_VARS was not found: - if(${_NAME}_CONFIG) - _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: missing: ${MISSING_VARS} (found ${${_NAME}_CONFIG} ${VERSION_MSG})") - else() - # If _CONSIDERED_CONFIGS is set, the config-file has been found, but no suitable version. - # List them all in the error message: - if(${_NAME}_CONSIDERED_CONFIGS) - set(configsText "") - list(LENGTH ${_NAME}_CONSIDERED_CONFIGS configsCount) - math(EXPR configsCount "${configsCount} - 1") - foreach(currentConfigIndex RANGE ${configsCount}) - list(GET ${_NAME}_CONSIDERED_CONFIGS ${currentConfigIndex} filename) - list(GET ${_NAME}_CONSIDERED_VERSIONS ${currentConfigIndex} version) - set(configsText "${configsText} ${filename} (version ${version})\n") - endforeach() - if (${_NAME}_NOT_FOUND_MESSAGE) - set(configsText "${configsText} Reason given by package: ${${_NAME}_NOT_FOUND_MESSAGE}\n") - endif() - _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} ${VERSION_MSG}, checked the following files:\n${configsText}") - - else() - # Simple case: No Config-file was found at all: - _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: found neither ${_NAME}Config.cmake nor ${_NAME_LOWER}-config.cmake ${VERSION_MSG}") - endif() - endif() -endmacro() - - -function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) - -# set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in -# new extended or in the "old" mode: - set(options CONFIG_MODE HANDLE_COMPONENTS) - set(oneValueArgs FAIL_MESSAGE VERSION_VAR FOUND_VAR) - set(multiValueArgs REQUIRED_VARS) - set(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} ) - list(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX) - - if(${INDEX} EQUAL -1) - set(FPHSA_FAIL_MESSAGE ${_FIRST_ARG}) - set(FPHSA_REQUIRED_VARS ${ARGN}) - set(FPHSA_VERSION_VAR) - else() - - CMAKE_PARSE_ARGUMENTS(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN}) - - if(FPHSA_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unknown keywords given to FIND_PACKAGE_HANDLE_STANDARD_ARGS(): \"${FPHSA_UNPARSED_ARGUMENTS}\"") - endif() - - if(NOT FPHSA_FAIL_MESSAGE) - set(FPHSA_FAIL_MESSAGE "DEFAULT_MSG") - endif() - endif() - -# now that we collected all arguments, process them - - if("${FPHSA_FAIL_MESSAGE}" STREQUAL "DEFAULT_MSG") - set(FPHSA_FAIL_MESSAGE "Could NOT find ${_NAME}") - endif() - - # In config-mode, we rely on the variable _CONFIG, which is set by find_package() - # when it successfully found the config-file, including version checking: - if(FPHSA_CONFIG_MODE) - list(INSERT FPHSA_REQUIRED_VARS 0 ${_NAME}_CONFIG) - list(REMOVE_DUPLICATES FPHSA_REQUIRED_VARS) - set(FPHSA_VERSION_VAR ${_NAME}_VERSION) - endif() - - if(NOT FPHSA_REQUIRED_VARS) - message(FATAL_ERROR "No REQUIRED_VARS specified for FIND_PACKAGE_HANDLE_STANDARD_ARGS()") - endif() - - list(GET FPHSA_REQUIRED_VARS 0 _FIRST_REQUIRED_VAR) - - string(TOUPPER ${_NAME} _NAME_UPPER) - string(TOLOWER ${_NAME} _NAME_LOWER) - - if(FPHSA_FOUND_VAR) - if(FPHSA_FOUND_VAR MATCHES "^${_NAME}_FOUND$" OR FPHSA_FOUND_VAR MATCHES "^${_NAME_UPPER}_FOUND$") - set(_FOUND_VAR ${FPHSA_FOUND_VAR}) - else() - message(FATAL_ERROR "The argument for FOUND_VAR is \"${FPHSA_FOUND_VAR}\", but only \"${_NAME}_FOUND\" and \"${_NAME_UPPER}_FOUND\" are valid names.") - endif() - else() - set(_FOUND_VAR ${_NAME_UPPER}_FOUND) - endif() - - # collect all variables which were not found, so they can be printed, so the - # user knows better what went wrong (#6375) - set(MISSING_VARS "") - set(DETAILS "") - # check if all passed variables are valid - unset(${_FOUND_VAR}) - foreach(_CURRENT_VAR ${FPHSA_REQUIRED_VARS}) - if(NOT ${_CURRENT_VAR}) - set(${_FOUND_VAR} FALSE) - set(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}") - else() - set(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]") - endif() - endforeach() - if(NOT "${${_FOUND_VAR}}" STREQUAL "FALSE") - set(${_FOUND_VAR} TRUE) - endif() - - # component handling - unset(FOUND_COMPONENTS_MSG) - unset(MISSING_COMPONENTS_MSG) - - if(FPHSA_HANDLE_COMPONENTS) - foreach(comp ${${_NAME}_FIND_COMPONENTS}) - if(${_NAME}_${comp}_FOUND) - - if(NOT DEFINED FOUND_COMPONENTS_MSG) - set(FOUND_COMPONENTS_MSG "found components: ") - endif() - set(FOUND_COMPONENTS_MSG "${FOUND_COMPONENTS_MSG} ${comp}") - - else() - - if(NOT DEFINED MISSING_COMPONENTS_MSG) - set(MISSING_COMPONENTS_MSG "missing components: ") - endif() - set(MISSING_COMPONENTS_MSG "${MISSING_COMPONENTS_MSG} ${comp}") - - if(${_NAME}_FIND_REQUIRED_${comp}) - set(${_FOUND_VAR} FALSE) - set(MISSING_VARS "${MISSING_VARS} ${comp}") - endif() - - endif() - endforeach() - set(COMPONENT_MSG "${FOUND_COMPONENTS_MSG} ${MISSING_COMPONENTS_MSG}") - set(DETAILS "${DETAILS}[c${COMPONENT_MSG}]") - endif() - - # version handling: - set(VERSION_MSG "") - set(VERSION_OK TRUE) - set(VERSION ${${FPHSA_VERSION_VAR}} ) - if (${_NAME}_FIND_VERSION) - - if(VERSION) - - if(${_NAME}_FIND_VERSION_EXACT) # exact version required - if (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}") - set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"") - set(VERSION_OK FALSE) - else () - set(VERSION_MSG "(found suitable exact version \"${VERSION}\")") - endif () - - else() # minimum version specified: - if ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}") - set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is at least \"${${_NAME}_FIND_VERSION}\"") - set(VERSION_OK FALSE) - else () - set(VERSION_MSG "(found suitable version \"${VERSION}\", minimum required is \"${${_NAME}_FIND_VERSION}\")") - endif () - endif() - - else() - - # if the package was not found, but a version was given, add that to the output: - if(${_NAME}_FIND_VERSION_EXACT) - set(VERSION_MSG "(Required is exact version \"${${_NAME}_FIND_VERSION}\")") - else() - set(VERSION_MSG "(Required is at least version \"${${_NAME}_FIND_VERSION}\")") - endif() - - endif() - else () - if(VERSION) - set(VERSION_MSG "(found version \"${VERSION}\")") - endif() - endif () - - if(VERSION_OK) - set(DETAILS "${DETAILS}[v${VERSION}(${${_NAME}_FIND_VERSION})]") - else() - set(${_FOUND_VAR} FALSE) - endif() - - - # print the result: - if (${_FOUND_VAR}) - FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}") - else () - - if(FPHSA_CONFIG_MODE) - _FPHSA_HANDLE_FAILURE_CONFIG_MODE() - else() - if(NOT VERSION_OK) - _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE}: ${VERSION_MSG} (found ${${_FIRST_REQUIRED_VAR}})") - else() - _FPHSA_FAILURE_MESSAGE("${FPHSA_FAIL_MESSAGE} (missing: ${MISSING_VARS}) ${VERSION_MSG}") - endif() - endif() - - endif () - - set(${_FOUND_VAR} ${${_FOUND_VAR}} PARENT_SCOPE) - -endfunction() diff --git a/CMakeModules/FindPackageMessage.cmake b/CMakeModules/FindPackageMessage.cmake deleted file mode 100644 index b6a58e427d14..000000000000 --- a/CMakeModules/FindPackageMessage.cmake +++ /dev/null @@ -1,57 +0,0 @@ -#.rst: -# FindPackageMessage -# ------------------ -# -# -# -# FIND_PACKAGE_MESSAGE( "message for user" "find result details") -# -# This macro is intended to be used in FindXXX.cmake modules files. It -# will print a message once for each unique find result. This is useful -# for telling the user where a package was found. The first argument -# specifies the name (XXX) of the package. The second argument -# specifies the message to display. The third argument lists details -# about the find result so that if they change the message will be -# displayed again. The macro also obeys the QUIET argument to the -# find_package command. -# -# Example: -# -# :: -# -# if(X11_FOUND) -# FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}" -# "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") -# else() -# ... -# endif() - -#============================================================================= -# Copyright 2008-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -function(FIND_PACKAGE_MESSAGE pkg msg details) - # Avoid printing a message repeatedly for the same find result. - if(NOT ${pkg}_FIND_QUIETLY) - string(REGEX REPLACE "[\n]" "" details "${details}") - set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) - if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") - # The message has not yet been printed. - message(STATUS "${msg}") - - # Save the find details in the cache to avoid printing the same - # message again. - set("${DETAILS_VAR}" "${details}" - CACHE INTERNAL "Details about finding ${pkg}") - endif() - endif() -endfunction() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000000..9dc2ac90dc8e --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,74 @@ +{ + "version": 2, + "cmakeMinimumRequired": { + "major": 3, + "minor": 20, + "patch": 0 + }, + "configurePresets": [ + { + "name": "windows-tiles-sounds-x64-msvc", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "displayName": "Windows Tiles Sounds x64 MSVC", + "description": "Target Windows (64-bit) with the Visual Studio 2019 development environment.", + "generator": "Visual Studio 16 2019", + "cacheVariables": { + "CMAKE_PROJECT_INCLUDE_BEFORE": "${sourceDir}/build-scripts/${presetName}.cmake", + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/build-scripts/MSVC.cmake", + "VCPKG_TARGET_TRIPLET": "x64-windows-static", + "DYNAMIC_LINKING": "False", + "CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo;Release", + "CURSES": "False", "LOCALIZE": "True", "TILES": "True", "SOUND": "True", "LUA": "True", "TESTS": "True", + "CMAKE_INSTALL_MESSAGE": "NEVER" + } + }, + { + "name": "windows-tiles-sounds-x64-msvc-2022", + "inherits": ["windows-tiles-sounds-x64-msvc"], + "binaryDir": "${sourceDir}/out/build/${presetName}", + "displayName": "Windows Tiles Sounds x64 MSVC 2022", + "description": "Target Windows (64-bit) with the Visual Studio 2022 development environment.", + "generator": "Visual Studio 17 2022", + "cacheVariables": { + "CMAKE_PROJECT_INCLUDE_BEFORE": "${sourceDir}/build-scripts/windows-tiles-sounds-x64-msvc.cmake" + } + }, + { + "name": "linux-tiles-sounds-x64", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "displayName": "Linux Tiles Sounds x64", + "description": "Target Linux (64-bit) with the GCC development environment.", + "generator": "Ninja Multi-Config", + "cacheVariables": { + "DYNAMIC_LINKING": "True", "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CURSES": "False", "LOCALIZE": "True", "TILES": "True", "SOUND": "True", "LUA": "True", "TESTS": "False", + "CMAKE_INSTALL_MESSAGE": "NEVER" + } + }, + { + "name": "linux-tiles-sounds-x64-vcpkg", + "inherits": ["linux-tiles-sounds-x64"], + "displayName": "Linux Tiles Sounds x64 VCPKG", + "description": "Target Linux (64-bit) with the GCC development environment and VCPKG.", + "generator": "Ninja Multi-Config", + "environment": { + "VCPKG_ROOT": "/usr/local/vcpkg" + }, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "VCPKG_TARGET_TRIPLET": "x64-linux", + "VCPKG_MANIFEST_DIR": "${sourceDir}/msvc-full-features/" + } + } + ], + "buildPresets": [ + { + "name": "linux-tiles-sounds-x64", + "configurePreset": "linux-tiles-sounds-x64" + }, + { + "name": "linux-tiles-sounds-x64-vcpkg", + "configurePreset": "linux-tiles-sounds-x64-vcpkg" + } + ] +} diff --git a/Makefile b/Makefile index 14f76f4dd1f7..8e7402f4a7c3 100644 --- a/Makefile +++ b/Makefile @@ -882,7 +882,7 @@ ifeq ($(LTO), 1) endif endif -all: version $(CHECKS) $(TARGET) $(L10N) $(TESTS) +all: version prefix $(CHECKS) $(TARGET) $(L10N) $(TESTS) @ $(TARGET): $(OBJS) $(LUA_OBJS) @@ -913,7 +913,7 @@ else @$(AR) rcs $(BUILD_PREFIX)$(TARGET_NAME).a $(filter-out $(ODIR)/main.o $(ODIR)/messages.o,$(OBJS)) $(LUA_OBJS) endif -.PHONY: version +.PHONY: version prefix version: @( VERSION_STRING=$(VERSION) ; \ VERSION_AUTOMATIC=$(VERSION_AUTOMATIC) ; \ @@ -922,6 +922,12 @@ version: if [ "x$$VERSION_STRING" != "x$$OLDVERSION" ]; then printf '// NOLINT(cata-header-guard)\n#define VERSION "%s"\n' "$$VERSION_STRING" | tee $(SRC_DIR)/version.h ; fi \ ) +prefix: + @( PREFIX_STRING=$(PREFIX) ; \ + [ -e "$(SRC_DIR)/prefix.h" ] && OLDPREFIX=$$(grep PREFIX $(SRC_DIR)/PREFIX.h|cut -d '"' -f2) ; \ + if [ "x$$PREFIX_STRING" != "x$$OLDPREFIX" ]; then printf '// NOLINT(cata-header-guard)\n#define PREFIX "%s"\n' "$$PREFIX_STRING" | tee $(SRC_DIR)/prefix.h ; fi \ + ) + # Unconditionally create the object dir on every invocation. $(shell mkdir -p $(ODIR)) $(shell mkdir -p $(ODIRLUA)) @@ -1200,24 +1206,6 @@ 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/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/build-scripts/CMakeUserPresets.json.in b/build-scripts/CMakeUserPresets.json.in new file mode 100644 index 000000000000..47a6f1ba9ec5 --- /dev/null +++ b/build-scripts/CMakeUserPresets.json.in @@ -0,0 +1,14 @@ +{ + "version": 2, + "buildPresets": [ + { + "name": "@BUILD_PRESET_NAME@", + "configurePreset": "@CONFIGURE_PRESET@", + "environment": { + @_MSVC_DEVENV@ + }, + "configuration": "@CMAKE_BUILD_TYPE@", + "verbose": true + } + ] +} diff --git a/build-scripts/MSVC.cmake b/build-scripts/MSVC.cmake new file mode 100644 index 000000000000..7ad85eaee5c5 --- /dev/null +++ b/build-scripts/MSVC.cmake @@ -0,0 +1,89 @@ +#[=======================================================================[ + +MSVC +---- + +Toolchain file for Microsoft Visual C++. + +Used by CMakePresets.json -> "toolchainFile". + +C++ flags used by all builds: + +/MP cl.exe build with multiple processes +/utf-8 set source and execution character sets to UTF-8 +/bigobj increase # of sections in object files +/sdl- disable additional security checks +/FC full path in compiler messages +/Gd __cdecl +/GS- disable buffer security checks +/Gy Enable Function-Level Linking +/GF Eliminate Duplicate Strings +/wd4068 unknown pragma +/wd4146 negate unsigned +/wd4819 codepage? +/wd6237 short-circuit eval +/wd6319 a, b: unused a +/wd26444 unnamed objects +/wd26451 overflow +/wd26495 uninitialized member +/WX- (do not) Treat Warnings as Errors +/W1 Warning Level +/TP every file is a C++ file +/Zc:forScope Force Conformance in for Loop Scope +/Zc:inline Remove unreferenced COMDAT +/Zc:wchar_t wchar_t Is Native Type + +Additional C++ flags used by RelWithDebInfo builds: + +/Ob1 Inline Function Expansion (1 = only when marked as such) +/Oi Generate Intrinsic Functions + +Linker flags used by all builds: + +/OPT:REF remove unreferenced COMDATs +/OPT:ICF folds identical COMDATs +/DYNAMICBASE does this app really need ASLR ? +/NXCOMPAT same as above +No need to force /TLBID:1 because is default + +#]=======================================================================] + +# Path has changed, so this configure run will find cl.exe +set(CMAKE_C_COMPILER cl.exe) +set(CMAKE_CXX_COMPILER ${CMAKE_C_COMPILER}) +set(CMAKE_CXX_FLAGS_INIT "\ +/MP /utf-8 /bigobj /sdl- /FC /Gd /GS- /Gy /GF \ +/wd4068 /wd4146 /wd4819 /wd6237 /wd6319 /wd26444 /wd26451 /wd26495 /WX- /W1 \ +/TP /Zc:forScope /Zc:inline /Zc:wchar_t" +) +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT +"/Oi" +) +add_compile_definitions( + _SCL_SECURE_NO_WARNINGS + _CRT_SECURE_NO_WARNINGS + WIN32_LEAN_AND_MEAN + LOCALIZE + USE_VCPKG +) +add_link_options( + /OPT:REF + /OPT:ICF + /LTCG:OFF + /MANIFEST:NO + /INCREMENTAL:NO + /DYNAMICBASE + /NXCOMPAT +) + +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded") + +# Where is vcpkg.json ? +set(VCPKG_MANIFEST_DIR ${CMAKE_SOURCE_DIR}/msvc-full-features) + +set(VCPKG_ROOT "" CACHE PATH "Path to VCPKG installation") +if (NOT $ENV{VCPKG_ROOT} STREQUAL "") + include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) +elseif(NOT $CACHE{VCPKG_ROOT} STREQUAL "") + include($CACHE{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) +endif() diff --git a/build-scripts/VsDevCmd.cmake b/build-scripts/VsDevCmd.cmake new file mode 100644 index 000000000000..efdefa3bdb3a --- /dev/null +++ b/build-scripts/VsDevCmd.cmake @@ -0,0 +1,115 @@ +#[=======================================================================[ + +VsDevCmd.cmake +-------------- + +Run VsDevCmd.bat and extracts environment variables it changes. +Inject them into the global scope and _MSVC_DEVENV for +CMakeUserPreset.json at a later step. + +#]=======================================================================] + +if("$ENV{VSCMD_VER}" STREQUAL "") + # This cmake process is running under VsDevCmd.bat or VS IDE GUI + # Avoid to run VsDevCmd.bat twice + + if ("$ENV{DevEnvDir}" STREQUAL "") + # Use Community Edition when not specified + file(DOWNLOAD https://github.com/microsoft/vswhere/releases/download/3.0.3/vswhere.exe vswhere.exe + TLS_VERIFY ON + EXPECTED_HASH SHA1=8569081535767af53811f47c0e6abeabd695f8f4 + STATUS vswhere + ) + list(GET vswhere 0 vswhere) + if("0" EQUAL vswhere) + execute_process(COMMAND vswhere.exe -all -latest -property productPath + OUTPUT_VARIABLE DevEnvDir + OUTPUT_STRIP_TRAILING_WHITESPACE) + cmake_path(GET DevEnvDir PARENT_PATH DevEnvDir) + set(ENV{DevEnvDir} ${DevEnvDir}) + else() + set(ENV{DevEnvDir} "C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/") + endif() + endif() + + # Run VsDevCmd.bat and set all environment variables it changes + set(DevEnvDir $ENV{DevEnvDir}) + cmake_path(APPEND DevEnvDir ../Tools/VsDevCmd.bat OUTPUT_VARIABLE VSDEVCMD_BAT) + cmake_path(NATIVE_PATH VSDEVCMD_BAT NORMALIZE VSDEVCMD_BAT) + cmake_path(NATIVE_PATH DevEnvDir NORMALIZE DevEnvDir) + set(ENV{DevEnvDir} ${DevEnvDir}) + set(ENV{VSDEVCMD_BAT} \"${VSDEVCMD_BAT}\") + # Use short DOS path names because of spaces in path names + # See https://gitlab.kitware.com/cmake/cmake/-/issues/16321 + execute_process(COMMAND cmd /c for %A in (%VSDEVCMD_BAT%) do @echo %~sA + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE VSDEVCMD_BAT) + # Run it + execute_process(COMMAND cmd /c ${VSDEVCMD_BAT} -no_logo -arch=amd64 && set + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE _ENV) + # This list the environment variables we need. + # It is essentially a revised result of: + # comm -1 -3 <(sort before.txt) <(sort after.txt) |egrep -o '^[^=]+='" + set(_replace + ExtensionSdkDir= + Framework40Version= + FrameworkDIR64= + FrameworkDir= + FrameworkVersion64= + FrameworkVersion= + INCLUDE= + LIB= + LIBPATH= + NETFXSDKDir= + Path= + UCRTVersion= + UniversalCRTSdkDir= + VCIDEInstallDir= + VCINSTALLDIR= + VCToolsInstallDir= + VCToolsRedistDir= + VCToolsVersion= + VS170COMNTOOLS= + VSCMD_ARG_HOST_ARCH= + VSCMD_ARG_TGT_ARCH= + VSCMD_ARG_app_plat= + VSCMD_VER= + VSINSTALLDIR= + VisualStudioVersion= + WindowsLibPath= + WindowsSDKLibVersion= + WindowsSDKVersion= + WindowsSDK_ExecutablePath_x64= + WindowsSDK_ExecutablePath_x86= + WindowsSdkBinPath= + WindowsSdkDir= + WindowsSdkVerBinPath= + ) + string(REGEX REPLACE ";" "\\\\;" _ENV "${_ENV}") + string(REGEX MATCHALL "[^\n]+\n" _ENV "${_ENV}") + foreach(_env IN LISTS _ENV) + string(REGEX MATCH ^[^=]+ _key "${_env}") + string(REGEX MATCH =[^\n]+\n _value "${_env}") + # We may get some spurious output. Skip the line + if(NOT _value MATCHES ^=) + continue() + endif() + string(SUBSTRING "${_value}" 1 -1 _value) # Removes the = at begin + string(STRIP "${_value}" _value) # Remove the \r + list(FIND _replace ${_key}= _idx) + if(-1 EQUAL _idx) + continue() + endif() + list(REMOVE_AT _replace ${_idx}) + set(ENV{${_key}} "${_value}") + string(REPLACE \\ \\\\ _value "${_value}") + set(_json_entry "\"${_key}\": \"${_value}\"") + if("${_MSVC_DEVENV}" STREQUAL "") + string(APPEND _MSVC_DEVENV "${_json_entry}") + continue() + endif() + string(APPEND _MSVC_DEVENV ",\n${_json_entry}") + endforeach() # _ENV +endif() # VSCMD_VER + diff --git a/build-scripts/windows-tiles-sounds-x64-msvc.cmake b/build-scripts/windows-tiles-sounds-x64-msvc.cmake new file mode 100644 index 000000000000..6bb7d17cd9d7 --- /dev/null +++ b/build-scripts/windows-tiles-sounds-x64-msvc.cmake @@ -0,0 +1,38 @@ +#[=======================================================================[ + +windows-tiles-sounds-x64-msvc +----------------------------- + +Pre-load script for Microsoft Visual Studio builds. + +Used by CMakePresets.json -> "cacheVariables" -> "CMAKE_PROJECT_INCLUDE_BEFORE". + +When CMake does not run under VS environment, it sources the VsDevCmd.bat on it own. +It then writes CMakeUserPresets.json -> "buildPresets" -> "environment" + +#]=======================================================================] + +# Ref https://github.com/actions/virtual-environments/blob/win19/20220515.1/images/win/Windows2019-Readme.md#environment-variables +if (NOT $ENV{VCPKG_INSTALLATION_ROOT} STREQUAL "") + set(ENV{VCPKG_ROOT} $ENV{VCPKG_INSTALLATION_ROOT}) +endif() +# Ref https://vcpkg.io/en/docs/users/config-environment.html#vcpkg_root +if ("$ENV{VCPKG_ROOT}" STREQUAL "" AND WIN32) + set(ENV{VCPKG_ROOT} $CACHE{VCPKG_ROOT}) +endif() + +include(${CMAKE_SOURCE_DIR}/build-scripts/VsDevCmd.cmake) + +# It's fine to keep @_MSVC_DEVENV@ undefined +set(BUILD_PRESET_NAME "windows-tiles-sounds-x64-msvc") +set(CONFIGURE_PRESET "windows-tiles-sounds-x64-msvc") +configure_file( + ${CMAKE_SOURCE_DIR}/build-scripts/CMakeUserPresets.json.in + ${CMAKE_SOURCE_DIR}/CMakeUserPresets.json + @ONLY +) + +# Ninja is provided by Microsoft but not in the Path +if (CMAKE_GENERATOR MATCHES "^Ninja") + set(CMAKE_MAKE_PROGRAM $ENV{DevEnvDir}\\CommonExtensions\\Microsoft\\CMake\\Ninja\\ninja.exe CACHE PATH "") +endif() diff --git a/build-scripts/x64-windows-static.cmake b/build-scripts/x64-windows-static.cmake new file mode 100644 index 000000000000..66655f187771 --- /dev/null +++ b/build-scripts/x64-windows-static.cmake @@ -0,0 +1,5 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE static) + +set(VCPKG_BUILD_TYPE release) diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 6d3c79e04730..37ff7ac2519d 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -1,29 +1,23 @@ -# Cataclysm data files -cmake_minimum_required(VERSION 3.16) - set(CATACLYSM_DATA_DIRS - ${CMAKE_SOURCE_DIR}/data/font - ${CMAKE_SOURCE_DIR}/data/json - ${CMAKE_SOURCE_DIR}/data/mods - ${CMAKE_SOURCE_DIR}/data/names - ${CMAKE_SOURCE_DIR}/data/raw - ${CMAKE_SOURCE_DIR}/data/motd - ${CMAKE_SOURCE_DIR}/data/credits - ${CMAKE_SOURCE_DIR}/data/title - ${CMAKE_SOURCE_DIR}/data/help) + font + json + mods + names + raw + motd + credits + title + help) 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) + list(APPEND CATACLYSM_DATA_DIRS sound) 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 + changelog.txt + cataicon.ico) if (RELEASE) - install(DIRECTORY ${CATACLYSM_DATA_DIRS} DESTINATION ${DATA_PREFIX}) - install(FILES ${CATACLYSM_DATA_FILES} DESTINATION ${DATA_PREFIX}) + install(DIRECTORY ${CATACLYSM_DATA_DIRS} TYPE DATA) + install(FILES ${CATACLYSM_DATA_FILES} TYPE DATA) 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 5907f9519a6a..0b9ca80a40f2 100644 --- a/doc/src/content/docs/en/dev/guides/building/cmake.md +++ b/doc/src/content/docs/en/dev/guides/building/cmake.md @@ -4,7 +4,7 @@ title: CMake :::caution -CMake build is unofficial. +CMake build is work-in-progress. ::: @@ -128,7 +128,7 @@ $ ccmake .. $ cmake-gui .. ``` -## build for MSYS2 (MinGW) +## Build for MSYS2 (MinGW) **NOTE**: For development purposes it is preferred to use `MinGW Win64 Shell` or `MinGW Win32 Shell` instead of `MSYS2 Shell`. In other case, you will need to set `PATH` variable manually. @@ -199,7 +199,15 @@ Currently known depends (Maybe outdated use ldd.exe to correct it for Your syste - `smpeg2.dll` - `libvorbisfile-3.dll` -## build for Visual Studio / MSBuild +## Build for Visual Studio / MSBuild + +:::caution + +This guide is quite old and requires manual dependency management. + +For modern alternative, see [CMake Visual Studio build with vcpkg](./vs_cmake.md) + +::: CMake can generate `.sln` and `.vcxproj` files used either by Visual Studio itself or by MSBuild command line compiler (if you don't want a full fledged IDE) and have more "native" binaries than @@ -273,7 +281,7 @@ destination directory with `-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=` option (a Run the game. Should work. -# Build Options +## Build Options A full list of options supported by CMake, you may either run the `ccmake` or `cmake-gui` front-ends, or run `cmake` and open the generated CMakeCache.txt from the build directory in a text @@ -283,7 +291,7 @@ editor. $ cmake -DOPTION_NAME1=option_value1 [-DOPTION_NAME2=option_value2 [...]] ``` -## CMake specific options +### CMake specific options - CMAKE_BUILD_TYPE=`` @@ -298,7 +306,7 @@ passed in the command line. Installation prefix for binaries, resources, and documentation files. -## CataclysmBN specific options +### CataclysmBN specific options - CURSES=`` @@ -362,6 +370,14 @@ Override default Git binary name or path. Use UNIX system directories for game data in release build. +- USE_XDG_DIR=`` + +Use XDG directories for save and config files. + +- TESTS=`` + +Whether to build tests. + 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/doc/src/content/docs/en/dev/guides/building/vs_cmake.md b/doc/src/content/docs/en/dev/guides/building/vs_cmake.md new file mode 100644 index 000000000000..b1a0eb18e030 --- /dev/null +++ b/doc/src/content/docs/en/dev/guides/building/vs_cmake.md @@ -0,0 +1,204 @@ +--- +title: CMake + Visual Studio + Vcpkg +--- + +:::caution + +CMake build is work-in-progress. + +::: + +## Prerequisites + +- `cmake` >= 3.20.0 +- `vcpkg` from [vcpkg.io](https://vcpkg.io/en/getting-started.html) + +Note that starting from Visual Studio 2022 version 17.6, `vcpkg` is included with the distribution +and is available in the VS developer command prompt, so you don't have to install it separately. + +## Configure + +Configuration can be done using one of the presets in `CMakePresets.json`. They will all build the +code into the directory `out/build//`. + +### Terminal + +Ensure that `cmake` can find `vcpkg`. If it can't, it will complain about missing packages. You can +do this in one of the following ways: + +- For VS2022 users with preinstalled `vcpkg`, `vcpkg` should already be available if you're running + the VS developer command prompt and not the plain terminal +- Append `-DVCPKG_ROOT=C:\dev\vcpkg` (or whatever the path is) to any cmake configure commands +- Set the environment variable `VCPKG_ROOT` to the path to the vcpkg checkout +- Add the `VCPKG_ROOT` cache variable in `CMakePresets.json` with the appropriate path (not + recommended if you plan to work with the code later, git tracks this file) + +Run the command + +```sh +cmake --list-presets +``` + +It will show the presets available to you. The list changes based on the environment you are in. If +empty, the environment is not supported. + +Run the command + +```sh +cmake --preset +``` + +It will download all dependencies and generate build files, as long as `vcpkg` installation is +available. + +If you're using VS2022, be sure to select a preset with `2022` in its name, as presets without that +suffix will target VS2019. + +You can override any option by appending `-Doption=value` to this command, see +[Build options](./cmake.md/#build-options) in CMake guide. For example, you can disable building of +tests with `-DTESTS=OFF` if you don't care about them. + +### Visual Studio + +Open the game source folder in Visual Studio. + +Visual Studio should be able to recognize the folder as a CMake project, and may attempt to start +configuring it, which will most likely fail because it didn't use the proper preset. + +The Standard toolbar shows the presets in the `Configuration` drop-down box. Choose the proper one +(should contain `windows` and `msvc`), then from the main menu, select `Project` -> +`Configure Cache`. + +If you're using VS2022, be sure to select a preset with `2022` in its name, as presets without that +suffix are targeting VS2019. + +## Build + +### Terminal + +Run the command + +- `cmake --build --preset --config Release` + +You can replace `Release` with `Debug` to get a debug build, or `RelWithDebInfo` for a release build +with less optimizations but more debug information. + +### Visual Studio + +From the Standard toolbar's `Build Preset` drop-down menu select the build preset. From the main +menu, select `Build` -> `Build All`. + +You can also select between `Release`, `Debug` and `RelWithDebInfo` builds, though depending on UI +layout the drop-down menu for this may be hidden behind the overflow button. + +## Translations + +Translations are optional and require `msgfmt` binary from `gettext` package; `vcpkg` should install +it automatically. + +### Terminal + +Run the command + +- `cmake --build --preset --target translations_compile` + +### Visual Studio + +Visual Studio should have built the translations in the previous step. If it did not, open Solution +Explorer, switch it into CMake Targets mode (can be done with right click), then right click on +`translations_compile` target -> `Build translations_compile`. + +## Install + +:::caution + +Install is still considered WIP and has received little testing. + +::: + +### Visual Studio + +From the main menu, select `Build` -> `Install CataclysmBN` + +### Terminal + +Run the command + +- `cmake --install out/build// --config Release` + +Replace `Release` with your chosen build type. + +## Run + +The game and test executables will both be available in `.\Release\` folder (folder name matches +build type, so for other build types you'll get other folder names). + +You can run them manually from the terminal, as long as you do it from the project's top directory +as by default the game expects data files to be in current path. + +For running and debugging from Visual Studio, it's recommended to open the generated VS solution +located at `out\build\\CataclysmBN.sln` (it will be there regardless of whether you've +completed previous steps in IDE or terminal) and do any further work with it instead. + +Alternatively, it's possible to stay in the "Open Folder" mode, but then you'll have to customize +launch configuration for the game executable (and tests), and there may be other yet undiscovered +side effects. + +### Terminal + +To start the game, run + +- `.\Release\cataclysm-tiles.exe` + +To execute tests, run + +- `.\Release\cata_test-tiles.exe` + +### Visual Studio (Option 1, Recommended) + +Close Visual Studio, then navigate to `out\build\\` and open `CataclysmBN.sln`. Set +`cataclysm-tiles` as Startup Project (can be done with right click from Solution Explorer), and +you'll be able to run and debug the game executable without additional issues. It will already be +preconfigured to look for the data files in the top project directory. + +To run tests, switch the Startup Project to `cata_test-tiles`. + +### Visual Studio (Option 2) + +Due to how Visual Studio handles CMake projects, it's impossible to specify the working directory +for the executable while VS is in the "Open Folder" mode. This StackOverflow answer explains it +nicely: https://stackoverflow.com/a/62309569 Fortunately, VS allows customizing exe launch options +on individual basis. + +Open solution explorer and switch it into CMake Targets mode if you haven't already (can be done +with a right click). There, right click on the `cataclysm-tiles` target -> +`Add Debug Configuration`. Visual Studio will open launch configurations file for this project, with +new configuration for the `cataclysm-tiles` target. Add the following line: + +``` +"currentDir": "${workspaceRoot}", +``` + +to the config and save the file. + +The final result should look something like this: + +```json +{ + "version": "0.2.1", + "defaults": {}, + "configurations": [ + { + "currentDir": "${workspaceRoot}", + "type": "default", + "project": "CMakeLists.txt", + "projectTarget": "cataclysm-tiles.exe (\\Debug\\cataclysm-tiles.exe)", + "name": "cataclysm-tiles.exe (\\Debug\\cataclysm-tiles.exe)" + } + ] +} +``` + +Now, you should be able to run and debug the game executable from inside Visual Studio. + +If you'd like to run tests, repeat this process for the `cata_test-tiles` target. diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt index ef5cf2c0ceff..b5ec789110f2 100644 --- a/lang/CMakeLists.txt +++ b/lang/CMakeLists.txt @@ -5,15 +5,12 @@ if (LANGUAGES STREQUAL none) return() endif () -find_package(Gettext) - -if (NOT GETTEXT_FOUND) - message( - FATAL_ERROR +if(NOT GETTEXT_MSGFMT_EXECUTABLE) + 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 () +endif() if (LANGUAGES STREQUAL all) set(LANGUAGES "") @@ -27,7 +24,7 @@ if (LANGUAGES STREQUAL all) endif () foreach (LANG ${LANGUAGES}) - message(STATUS "Add translation for ${LANG}: ${LANG}.po") + message(VERBOSE "Add translation for ${LANG}: ${LANG}.po") endforeach () message("\n") @@ -59,5 +56,5 @@ foreach (LANG ${LANGUAGES}) ${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}) + # install(DIRECTORY ${CMAKE_SOURCE_DIR}/lang/mo/${LANG} DESTINATION ${DATA_PREFIX}) endforeach () diff --git a/msvc-full-features/stdafx.h b/msvc-full-features/stdafx.h index e6eff8ed2115..dadbfff9273b 100644 --- a/msvc-full-features/stdafx.h +++ b/msvc-full-features/stdafx.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -19,13 +18,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include diff --git a/msvc-full-features/vcpkg.json b/msvc-full-features/vcpkg.json index 90151953352f..da73cbcffe94 100644 --- a/msvc-full-features/vcpkg.json +++ b/msvc-full-features/vcpkg.json @@ -3,12 +3,20 @@ "version-string": "experimental", "dependencies": [ "sdl2", - "sdl2-image", + { + "name": "sdl2-image", + "features": [ "libjpeg-turbo" ] + }, { "name": "sdl2-mixer", - "features": [ "libflac", "mpg123", "libmodplug", "libvorbis" ] + "features": [ "libflac", "mpg123", "libmodplug" ] }, "sdl2-ttf" ], - "builtin-baseline": "a7b6122f6b6504d16d96117336a0562693579933" + "builtin-baseline": "c9aba300923c8ec0ab190e2bff23085209925c97", + "vcpkg-configuration": { + "overlay-ports": [ + "../.github/vcpkg_ports" + ] + } } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 843e9fef3317..05c0e934098c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,3 @@ -# Cataclysm BN client -cmake_minimum_required(VERSION 3.16) - -include(SetupLibrary.cmake) - 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) @@ -14,9 +9,8 @@ list(REMOVE_ITEM CATACLYSM_BN_SOURCES ${MAIN_CPP} ${MESSAGES_CPP}) file(GLOB CATACLYSM_BN_HEADERS ${CMAKE_SOURCE_DIR}/src/*.h) if (LUA) - file(GLOB LUA_C_SOURCES ${CMAKE_SOURCE_DIR}/src/lua/*.c) -else () - set(LUA_C_SOURCES "") + add_subdirectory(lua) + add_subdirectory(sol) endif () # Get GIT version strings @@ -27,77 +21,180 @@ add_custom_target( 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 + 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) - setup_library(cataclysm-tiles-common) + add_library( + cataclysm-tiles-common OBJECT + ${CATACLYSM_BN_SOURCES} + ${CATACLYSM_BN_HEADERS}) + target_include_directories(cataclysm-tiles-common INTERFACE ${CMAKE_SOURCE_DIR}/src) if (WIN32) add_definitions(-DUSE_WINMAIN) - add_executable(cataclysm-tiles WIN32 ${MAIN_CPP} ${MESSAGES_CPP} ${RESOURCE_RC}) + add_executable( + cataclysm-tiles WIN32 + ${MAIN_CPP} + ${MESSAGES_CPP} + ${RESOURCE_RC}) else () - add_executable(cataclysm-tiles ${MAIN_CPP} ${MESSAGES_CPP}) + add_executable(cataclysm-tiles + ${MAIN_CPP} + ${MESSAGES_CPP}) endif () - target_link_libraries(cataclysm-tiles cataclysm-tiles-common) - target_compile_definitions(cataclysm-tiles-common PUBLIC TILES) + if (LUA) + target_compile_definitions(cataclysm-tiles-common PUBLIC LUA) + target_link_libraries(cataclysm-tiles-common PUBLIC libsol) + endif () - 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}) + add_dependencies(cataclysm-tiles-common get_version) + + target_link_libraries(cataclysm-tiles PRIVATE cataclysm-tiles-common) + target_compile_definitions(cataclysm-tiles-common PUBLIC TILES ) + + if (NOT "${CMAKE_EXPORT_COMPILE_COMMANDS}") + target_precompile_headers(cataclysm-tiles-common PRIVATE + ${CMAKE_SOURCE_DIR}/pch/main-pch.hpp) + endif () + + if (CMAKE_USE_PTHREADS_INIT) + target_compile_options(cataclysm-tiles-common PUBLIC "-pthread") 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 (CMAKE_THREAD_LIBS_INIT) + target_link_libraries(cataclysm-tiles-common PUBLIC ${CMAKE_THREAD_LIBS_INIT}) + endif () + if (NOT DYNAMIC_LINKING) + target_link_libraries(cataclysm-tiles-common PUBLIC + SDL2::SDL2-static + SDL2_image::SDL2_image-static + SDL2_ttf::SDL2_ttf-static + ) + else() + target_link_libraries(cataclysm-tiles-common PUBLIC + SDL2::SDL2 + SDL2_image::SDL2_image + SDL2_ttf::SDL2_ttf + ) + endif () 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}) - target_link_libraries(cataclysm-tiles-common ${VORBIS_LIBRARY}) - 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}) + if (NOT DYNAMIC_LINKING) + target_link_libraries(cataclysm-tiles-common PUBLIC + SDL2_mixer::SDL2_mixer-static + ) + else() + target_link_libraries(cataclysm-tiles-common PUBLIC + SDL2_mixer::SDL2_mixer + ) + endif() + add_definitions(-DSDL_SOUND) + endif () + + if (WIN32) + # Global settings for Windows targets (at end) + target_link_libraries(cataclysm-tiles-common PUBLIC gdi32.lib) + target_link_libraries(cataclysm-tiles-common PUBLIC winmm.lib) + target_link_libraries(cataclysm-tiles-common PUBLIC imm32.lib) + target_link_libraries(cataclysm-tiles-common PUBLIC ole32.lib) + target_link_libraries(cataclysm-tiles-common PUBLIC oleaut32.lib) + target_link_libraries(cataclysm-tiles-common PUBLIC version.lib) + target_link_libraries(cataclysm-tiles-common PUBLIC setupapi.lib) + if (SOUND) + target_link_libraries(cataclysm-tiles-common PUBLIC shlwapi.lib) + endif() + if (BACKTRACE) + target_link_libraries(cataclysm-tiles-common PUBLIC dbghelp.lib) + if (LIBBACKTRACE) + target_link_libraries(cataclysm-tiles-common PUBLIC backtrace) + endif () + endif () + elseif (APPLE) + target_link_libraries(cataclysm-tiles-common PUBLIC "-framework CoreFoundation") + endif () + + if (LIBBACKTRACE) + target_link_libraries(cataclysm-tiles-common PUBLIC backtrace) endif () if (RELEASE) - install(TARGETS cataclysm-tiles DESTINATION ${BIN_PREFIX}) + install(TARGETS cataclysm-tiles RUNTIME) endif () + set_target_properties( cataclysm-tiles PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" ) endif () # Build curses version if requested if (CURSES) - setup_library(cataclysm-common) + add_library(cataclysm-common OBJECT + ${CATACLYSM_BN_SOURCES} + ${CATACLYSM_BN_HEADERS}) + target_include_directories(cataclysm-common INTERFACE ${CMAKE_SOURCE_DIR}/src) + + if (NOT "${CMAKE_EXPORT_COMPILE_COMMANDS}") + 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}) + add_executable(cataclysm + ${MAIN_CPP} + ${MESSAGES_CPP} + ${RESOURCE_RC}) else () - add_executable(cataclysm ${MAIN_CPP} ${MESSAGES_CPP}) + add_executable(cataclysm + ${MAIN_CPP} + ${MESSAGES_CPP}) endif () - target_link_libraries(cataclysm cataclysm-common) + if (LUA) + target_compile_definitions(cataclysm-common PUBLIC LUA) + target_link_libraries(cataclysm-common PUBLIC libsol) + endif () + + add_dependencies(cataclysm-common get_version) + target_link_libraries(cataclysm PRIVATE cataclysm-common) target_include_directories(cataclysm-common PUBLIC ${CURSES_INCLUDE_DIR}) - target_link_libraries(cataclysm-common ${CURSES_LIBRARIES}) + target_link_libraries(cataclysm-common PUBLIC ${CURSES_LIBRARIES}) - if (RELEASE) - install(TARGETS cataclysm DESTINATION ${BIN_PREFIX}) + if (CMAKE_USE_PTHREADS_INIT) + target_compile_options(cataclysm-common PUBLIC "-pthread") + endif () + + if (CMAKE_THREAD_LIBS_INIT) + target_link_libraries(cataclysm-common PUBLIC ${CMAKE_THREAD_LIBS_INIT}) + endif () + + if (WIN32) + # Global settings for Windows targets (at end) + target_link_libraries(cataclysm-common PUBLIC gdi32.lib) + target_link_libraries(cataclysm-common PUBLIC winmm.lib) + target_link_libraries(cataclysm-common PUBLIC imm32.lib) + target_link_libraries(cataclysm-common PUBLIC ole32.lib) + target_link_libraries(cataclysm-common PUBLIC oleaut32.lib) + target_link_libraries(cataclysm-common PUBLIC version.lib) + if (BACKTRACE) + target_link_libraries(cataclysm-common PUBLIC dbghelp.lib) + endif () + elseif (APPLE) + target_link_libraries(cataclysm-common PUBLIC "-framework CoreFoundation") endif () + if (LIBBACKTRACE) + target_link_libraries(cataclysm-common PUBLIC backtrace) + endif () + + if (RELEASE) + install(TARGETS cataclysm RUNTIME) + endif () endif () if (MINGW AND NOT RELEASE) @@ -106,28 +203,31 @@ if (MINGW AND NOT RELEASE) # probably it will fail if you run it :) # GCC-specific libraries - find_library(RuntimeLib_GCC_S_DW2_1 "gcc_s_dw2-1") - find_library(RuntimeLib_STDC_PP_6 "stdc++-6") + 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) # SDL2 can have a varius deps. Here you are the MSYS2 ones... - find_library(RuntimeLib_SDL2 "SDL2") - find_library(RuntimeLib_SDL2_IMG "SDL2_image") - find_library(RuntimeLib_png "libpng16-16") - find_library(RuntimeLib_jpeg "libjpeg-8") - find_library(RuntimeLib_jbig "libjbig-0") - find_library(RuntimeLib_tiff "libtiff-5") - find_library(RuntimeLib_webp "libwebp-5") - find_library(RuntimeLib_lzma "liblzma-5") - find_library(RuntimeLib_bz2 "libbz2-1") - find_library(RuntimeLib_zlib "zlib1") - find_library(RuntimeLib_hb "libharfbuzz-0") - find_library(RuntimeLib_SDL2_TTF "SDL2_ttf") - find_library(RuntimeLib_ft "libfreetype-6") - find_library(RuntimeLib_glib "libglib-2.0-0") + find_library(RuntimeLib_SDL2 "SDL2") + find_library(RuntimeLib_SDL2_IMG "SDL2_image") + find_library(RuntimeLib_png "libpng16-16") + find_library(RuntimeLib_jpeg "libjpeg-8") + find_library(RuntimeLib_jbig "libjbig-0") + find_library(RuntimeLib_tiff "libtiff-5") + find_library(RuntimeLib_webp "libwebp-5") + find_library(RuntimeLib_lzma "liblzma-5") + find_library(RuntimeLib_bz2 "libbz2-1") + find_library(RuntimeLib_zlib "zlib1") + find_library(RuntimeLib_hb "libharfbuzz-0") + find_library(RuntimeLib_SDL2_TTF "SDL2_ttf") + find_library(RuntimeLib_ft "libfreetype-6") + find_library(RuntimeLib_glib "libglib-2.0-0") set(RuntimeLib_SDL ${RuntimeLib_SDL2} ${RuntimeLib_SDL2_IMG} @@ -145,20 +245,20 @@ if (MINGW AND NOT RELEASE) ${RuntimeLib_glib}) if (SOUND) - find_library(RuntimeLib_SDL_SND "SDL2_mixer") - find_library(RuntimeLib_flak "libFLAC-8") - find_library(RuntimeLib_ogg "libogg-0") - find_library(RuntimeLib_flu "libfluidsynth-1") - find_library(RuntimeLib_port "libportaudio-2") - find_library(RuntimeLib_snd "libsndfile-1") - find_library(RuntimeLib_vorb "libvorbis-0") - find_library(RuntimeLib_vorb_enc "libvorbisenc-2") - find_library(RuntimeLib_vorb_f "libvorbisfile-3") - find_library(RuntimeLib_mod "libmodplug-1") - find_library(RuntimeLib_mpeg "smpeg2") + find_library(RuntimeLib_SDL_SND "SDL2_mixer") + find_library(RuntimeLib_flac "libFLAC-8") + find_library(RuntimeLib_ogg "libogg-0") + find_library(RuntimeLib_flu "libfluidsynth-1") + find_library(RuntimeLib_port "libportaudio-2") + find_library(RuntimeLib_snd "libsndfile-1") + find_library(RuntimeLib_vorb "libvorbis-0") + find_library(RuntimeLib_vorb_enc "libvorbisenc-2") + find_library(RuntimeLib_vorb_f "libvorbisfile-3") + find_library(RuntimeLib_mod "libmodplug-1") + find_library(RuntimeLib_mpeg "smpeg2") set(RuntimeLib_SDL_SOUND ${RuntimeLib_SDL_SND} - ${RuntimeLib_flak} + ${RuntimeLib_flac} ${RuntimeLib_ogg} ${RuntimeLib_flu} ${RuntimeLib_port} @@ -170,9 +270,8 @@ if (MINGW AND NOT RELEASE) ${RuntimeLib_mpeg}) endif () endif () - - install(FILES ${RuntimeLib_GCC_ALL} ${RuntimeLib_SDL} ${RuntimeLib_SDL_SOUND} - DESTINATION ${BIN_PREFIX}) + install(FILES ${RuntimeLib_GCC_ALL} + ${RuntimeLib_SDL} + ${RuntimeLib_SDL_SOUND} + TYPE BIN) endif () - -# vim:noet diff --git a/src/SetupLibrary.cmake b/src/SetupLibrary.cmake deleted file mode 100644 index 1aa47165f4d4..000000000000 --- a/src/SetupLibrary.cmake +++ /dev/null @@ -1,47 +0,0 @@ -# SPDX-License-Identifier: GPL-3.0-only -# Author: 2023 scarf - -function (setup_library TARGET) - - add_library(${TARGET} OBJECT ${CATACLYSM_BN_SOURCES} ${CATACLYSM_BN_HEADERS} ${LUA_C_SOURCES}) - target_include_directories(${TARGET} INTERFACE ${CMAKE_SOURCE_DIR}/src) - - add_dependencies(${TARGET} get_version) - - if (USE_PCH_HEADER) - target_precompile_headers(${TARGET} PRIVATE ${CMAKE_SOURCE_DIR}/pch/main-pch.hpp) - endif () - - if (CMAKE_USE_PTHREADS_INIT) - target_compile_options(${TARGET} PUBLIC "-pthread") - endif () - - if (CMAKE_THREAD_LIBS_INIT) - target_link_libraries(${TARGET} ${CMAKE_THREAD_LIBS_INIT}) - endif () - - if (LUA) - target_compile_definitions(${TARGET} PUBLIC LUA) - target_include_directories(${TARGET} PUBLIC ${CMAKE_SOURCE_DIR}/src) - target_include_directories(${TARGET} PUBLIC ${CMAKE_SOURCE_DIR}/src/lua) - endif () - - if (WIN32) - # Global settings for Windows targets (at end) - target_link_libraries(${TARGET} gdi32.lib) - target_link_libraries(${TARGET} winmm.lib) - target_link_libraries(${TARGET} imm32.lib) - target_link_libraries(${TARGET} ole32.lib) - target_link_libraries(${TARGET} oleaut32.lib) - target_link_libraries(${TARGET} version.lib) - - if (BACKTRACE) - target_link_libraries(${TARGET} dbghelp.lib) - endif () - endif () - - if (LIBBACKTRACE) - target_link_libraries(${TARGET} backtrace) - endif () - -endfunction () diff --git a/src/filesystem.cpp b/src/filesystem.cpp index c23474b4c666..4595fdd2efb9 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -82,7 +82,19 @@ bool file_exist( const std::string &path ) } #endif +std::string as_norm_dir( const std::string &path ) +{ + std::filesystem::path dir = std::filesystem::u8path( path ) / std::filesystem::path{}; + std::filesystem::path norm = dir.lexically_normal(); + std::string ret = norm.generic_u8string(); + if( "." == ret ) { + ret = "./"; // TODO Change the many places that use strings instead of paths + } + return ret; +} + #if defined(_WIN32) + bool remove_file( const std::string &path ) { return DeleteFileW( utf8_to_wstr( path ).c_str() ) != 0; diff --git a/src/filesystem.h b/src/filesystem.h index 86c5f6a7fb55..f1fe675f842f 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -60,6 +60,9 @@ std::string get_pid_string(); */ std::string read_entire_file( const std::string &path ); +/** Force 'path' to be a normalized directory */ +std::string as_norm_dir( const std::string &path ); + namespace cata_files { const char *eol(); diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt new file mode 100644 index 000000000000..99128063f29e --- /dev/null +++ b/src/lua/CMakeLists.txt @@ -0,0 +1,15 @@ +file(GLOB LUA_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) +file(GLOB LUA_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h) +list(APPEND LUA_SOURCES ${LUA_HEADERS}) + +# We compile Lua C sources with C++ compiler so we don't have to bother +# with defining 2 different compilers. +set_source_files_properties(${LUA_SOURCES} PROPERTIES LANGUAGE CXX) + +add_library(liblua ${LUA_SOURCES}) +target_include_directories(liblua SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +set_target_properties(liblua PROPERTIES LINKER_LANGUAGE CXX) + +# Silence all errors. It's C code being compiled as C++, there're lots of them. +target_compile_options(liblua PRIVATE -w) diff --git a/src/main.cpp b/src/main.cpp index 739a52d924e9..9ff6c64d59c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #if defined(_WIN32) # include "platform_win.h" @@ -44,6 +45,11 @@ #include "type_id.h" #include "ui_manager.h" +#if defined(PREFIX) +# undef PREFIX +# include "prefix.h" +#endif + class ui_adaptor; #if defined(TILES) @@ -207,17 +213,12 @@ int main( int argc, char *argv[] ) // On Android first launch, we copy all data files from the APK into the app's writeable folder so std::io stuff works. // Use the external storage so it's publicly modifiable data (so users can mess with installed data, save games etc.) std::string external_storage_path( SDL_AndroidGetExternalStoragePath() ); - if( external_storage_path.back() != '/' ) { - external_storage_path += '/'; - } PATH_INFO::init_base_path( external_storage_path ); #else // Set default file paths #if defined(PREFIX) -#define Q(STR) #STR -#define QUOTE(STR) Q(STR) - PATH_INFO::init_base_path( std::string( QUOTE( PREFIX ) ) ); + PATH_INFO::init_base_path( std::string( PREFIX ) ); #else PATH_INFO::init_base_path( "" ); #endif @@ -229,7 +230,7 @@ int main( int argc, char *argv[] ) # if defined(USE_HOME_DIR) || defined(USE_XDG_DIR) PATH_INFO::init_user_dir( "" ); # else - PATH_INFO::init_user_dir( "./" ); + PATH_INFO::init_user_dir( "." ); # endif #endif PATH_INFO::set_standard_filenames(); @@ -600,23 +601,29 @@ int main( int argc, char *argv[] ) } } + std::string current_path = std::filesystem::current_path().string(); + if( !dir_exist( PATH_INFO::datadir() ) ) { std::string msg = string_format( "Can't find directory \"%s\"\n" + "Current path: \"%s\"\n" "Please ensure the current working directory is correct.\n" "Perhaps you meant to start \"cataclysm-launcher\"?\n", - PATH_INFO::datadir().c_str() + PATH_INFO::datadir(), + current_path ); report_fatal_error( msg ); exit( 1 ); } - const auto check_dir_good = []( const std::string & dir ) { + const auto check_dir_good = [¤t_path]( const std::string & dir ) { if( !assure_dir_exist( dir ) ) { std::string msg = string_format( "Can't open or create \"%s\"\n" + "Current path: \"%s\"\n" "Please ensure you have write permission.\n", - dir.c_str() + dir.c_str(), + current_path ); report_fatal_error( msg ); exit( 1 ); @@ -624,8 +631,10 @@ int main( int argc, char *argv[] ) if( !can_write_to_dir( dir ) ) { std::string msg = string_format( "Can't write to \"%s\"\n" + "Current path: \"%s\"\n" "Please ensure you have write permission and free storage space.\n", - dir.c_str() + dir.c_str(), + current_path ); report_fatal_error( msg ); exit( 1 ); diff --git a/src/path_info.cpp b/src/path_info.cpp index 88bbeea7e562..86c27b2fc255 100644 --- a/src/path_info.cpp +++ b/src/path_info.cpp @@ -38,14 +38,7 @@ static std::string memorialdir_value; void PATH_INFO::init_base_path( std::string path ) { - if( !path.empty() ) { - const char ch = path.back(); - if( ch != '/' && ch != '\\' ) { - path.push_back( '/' ); - } - } - - base_path_value = path; + base_path_value = as_norm_dir( path ); } void PATH_INFO::init_user_dir( std::string dir ) @@ -72,7 +65,7 @@ void PATH_INFO::init_user_dir( std::string dir ) #endif } - user_dir_value = dir; + user_dir_value = as_norm_dir( dir ); } void PATH_INFO::set_standard_filenames() diff --git a/src/prefix.h.in b/src/prefix.h.in new file mode 100644 index 000000000000..e3f3bdbaa9cd --- /dev/null +++ b/src/prefix.h.in @@ -0,0 +1 @@ +#define PREFIX "@CMAKE_INSTALL_PREFIX@" diff --git a/src/sol/CMakeLists.txt b/src/sol/CMakeLists.txt new file mode 100644 index 000000000000..c0b9bad9c2f9 --- /dev/null +++ b/src/sol/CMakeLists.txt @@ -0,0 +1,7 @@ +file(GLOB SOL_SOURCES config.hpp forward.hpp sol.hpp) + +add_library(libsol INTERFACE ${SOL_SOURCES}) +# HACK: "/.." here is needed to avoid custom logic in Makefile. +# Get rid of it once we get rid of Make, and move sol sources into subdirectory. +target_include_directories(libsol SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/..) +target_link_libraries(libsol INTERFACE liblua) diff --git a/src/sol/config.hpp b/src/sol/config.hpp index 823a0e939527..fe88df36b2ca 100644 --- a/src/sol/config.hpp +++ b/src/sol/config.hpp @@ -52,6 +52,10 @@ the build system, or the command line options of your compiler. // We compile Lua parts with C++ compiler, so sol doesn't need to use extern "C" #define SOL_BUILD_CXX_MODE 1 +// Ugly hack so non-CMake builds work +#if defined(CMAKE) +# define SOL_USE_CXX_LUA 1 +#endif // Be helpful and verbose, even at the cost of speed #define SOL_ALL_SAFETIES_ON 1 diff --git a/src/string_id.h b/src/string_id.h index 096145f277bc..01b3fd8e693d 100644 --- a/src/string_id.h +++ b/src/string_id.h @@ -2,6 +2,7 @@ #ifndef CATA_SRC_STRING_ID_H #define CATA_SRC_STRING_ID_H +#include #include #include #include diff --git a/src/vpart_range.h b/src/vpart_range.h index 718b50038ef4..14911f0eeb94 100644 --- a/src/vpart_range.h +++ b/src/vpart_range.h @@ -85,6 +85,8 @@ namespace std template struct iterator_traits> { using difference_type = size_t; using value_type = vpart_reference; + using pointer = vpart_reference*; + using reference = vpart_reference&; // TODO: maybe change into random access iterator? This requires adding // more operators to the iterator, which may not be efficient. using iterator_category = std::forward_iterator_tag; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3ec9fb3ac5b5..cb21182661c1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,32 +1,42 @@ if (BUILD_TESTING) - file(GLOB CATACLYSM_BN_TEST_SOURCES ${CMAKE_SOURCE_DIR}/tests/*.cpp) + file(GLOB CATACLYSM_BN_TEST_SOURCES + ${CMAKE_SOURCE_DIR}/tests/*.cpp) # Enabling benchmarks add_definitions(-DCATCH_CONFIG_ENABLE_BENCHMARKING) + # TODO: build MO files required for tests + + # This needs to include catch.h with different macro switch + set_source_files_properties(test_main.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON) + 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) + target_link_libraries(cata_test-tiles PRIVATE cataclysm-tiles-common) add_test( NAME test-tiles COMMAND sh -c "$ --rng-seed time" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + + if (NOT "${CMAKE_EXPORT_COMPILE_COMMANDS}") + target_precompile_headers(cata_test-tiles PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/pch/tests-pch.hpp) + endif () + + set_target_properties( cata_test-tiles PROPERTIES VS_DEBUGGER_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 () - target_link_libraries(cata_test cataclysm-common) + target_link_libraries(cata_test PRIVATE cataclysm-common) add_test( NAME test COMMAND sh -c "$ --rng-seed time" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + + if (NOT "${CMAKE_EXPORT_COMPILE_COMMANDS}") + target_precompile_headers(cata_test PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/pch/tests-pch.hpp) + endif () endif () endif () - -# vim:noet diff --git a/tests/creature_test.cpp b/tests/creature_test.cpp index 3d11cb3708e6..4700b7600003 100644 --- a/tests/creature_test.cpp +++ b/tests/creature_test.cpp @@ -14,7 +14,7 @@ namespace { -using Weights = std::map; +using Weights = std::map; struct Expected { Weights base, max; }; @@ -23,12 +23,12 @@ struct Expected { const auto expected_smaller = Expected { Weights{ - { bp_torso, 20 }, { bp_head, 0 }, { bp_eyes, 0 }, { bp_mouth, 0 }, { bp_arm_l, 15 }, { bp_arm_r, 15 }, - { bp_hand_l, 0 }, { bp_hand_r, 0 }, { bp_leg_l, 25 }, { bp_leg_r, 25 }, { bp_foot_l, 0 }, { bp_foot_r, 0 } + { bp_torso, 20.0 }, { bp_head, 0.0 }, { bp_eyes, 0.0 }, { bp_mouth, 0.0 }, { bp_arm_l, 15.0 }, { bp_arm_r, 15.0 }, + { bp_hand_l, 0.0 }, { bp_hand_r, 0.0 }, { bp_leg_l, 25.0 }, { bp_leg_r, 25.0 }, { bp_foot_l, 0.0 }, { bp_foot_r, 0.0 } }, Weights{ - { bp_torso, 4960 }, { bp_head, 0 }, { bp_eyes, 0 }, { bp_mouth, 0 }, { bp_arm_l, 1143 }, { bp_arm_r, 1186 }, - { bp_hand_l, 0 }, { bp_hand_r, 0 }, { bp_leg_l, 3844 }, { bp_leg_r, 3867 }, { bp_foot_l, 0 }, { bp_foot_r, 0 } + { bp_torso, 4960.0 }, { bp_head, 0.0 }, { bp_eyes, 0.0 }, { bp_mouth, 0.0 }, { bp_arm_l, 1143.0 }, { bp_arm_r, 1186.0 }, + { bp_hand_l, 0.0 }, { bp_hand_r, 0.0 }, { bp_leg_l, 3844.0 }, { bp_leg_r, 3867.0 }, { bp_foot_l, 0.0 }, { bp_foot_r, 0.0 } } }; @@ -36,24 +36,24 @@ const auto expected_smaller = Expected const auto expected_same = Expected { Weights{ - { bp_torso, 33.33 }, { bp_head, 2.33 }, { bp_eyes, 0.33 }, { bp_mouth, 0 }, { bp_arm_l, 20 }, { bp_arm_r, 20 }, - { bp_hand_l, 0 }, { bp_hand_r, 0 }, { bp_leg_l, 12 }, { bp_leg_r, 12 }, { bp_foot_l, 0 }, { bp_foot_r, 0 } + { bp_torso, 33.33 }, { bp_head, 2.33 }, { bp_eyes, 0.33 }, { bp_mouth, 0.0 }, { bp_arm_l, 20.0 }, { bp_arm_r, 20.0 }, + { bp_hand_l, 0.0 }, { bp_hand_r, 0.0 }, { bp_leg_l, 12.0 }, { bp_leg_r, 12.0 }, { bp_foot_l, 0.0 }, { bp_foot_r, 0.0 } }, Weights{ { bp_torso, 6513 }, { bp_head, 2928 }, { bp_eyes, 150 }, { bp_mouth, 0 }, { bp_arm_l, 1224 }, { bp_arm_r, 1235 }, - { bp_hand_l, 0 }, { bp_hand_r, 0 }, { bp_leg_l, 1458 }, { bp_leg_r, 1492 }, { bp_foot_l, 0 }, { bp_foot_r, 0 } + { bp_hand_l, 0.0 }, { bp_hand_r, 0.0 }, { bp_leg_l, 1458.0 }, { bp_leg_r, 1492.0 }, { bp_foot_l, 0.0 }, { bp_foot_r, 0.0 } } }; const auto expected_larger = Expected { Weights{ - { bp_torso, 36.57 }, { bp_head, 5.71 }, { bp_eyes, 0.57 }, { bp_mouth, 0 }, { bp_arm_l, 22.86 }, { bp_arm_r, 22.86 }, - { bp_hand_l, 0 }, { bp_hand_r, 0 }, { bp_leg_l, 5.71 }, { bp_leg_r, 5.71 }, { bp_foot_l, 0 }, { bp_foot_r, 0 } + { bp_torso, 36.57 }, { bp_head, 5.71 }, { bp_eyes, 0.57 }, { bp_mouth, 0.0 }, { bp_arm_l, 22.86 }, { bp_arm_r, 22.86 }, + { bp_hand_l, 0.0 }, { bp_hand_r, 0.0 }, { bp_leg_l, 5.71 }, { bp_leg_r, 5.71 }, { bp_foot_l, 0.0 }, { bp_foot_r, 0.0 } }, Weights{ - { bp_torso, 5689 }, { bp_head, 5682 }, { bp_eyes, 221 }, { bp_mouth, 0 }, { bp_arm_l, 1185 }, { bp_arm_r, 1089 }, - { bp_hand_l, 0 }, { bp_hand_r, 0 }, { bp_leg_l, 578 }, { bp_leg_r, 556 }, { bp_foot_l, 0 }, { bp_foot_r, 0 } + { bp_torso, 5689.0 }, { bp_head, 5682.0 }, { bp_eyes, 221.0 }, { bp_mouth, 0.0 }, { bp_arm_l, 1185.0 }, { bp_arm_r, 1089.0 }, + { bp_hand_l, 0.0 }, { bp_hand_r, 0.0 }, { bp_leg_l, 578.0 }, { bp_leg_r, 556.0 }, { bp_foot_l, 0.0 }, { bp_foot_r, 0.0 } } }; @@ -64,8 +64,8 @@ void calculate_bodypart_distribution( const enum m_size attacker_size, { INFO( "hit roll = " << hit_roll ); auto selected_part_histogram = Weights{ - { bp_torso, 0 }, { bp_head, 0 }, { bp_eyes, 0 }, { bp_mouth, 0 }, { bp_arm_l, 0 }, { bp_arm_r, 0 }, - { bp_hand_l, 0 }, { bp_hand_r, 0 }, { bp_leg_l, 0 }, { bp_leg_r, 0 }, { bp_foot_l, 0 }, { bp_foot_r, 0 } + { bp_torso, 0.0 }, { bp_head, 0.0 }, { bp_eyes, 0.0 }, { bp_mouth, 0.0 }, { bp_arm_l, 0.0 }, { bp_arm_r, 0.0 }, + { bp_hand_l, 0.0 }, { bp_hand_r, 0.0 }, { bp_leg_l, 0.0 }, { bp_leg_r, 0.0 }, { bp_foot_l, 0.0 }, { bp_foot_r, 0.0 } }; mtype atype; @@ -84,8 +84,8 @@ void calculate_bodypart_distribution( const enum m_size attacker_size, selected_part_histogram.at( bp )++; } - const float total_weight = std::accumulate( expected.begin(), expected.end(), 0.0f, - []( float acc, const auto & p ) { + const double total_weight = std::accumulate( expected.begin(), expected.end(), 0.0, + []( double acc, const auto & p ) { return acc + p.second; } ); diff --git a/tests/pch/tests-pch.hpp b/tests/pch/tests-pch.hpp index 91f67a3c5913..a403a41a1d6e 100644 --- a/tests/pch/tests-pch.hpp +++ b/tests/pch/tests-pch.hpp @@ -1,3 +1,7 @@ #include "../pch/main-pch.hpp" #define CATCH_CONFIG_ALL_PARTS -#include "catch/catch.hpp" +#if defined(CMAKE) +# include "../catch/catch.hpp" +#else +# include "catch/catch.hpp" +#endif diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 9d554959ebf9..e1861cb1428d 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -327,6 +327,7 @@ int main( int argc, const char *argv[] ) DebugLog( DL::Info, DC::Main ) << "Randomness seeded to: " << seed; auto _on_out_of_scope = on_out_of_scope( []() { + g.reset(); DynamicDataLoader::get_instance().unload_data(); } ); try { diff --git a/tests/translations_test.cpp b/tests/translations_test.cpp index f22b49656c24..5abdcf74054e 100644 --- a/tests/translations_test.cpp +++ b/tests/translations_test.cpp @@ -168,9 +168,7 @@ TEST_CASE( "translations_actually_translate", "[translations][i18n]" ) } } - // Back up current language (should be 'en') const static std::string USE_LANG( "USE_LANG" ); - std::string lang_default = get_option( USE_LANG ); for( const auto &test : test_cases ) { CAPTURE( test.id ); @@ -187,7 +185,7 @@ TEST_CASE( "translations_actually_translate", "[translations][i18n]" ) } // Restore language - get_options().get_option( USE_LANG ).setValue( lang_default ); + get_options().get_option( USE_LANG ).setValue( "en_US" ); get_options().save(); set_language(); } diff --git a/tools/clang-tidy-plugin/CMakeLists.txt b/tools/clang-tidy-plugin/CMakeLists.txt index 4bd854d2ab1a..baf4cbe53f50 100644 --- a/tools/clang-tidy-plugin/CMakeLists.txt +++ b/tools/clang-tidy-plugin/CMakeLists.txt @@ -30,11 +30,6 @@ target_include_directories(CataAnalyzerPlugin SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS ${CLANG_INCLUDE_DIRS}) if ("${CATA_CLANG_TIDY_INCLUDE_DIR}" STREQUAL "") - # suppress DOWNLOAD_EXTRACT_TIMESTAMP warning - if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") - cmake_policy(SET CMP0135 NEW) - endif () - 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)