Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CMake compilation and localization #63208

Merged
merged 1 commit into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ tags

# Generated translation source
/lang/po/*.pot
/lang/po/en.po

# Compiled binary translations
/lang/mo/
Expand Down
3 changes: 1 addition & 2 deletions doc/COMPILING/COMPILING-CMAKE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<boolean>`: Use dynamic linking. Or use static to remove MinGW dependency instead.
* `GIT_BINARY=<str>` Override the default Git binary name or path.

Expand Down
21 changes: 2 additions & 19 deletions lang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
30 changes: 15 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ()
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<TARGET_FILE:cata_test-tiles> --rng-seed time"
Expand All @@ -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
"$<TARGET_FILE:cata_test> --rng-seed time"
Expand Down
2 changes: 1 addition & 1 deletion tools/clang-tidy-plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/format/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down