From b5f3431526d3b8c13ce98cd235735666ebbbe869 Mon Sep 17 00:00:00 2001 From: Qrox Date: Fri, 20 Jan 2023 22:50:00 +0800 Subject: [PATCH] Fix CMake compilation and localization Localization: - Outdated .gitignore entry - Outdated documentation of .mo file compilation - Outdated .pot generation code Compilation: - `target_link_libraries` mixed signature error - Target name typo --- .gitignore | 1 - doc/COMPILING/COMPILING-CMAKE.md | 3 +-- lang/CMakeLists.txt | 21 ++---------------- src/CMakeLists.txt | 30 +++++++++++++------------- tests/CMakeLists.txt | 4 ++-- tools/clang-tidy-plugin/CMakeLists.txt | 2 +- tools/format/CMakeLists.txt | 2 +- 7 files changed, 22 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index ed663a1efdd3e..65aa08f798929 100644 --- a/.gitignore +++ b/.gitignore @@ -108,7 +108,6 @@ tags # Generated translation source /lang/po/*.pot -/lang/po/en.po # Compiled binary translations /lang/mo/ diff --git a/doc/COMPILING/COMPILING-CMAKE.md b/doc/COMPILING/COMPILING-CMAKE.md index 1ff272283aaf4..92c27ceca2568 100644 --- a/doc/COMPILING/COMPILING-CMAKE.md +++ b/doc/COMPILING/COMPILING-CMAKE.md @@ -290,9 +290,8 @@ $ cmake -DOPTION_NAME1=option_value1 [-DOPTION_NAME2=option_value2 [...]] -DLANGUAGES="cs;de;el;es_AR;es_ES" ``` - Note that language files are only compiled automatically when building the `RELEASE` build type. For other build types, you need to add the `translations_compile` target to the `make` command: for example `make all translations_compile`. + Note that language files are only compiled automatically when building the `RELEASE` build type. For other build types, you need to add the `locale` target to the `make` command: for example `make all locale`. - Special note for MinGW: Due to a [libintl bug](https://savannah.gnu.org/bugs/index.php?58006), using English without a `.mo` file causes significant slowdown on MinGW targets. Make sure `en` is in the list provided to `-DLANGUAGES` (it is by default), in order to generate a `.mo` file for English. * `DYNAMIC_LINKING=`: Use dynamic linking. Or use static to remove MinGW dependency instead. * `GIT_BINARY=` Override the default Git binary name or path. diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt index 2fcd3b5c98008..c2556547f86aa 100644 --- a/lang/CMakeLists.txt +++ b/lang/CMakeLists.txt @@ -13,12 +13,6 @@ foreach (LANG ${LANGUAGES}) message(STATUS "Add translation for ${LANG}: ${LANG}.po") endforeach () -# Extract json strings -add_custom_target( - extract_string - COMMAND python3 lang/extract_json_strings.py - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) - cmake_path(GET GETTEXT_MSGFMT_EXECUTABLE PARENT_PATH _path) find_program(XGETTEXT_MSGFMT_EXECUTABLE xgettext @@ -32,19 +26,8 @@ endif() # Generate cataclysm-dda.pot add_custom_target( translations - COMMAND ${XGETTEXT_MSGFMT_EXECUTABLE} --default-domain="cataclysm-dda" - --sort-by-file - --add-comments="~" - --output="${CMAKE_SOURCE_DIR}/lang/po/cataclysm-dda.pot" - --keyword="_" - --keyword="pgettext:1c,2" - --keyword="ngettext:1,2" - --from-code="UTF-8" - ${CMAKE_SOURCE_DIR}/src/*.cpp - ${CMAKE_SOURCE_DIR}/src/*.h - ${CMAKE_SOURCE_DIR}/lang/json/*.py - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - DEPENDS extract_string) + COMMAND ${CMAKE_SOURCE_DIR}/lang/update_pot.sh + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) add_custom_target( translations_prepare diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 214d54afc1356..5721599a04aeb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,7 +61,7 @@ if (TILES) add_dependencies(cataclysm-tiles-common get_version) - target_link_libraries(cataclysm-tiles cataclysm-tiles-common) + 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 PUBLIC @@ -71,7 +71,7 @@ if (TILES) target_include_directories(cataclysm-tiles-common PUBLIC ${LIBINTL_INCLUDE_DIR} ${ICONV_INCLUDE_DIR}) - target_link_libraries(cataclysm-tiles-common + target_link_libraries(cataclysm-tiles-common PUBLIC ${LIBINTL_LIBRARIES} ${ICONV_LIBRARIES}) endif () @@ -168,7 +168,7 @@ if (CURSES) ${CATACLYSM_DDA_HEADERS}) target_include_directories(cataclysm-common INTERFACE ${CMAKE_SOURCE_DIR}/src) - target_link_libraries(cataclysm-common third-party) + target_link_libraries(cataclysm-common PUBLIC third-party) if (WIN32) add_executable(cataclysm @@ -182,43 +182,43 @@ if (CURSES) endif () add_dependencies(cataclysm-common get_version) - target_link_libraries(cataclysm cataclysm-common) + target_link_libraries(cataclysm PRIVATE cataclysm-common) if (LOCALIZE) target_include_directories(cataclysm-common PUBLIC ${LIBINTL_INCLUDE_DIR} ${ICONV_INCLUDE_DIR}) - target_link_libraries(cataclysm-common + target_link_libraries(cataclysm-common PUBLIC ${LIBINTL_LIBRARIES} ${ICONV_LIBRARIES}) endif () target_include_directories(cataclysm-common PUBLIC ${CURSES_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS}) - target_link_libraries(cataclysm-common ${CURSES_LIBRARIES} ${ZLIB_LIBRARIES}) + target_link_libraries(cataclysm-common PUBLIC ${CURSES_LIBRARIES} ${ZLIB_LIBRARIES}) if (CMAKE_USE_PTHREADS_INIT) target_compile_options(cataclysm-common PUBLIC "-pthread") endif () if (CMAKE_THREAD_LIBS_INIT) - target_link_libraries(cataclysm-common ${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 gdi32.lib) - target_link_libraries(cataclysm-common winmm.lib) - target_link_libraries(cataclysm-common imm32.lib) - target_link_libraries(cataclysm-common ole32.lib) - target_link_libraries(cataclysm-common oleaut32.lib) - target_link_libraries(cataclysm-common version.lib) + 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 dbghelp.lib) + target_link_libraries(cataclysm-common PUBLIC dbghelp.lib) endif () endif () if (LIBBACKTRACE) - target_link_libraries(cataclysm-tiles-common backtrace) + target_link_libraries(cataclysm-common PUBLIC backtrace) endif () if (RELEASE) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8d1b43e19cde0..42369f443261f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,7 +26,7 @@ if (BUILD_TESTING) if (LOCALIZE) add_dependencies(cata_test-tiles test_mo) 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" @@ -38,7 +38,7 @@ if (BUILD_TESTING) if (LOCALIZE) add_dependencies(cata_test test_mo) 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" diff --git a/tools/clang-tidy-plugin/CMakeLists.txt b/tools/clang-tidy-plugin/CMakeLists.txt index 5f0ae1cd1715c..8758797994c21 100644 --- a/tools/clang-tidy-plugin/CMakeLists.txt +++ b/tools/clang-tidy-plugin/CMakeLists.txt @@ -47,7 +47,7 @@ set(CataAnalyzerSrc if (CATA_CLANG_TIDY_EXECUTABLE) set(CataAnalyzerName CataAnalyzer) add_executable(${CataAnalyzerName} ${CataAnalyzerSrc}) - target_link_libraries(${CataAnalyzerName} clangTidyMain) + target_link_libraries(${CataAnalyzerName} PRIVATE clangTidyMain) add_definitions(-DCATA_CLANG_TIDY_EXECUTABLE) else () set(CataAnalyzerName CataAnalyzerPlugin) diff --git a/tools/format/CMakeLists.txt b/tools/format/CMakeLists.txt index 905bda0f3b5cd..ee95b8cbc1e1c 100644 --- a/tools/format/CMakeLists.txt +++ b/tools/format/CMakeLists.txt @@ -6,7 +6,7 @@ add_executable( format_main.cpp ${CMAKE_SOURCE_DIR}/src/json.cpp) -target_link_libraries(json_formatter flatbuffers) +target_link_libraries(json_formatter PRIVATE flatbuffers) add_definitions(-DCATA_IN_TOOL)