[Build] Remove ENABLE_NLS, fix TRANSLATIONS_ONLY

* Remove the ENABLE_NLS option, it is now always enabled.
* Fix the TRANSLATIONS_ONLY build to properly build the zip file.
This commit is contained in:
Fabrice de Gans 2024-03-26 17:00:53 -07:00 committed by Fabrice de Gans
parent c3f0aa2edf
commit 98b51910eb
7 changed files with 141 additions and 146 deletions

View File

@ -292,41 +292,40 @@ if(NOT ENABLE_ASM_CORE)
endif()
# Enable internationalization
if(ENABLE_NLS)
set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale)
add_compile_definitions(ENABLE_NLS)
add_compile_definitions(LOCALEDIR="${LOCALEDIR}")
# for now, only GBALink.cpp uses gettext() directly
if(APPLE)
# use Homebrew gettext if available
if(EXISTS "/usr/local/opt/gettext")
set(CMAKE_INCLUDE_PATH "${CMAKE_INCLUDE_PATH};/usr/local/opt/gettext/include")
set(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH};/usr/local/opt/gettext/lib")
set(CMAKE_PROGRAM_PATH "${CMAKE_PROGRAM_PATH};/usr/local/opt/gettext/bin")
endif()
set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale)
add_compile_definitions(LOCALEDIR="${LOCALEDIR}")
# for now, only GBALink.cpp uses gettext() directly
if(APPLE)
# use Homebrew gettext if available
if(EXISTS "/usr/local/opt/gettext")
set(CMAKE_INCLUDE_PATH "${CMAKE_INCLUDE_PATH};/usr/local/opt/gettext/include")
set(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH};/usr/local/opt/gettext/lib")
set(CMAKE_PROGRAM_PATH "${CMAKE_PROGRAM_PATH};/usr/local/opt/gettext/bin")
endif()
if(ENABLE_LINK OR ENABLE_WX)
find_path(LIBINTL_INC libintl.h)
find_library(LIBINTL_LIB NAMES libintl intl)
find_library(LIBICONV_LIB NAMES libiconv iconv)
find_library(LIBCHARSET_LIB NAMES libcharset charset)
if(LIBINTL_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBINTL_LIB})
list(APPEND NLS_LIBS ${LIBINTL_LIB})
endif()
if(LIBICONV_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBICONV_LIB})
list(APPEND NLS_LIBS ${LIBICONV_LIB})
endif()
if(LIBCHARSET_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBCHARSET_LIB})
list(APPEND NLS_LIBS ${LIBCHARSET_LIB})
endif()
include(CheckFunctionExists)
check_function_exists(gettext GETTEXT_FN)
if(NOT (LIBINTL_INC OR GETTEXT_FN))
message(FATAL_ERROR "NLS requires libintl/gettext")
endif()
endif()
if(ENABLE_LINK OR ENABLE_WX)
find_path(LIBINTL_INC libintl.h)
find_library(LIBINTL_LIB NAMES libintl intl)
find_library(LIBICONV_LIB NAMES libiconv iconv)
find_library(LIBCHARSET_LIB NAMES libcharset charset)
if(LIBINTL_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBINTL_LIB})
list(APPEND NLS_LIBS ${LIBINTL_LIB})
endif()
if(LIBICONV_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBICONV_LIB})
list(APPEND NLS_LIBS ${LIBICONV_LIB})
endif()
if(LIBCHARSET_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBCHARSET_LIB})
list(APPEND NLS_LIBS ${LIBCHARSET_LIB})
endif()
include(CheckFunctionExists)
check_function_exists(gettext GETTEXT_FN)
if(NOT (LIBINTL_INC OR GETTEXT_FN))
message(FATAL_ERROR "NLS requires libintl/gettext")
endif()
endif()
@ -336,9 +335,9 @@ if(NOT TRANSLATIONS_ONLY)
add_subdirectory(src/core)
add_subdirectory(src/components)
add_subdirectory(src/sdl)
add_subdirectory(src/wx)
endif()
add_subdirectory(src/wx)
add_subdirectory(po/wxvbam)
set(CPACK_GENERATOR "ZIP")

View File

@ -148,7 +148,7 @@ And the following development libraries:
- [zlib](https://zlib.net/) (required)
- [mesa](https://mesa3d.org/) (if using X11 or any OpenGL otherwise)
- [ffmpeg](https://ffmpeg.org/) (optional, at least version `4.0.4`, for game recording)
- [gettext](https://www.gnu.org/software/gettext/) and gettext-tools (optional, with ENABLE_NLS)
- [gettext](https://www.gnu.org/software/gettext/) and gettext-tools
- [SDL2](https://www.libsdl.org/) (required)
- [SFML](https://www.sfml-dev.org/) (optional, for link)
- [OpenAL](https://www.openal.org/) or [openal-soft](https://kcat.strangesoft.net/openal.html) (required, a sound interface)
@ -205,7 +205,6 @@ Here is the complete list:
| ENABLE_SDL | Build the SDL port | OFF |
| ENABLE_WX | Build the wxWidgets port | ON |
| ENABLE_DEBUGGER | Enable the debugger | ON |
| ENABLE_NLS | Enable translations | ON |
| ENABLE_ASM_CORE | Enable x86 ASM CPU cores (**BUGGY AND DANGEROUS**) | OFF |
| ENABLE_ASM | Enable the following two ASM options | ON for 32 bit builds |
| ENABLE_ASM_SCALERS | Enable x86 ASM graphic filters | ON for 32 bit builds |

View File

@ -1,8 +1,15 @@
option(BUILD_TESTING "Build testing" ON)
option(BUILD_SHARED_LIBS "Build dynamic libraries" OFF)
option(ENABLE_SDL "Build the SDL port" ON)
option(ENABLE_WX "Build the wxWidgets port" ON)
option(TRANSLATIONS_ONLY "Build only the translations.zip" OFF)
if(TRANSLATIONS_ONLY)
set(BUILD_DEFAULT OFF)
else()
set(BUILD_DEFAULT ON)
endif()
option(ENABLE_SDL "Build the SDL port" ${BUILD_DEFAULT})
option(ENABLE_WX "Build the wxWidgets port" ${BUILD_DEFAULT})
option(ENABLE_DEBUGGER "Enable the debugger" ON)
option(ENABLE_ASAN "Enable -fsanitize=address by default. Requires debug build with GCC/Clang" OFF)
@ -114,12 +121,8 @@ if(APPLE AND NOT DISABLE_MACOS_PACKAGE_MANAGERS)
include(MacPackageManagers)
endif()
option(ENABLE_NLS "Enable translations" ON)
option(UPSTREAM_RELEASE "do some optimizations and release automation tasks" OFF)
option(TRANSLATIONS_ONLY "Build only the translations.zip" OFF)
if(WIN32)
# not yet implemented
option(ENABLE_DIRECT3D "Enable Direct3D rendering for the wxWidgets port" OFF)

View File

@ -1,4 +1,4 @@
if(NOT ENABLE_WX OR NOT ENABLE_NLS)
if(NOT TRANSLATIONS_ONLY AND NOT ENABLE_WX)
return()
endif()

View File

@ -121,17 +121,18 @@ if(ENABLE_LINK)
)
target_include_directories(vbam-core
PRIVATE ${SFML_INCLUDE_DIR})
PRIVATE ${SFML_INCLUDE_DIR}
)
target_link_libraries(vbam-core
PRIVATE ${SFML_LIBRARIES})
if(ENABLE_NLS)
# Add libintl.h
target_include_directories(vbam-core
PRIVATE ${LIBINTL_INC})
target_link_libraries(vbam-core
PRIVATE ${NLS_LIBS})
endif()
PRIVATE ${SFML_LIBRARIES}
)
# Add libintl.h
target_include_directories(vbam-core
PRIVATE ${LIBINTL_INC}
)
target_link_libraries(vbam-core
PRIVATE ${NLS_LIBS}
)
endif()

View File

@ -28,12 +28,8 @@
#include <SFML/Network.hpp>
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(x) gettext(x)
#else
#define _(x) x
#endif
#include "core/base/message.h"
#include "core/base/port.h"

View File

@ -1,3 +1,7 @@
if(NOT TRANSLATIONS_ONLY AND NOT ENABLE_WX)
return()
endif()
# Do not use this file directly. Always use the top level CMakeLists.txt file
include(VbamFunctions)
@ -114,22 +118,57 @@ if(NOT ZIP_PROGRAM)
endif()
endif()
# Make the translations.zip
if(ENABLE_NLS OR TRANSLATIONS_ONLY)
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/translations.zip
COMMAND ${CMAKE_COMMAND} -D "ZIP_PROGRAM=${ZIP_PROGRAM}" -P ${CMAKE_CURRENT_SOURCE_DIR}/make-translations-zip.cmake
if(MSVC)
# Install gettext tools from nuget.
# First fetch the nuget binary.
if(NOT EXISTS ${CMAKE_BINARY_DIR}/nuget.exe)
file(DOWNLOAD "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" ${CMAKE_BINARY_DIR}/nuget.exe)
endif()
# Add nuget package source.
execute_process(
COMMAND nuget sources add -Name "NuGet official package source" -Source "https://api.nuget.org/v3/index.json"
OUTPUT_QUIET
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS translations make-translations-zip.cmake
)
add_custom_target(
translations-zip
SOURCES ${CMAKE_BINARY_DIR}/translations.zip
# Install the Gettext.Tools package.
execute_process(
COMMAND nuget.exe install Gettext.Tools -OutputDirectory ${CMAKE_BINARY_DIR}/nuget
OUTPUT_QUIET
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Find the path to the binaries in the package and add them to find path.
file(GLOB pkg ${CMAKE_BINARY_DIR}/nuget/Gettext.Tools*)
list(APPEND CMAKE_PROGRAM_PATH ${pkg}/tools/bin)
endif()
if(TRANSLATIONS_ONLY OR NOT ENABLE_WX)
find_package(Gettext REQUIRED)
find_program(XGETTEXT xgettext)
find_program(MSGINIT msginit)
if(NOT XGETTEXT OR NOT MSGINIT)
message(SEND_ERROR "Cannot find gettext xgettext:'${XGETTEXT}' msginit:'${MSGINIT}'")
endif()
# Make the translations.zip
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/translations.zip
COMMAND ${CMAKE_COMMAND} -D "ZIP_PROGRAM=${ZIP_PROGRAM}" -P ${CMAKE_CURRENT_SOURCE_DIR}/make-translations-zip.cmake
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS translations make-translations-zip.cmake
)
add_custom_target(
translations-zip
ALL
SOURCES ${CMAKE_BINARY_DIR}/translations.zip
)
if(TRANSLATIONS_ONLY)
# Nothing more to do if we are only building the translations.zip file.
return()
endif()
@ -158,9 +197,7 @@ target_link_libraries(
${OPENGL_LIBRARIES}
)
if(ENABLE_NLS)
add_dependencies(visualboyadvance-m translations-zip)
endif()
add_dependencies(visualboyadvance-m translations-zip)
# on unix we have to check for X11 before we overwrite all the compile/link
# flags with the wx tests
@ -381,44 +418,6 @@ if(ENABLE_FFMPEG)
endif()
endif()
if(ENABLE_NLS)
if(MSVC)
# Install gettext tools from nuget.
# First fetch the nuget binary.
if(NOT EXISTS ${CMAKE_BINARY_DIR}/nuget.exe)
file(DOWNLOAD "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" ${CMAKE_BINARY_DIR}/nuget.exe)
endif()
# Add nuget package source.
execute_process(
COMMAND nuget sources add -Name "NuGet official package source" -Source "https://api.nuget.org/v3/index.json"
OUTPUT_QUIET
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Install the Gettext.Tools package.
execute_process(
COMMAND nuget.exe install Gettext.Tools -OutputDirectory ${CMAKE_BINARY_DIR}/nuget
OUTPUT_QUIET
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Find the path to the binaries in the package and add them to find path.
file(GLOB pkg ${CMAKE_BINARY_DIR}/nuget/Gettext.Tools*)
list(APPEND CMAKE_PROGRAM_PATH ${pkg}/tools/bin)
endif()
find_package(Gettext REQUIRED)
find_program(XGETTEXT xgettext)
find_program(MSGINIT msginit)
if(NOT XGETTEXT OR NOT MSGINIT)
message(SEND_ERROR "Cannot find gettext xgettext:'${XGETTEXT}' msginit:'${MSGINIT}'")
endif()
endif()
# wxrc does not support xrs files in -c output (> 10x compression)
# we do it using the bin2c.c utility.
set(BIN2C ${CMAKE_BINARY_DIR}/bin2c)
@ -661,45 +660,43 @@ endif()
# Update the gettext pot source.
# Do this automatically instead of manually to make sure we don't forget to update.
if(ENABLE_NLS)
add_custom_target(
vbam-wx-xrc-strings
COMMAND ${CMAKE_COMMAND}
-E env
"PATH=$ENV{PATH}"
${WXRC}
-g ${VBAM_XRC_FILES}
-o ${CMAKE_BINARY_DIR}/wx-xrc-strings.h
BYPRODUCTS
${CMAKE_BINARY_DIR}/wx-xrc-strings.h
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS
${VBAM_XRC_FILES}
)
add_custom_target(
vbam-wx-xrc-strings
COMMAND ${CMAKE_COMMAND}
-E env
"PATH=$ENV{PATH}"
${WXRC}
-g ${VBAM_XRC_FILES}
-o ${CMAKE_BINARY_DIR}/wx-xrc-strings.h
BYPRODUCTS
${CMAKE_BINARY_DIR}/wx-xrc-strings.h
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS
${VBAM_XRC_FILES}
)
add_custom_target(
vbam-wx-pot
COMMAND ${XGETTEXT}
-k_ -kN_
-o ${CMAKE_BINARY_DIR}/wxvbam.pot
${VBAM_LOCALIZABLE_FILES} ${CMAKE_BINARY_DIR}/wx-xrc-strings.h
BYPRODUCTS
${CMAKE_BINARY_DIR}/wxvbam.pot
DEPENDS
${VBAM_LOCALIZABLE_FILES} ${CMAKE_BINARY_DIR}/wx-xrc-strings.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(
vbam-wx-pot
COMMAND ${XGETTEXT}
-k_ -kN_
-o ${CMAKE_BINARY_DIR}/wxvbam.pot
${VBAM_LOCALIZABLE_FILES} ${CMAKE_BINARY_DIR}/wx-xrc-strings.h
BYPRODUCTS
${CMAKE_BINARY_DIR}/wxvbam.pot
DEPENDS
${VBAM_LOCALIZABLE_FILES} ${CMAKE_BINARY_DIR}/wx-xrc-strings.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_command(
TARGET vbam-wx-pot
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-DSRC_DIR=${CMAKE_SOURCE_DIR}/po/wxvbam
-DBIN_DIR=${CMAKE_BINARY_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/check-pot-updated.cmake
)
endif()
add_custom_command(
TARGET vbam-wx-pot
POST_BUILD
COMMAND ${CMAKE_COMMAND}
-DSRC_DIR=${CMAKE_SOURCE_DIR}/po/wxvbam
-DBIN_DIR=${CMAKE_BINARY_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/check-pot-updated.cmake
)
find_program(GPG_PROGRAM gpg)
if(GPG_PROGRAM)