[config] Create the vbam-wx-config target

Circular dependencies between the config sub-module and the rest of the
wx frontend have been removed. This change separates the config code to
its own submodule.

This is a preliminary change to improve testing coverage.
This commit is contained in:
Fabrice de Gans 2024-05-05 21:51:07 -07:00
parent 90a56c6937
commit c9668d9a88
5 changed files with 148 additions and 193 deletions

View File

@ -5,7 +5,9 @@
# Generate version_gen.h
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\1,\\2,\\3,0" VBAM_WIN_VERSION "${VBAM_VERSION}")
set(VBAM_GENERATED_VERSION_H ${VBAM_GENERATED_DIR}/core/base/version_gen.h)
add_custom_target(vbam-core-base-generated
add_custom_command(
OUTPUT
${VBAM_GENERATED_VERSION_H}
COMMAND ${CMAKE_COMMAND}
-DVBAM_GENERATED_VERSION_H=${VBAM_GENERATED_VERSION_H}
-DVBAM_VERSION=${VBAM_VERSION}
@ -13,8 +15,6 @@ add_custom_target(vbam-core-base-generated
-DVBAM_VERSION_RELEASE=${VBAM_VERSION_RELEASE}
-DVBAM_WIN_VERSION=${VBAM_WIN_VERSION}
-P ${CMAKE_CURRENT_SOURCE_DIR}/build-version.cmake
BYPRODUCTS
${VBAM_GENERATED_VERSION_H}
DEPENDS
version_gen.h.in
build-version.cmake
@ -22,8 +22,6 @@ add_custom_target(vbam-core-base-generated
add_library(vbam-core-base OBJECT)
add_dependencies(vbam-core-base vbam-core-base-generated)
target_sources(vbam-core-base
PRIVATE
file_util_common.cpp
@ -48,6 +46,8 @@ target_sources(vbam-core-base
sound_driver.h
system.h
version.h
# Generated file.
${VBAM_GENERATED_VERSION_H}
)
target_include_directories(vbam-core-base

View File

@ -13,28 +13,6 @@ set(VBAM_WX_COMMON
background-input.cpp
background-input.h
cmdevents.cpp
config/bindings.cpp
config/bindings.h
config/command.cpp
config/command.h
config/cmdtab.cpp
config/cmdtab.h
config/emulated-gamepad.cpp
config/emulated-gamepad.h
config/internal/bindings-internal.cpp
config/internal/bindings-internal.h
config/internal/option-internal.cpp
config/internal/option-internal.h
config/option-id.h
config/option-observer.cpp
config/option-observer.h
config/option-proxy.h
config/option.cpp
config/option.h
config/strutils.cpp
config/strutils.h
config/user-input.cpp
config/user-input.h
dialogs/accel-config.cpp
dialogs/accel-config.h
dialogs/base-dialog.cpp
@ -106,7 +84,6 @@ set(VBAM_WX_COMMON
${VBAM_GENERATED_DIR}/wx/builtin-over.h
${VBAM_GENERATED_DIR}/wx/cmdhandlers.h
${VBAM_GENERATED_DIR}/wx/cmd-evtable.h
${VBAM_GENERATED_DIR}/wx/config/internal/cmdtab.cpp
)
if(NOT ZIP_PROGRAM)
@ -187,6 +164,74 @@ if(TRANSLATIONS_ONLY)
return()
endif()
# wxWidgets configuration.
set(wxWidgets_USE_UNICODE ON)
if(CMAKE_BUILD_TYPE MATCHES "^(Debug|RelWithDebInfo)$")
set(wxWidgets_USE_DEBUG ON) # noop if wx is compiled with --disable-debug, like in Mac Homebrew atm
endif()
if(VBAM_STATIC)
set(wxWidgets_USE_STATIC ON)
endif()
unset(wx_find_extra)
if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
set(wx_find_extra NO_DEFAULT_PATH)
set(wxWidgets_DIR "${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/share/wxwidgets")
endif()
find_package(wxWidgets COMPONENTS xrc xml html adv net core base gl ${wx_find_extra})
if(NOT wxWidgets_FOUND)
find_package(wxWidgets COMPONENTS xrc xml html adv net core base ${wx_find_extra} REQUIRED)
target_compile_definitions(visualboyadvance-m PRIVATE NO_OGL)
endif()
# Workaround of static liblzma not being found on MSYS2.
if(VBAM_STATIC AND MSYS)
unset(cleaned_up_wx_libs)
foreach(lib ${wxWidgets_LIBRARIES})
if(lib STREQUAL "-llzma")
set(lib "liblzma.a")
endif()
list(APPEND cleaned_up_wx_libs "${lib}")
endforeach()
set(wxWidgets_LIBRARIES "${cleaned_up_wx_libs}")
endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES ${wxWidgets_LIBRARIES})
list(APPEND CMAKE_REQUIRED_INCLUDES ${wxWidgets_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_FLAGS ${wxWidgets_CXX_FLAGS})
foreach(DEF ${wxWidgets_DEFINITIONS})
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D${DEF}")
endforeach()
# Sets the wxWidgets dependencies for a given target.
function(configure_wx_deps target)
get_target_property(target_type ${target} TYPE)
if (target_type STREQUAL "EXECUTABLE")
target_link_libraries(${target} ${wxWidgets_LIBRARIES})
target_include_directories(${target} PRIVATE ${wxWidgets_INCLUDE_DIRS})
target_compile_options(${target} PRIVATE ${wxWidgets_CXX_FLAGS})
target_compile_definitions(${target} PRIVATE ${wxWidgets_DEFINITIONS})
if(CMAKE_BUILD_TYPE MATCHES "^(Debug|RelWithDebInfo)$")
target_compile_definitions(${target} PRIVATE ${wxWidgets_DEFINITIONS_DEBUG})
endif()
else()
target_link_libraries(${target} PUBLIC ${wxWidgets_LIBRARIES})
target_include_directories(${target} PUBLIC ${wxWidgets_INCLUDE_DIRS})
target_compile_options(${target} PUBLIC ${wxWidgets_CXX_FLAGS})
target_compile_definitions(${target} PUBLIC ${wxWidgets_DEFINITIONS})
if(CMAKE_BUILD_TYPE MATCHES "^(Debug|RelWithDebInfo)$")
target_compile_definitions(${target} PUBLIC ${wxWidgets_DEFINITIONS_DEBUG})
endif()
endif()
endfunction()
# Sub-projects.
add_subdirectory(config)
set(VBAM_ICON visualboyadvance-m.icns)
set(VBAM_ICON_PATH ${CMAKE_CURRENT_SOURCE_DIR}/icons/${VBAM_ICON})
@ -208,6 +253,7 @@ target_link_libraries(
vbam-components-filters-agb
vbam-components-filters-interframe
vbam-components-user-config
vbam-wx-config
${OPENGL_LIBRARIES}
${VBAM_SDL2_LIBS}
)
@ -342,56 +388,7 @@ if(ENABLE_FAUDIO)
target_compile_definitions(visualboyadvance-m PRIVATE VBAM_ENABLE_FAUDIO)
endif()
# wxWidgets.
set(wxWidgets_USE_UNICODE ON)
if(CMAKE_BUILD_TYPE MATCHES "^(Debug|RelWithDebInfo)$")
set(wxWidgets_USE_DEBUG ON) # noop if wx is compiled with --disable-debug, like in Mac Homebrew atm
endif()
if(VBAM_STATIC)
set(wxWidgets_USE_STATIC ON)
endif()
unset(wx_find_extra)
if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
set(wx_find_extra NO_DEFAULT_PATH)
set(wxWidgets_DIR "${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/share/wxwidgets")
endif()
find_package(wxWidgets COMPONENTS xrc xml html adv net core base gl ${wx_find_extra})
if(NOT wxWidgets_FOUND)
find_package(wxWidgets COMPONENTS xrc xml html adv net core base ${wx_find_extra} REQUIRED)
target_compile_definitions(visualboyadvance-m PRIVATE NO_OGL)
endif()
# Workaround of static liblzma not being found on MSYS2.
if(VBAM_STATIC AND MSYS)
unset(cleaned_up_wx_libs)
foreach(lib ${wxWidgets_LIBRARIES})
if(lib STREQUAL "-llzma")
set(lib "liblzma.a")
endif()
list(APPEND cleaned_up_wx_libs "${lib}")
endforeach()
set(wxWidgets_LIBRARIES "${cleaned_up_wx_libs}")
endif()
target_link_libraries(visualboyadvance-m ${wxWidgets_LIBRARIES})
target_include_directories(visualboyadvance-m PRIVATE ${wxWidgets_INCLUDE_DIRS})
target_compile_options(visualboyadvance-m PRIVATE ${wxWidgets_CXX_FLAGS})
target_compile_definitions(visualboyadvance-m PRIVATE ${wxWidgets_DEFINITIONS})
if(CMAKE_BUILD_TYPE MATCHES "^(Debug|RelWithDebInfo)$")
target_compile_definitions(visualboyadvance-m PRIVATE ${wxWidgets_DEFINITIONS_DEBUG})
endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES ${wxWidgets_LIBRARIES})
list(APPEND CMAKE_REQUIRED_INCLUDES ${wxWidgets_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_FLAGS ${wxWidgets_CXX_FLAGS})
foreach(DEF ${wxWidgets_DEFINITIONS})
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D${DEF}")
endforeach()
configure_wx_deps(visualboyadvance-m)
# we make some direct gtk/gdk calls on linux and such
# so need to link the gtk that wx was built with
@ -601,24 +598,7 @@ add_custom_command(
DEPENDS ${CMAKE_SOURCE_DIR}/src/vba-over.ini ${BIN2C}
)
# I don't like duplicating/triplicating code, so I only declare
# event handlers once, and copy them in other places they are needed
# all using portable cmake code
add_custom_command(
OUTPUT
${VBAM_GENERATED_DIR}/wx/config/internal/cmdtab.cpp
${VBAM_GENERATED_DIR}/wx/cmdhandlers.h
${VBAM_GENERATED_DIR}/wx/cmd-evtable.h
COMMAND
${CMAKE_COMMAND} -D OUTDIR=${VBAM_GENERATED_DIR}/wx/ -P copy-events.cmake
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS
cmdevents.cpp
copy-events.cmake
)
set(VBAM_LOCALIZABLE_FILES ${VBAM_WX_COMMON})
set(VBAM_LOCALIZABLE_FILES ${VBAM_WX_COMMON} ${VBAM_LOCALIZABLE_WX_CONFIG_FILES})
list(APPEND VBAM_LOCALIZABLE_FILES
audio/internal/dsound.cpp
audio/internal/faudio.cpp

View File

@ -0,0 +1,71 @@
# This defines the vbam-wx-config target and the
# `VBAM_LOCALIZABLE_WX_CONFIG_FILES` variable, containing the list of
# localizable files in the vbam-wx-config target.
# I don't like duplicating/triplicating code, so I only declare
# event handlers once, and copy them in other places they are needed
# all using portable cmake code
add_custom_command(
OUTPUT
${VBAM_GENERATED_DIR}/wx/config/internal/cmdtab.cpp
${VBAM_GENERATED_DIR}/wx/cmdhandlers.h
${VBAM_GENERATED_DIR}/wx/cmd-evtable.h
COMMAND
${CMAKE_COMMAND} -D OUTDIR=${VBAM_GENERATED_DIR}/wx/ -P copy-events.cmake
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS
../cmdevents.cpp
copy-events.cmake
)
add_library(vbam-wx-config OBJECT)
# Export the localizable files to the parent scope.
set(VBAM_LOCALIZABLE_WX_CONFIG_FILES
${CMAKE_CURRENT_LIST_DIR}/bindings.cpp
${CMAKE_CURRENT_LIST_DIR}/command.cpp
${CMAKE_CURRENT_LIST_DIR}/cmdtab.cpp
${CMAKE_CURRENT_LIST_DIR}/emulated-gamepad.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/bindings-internal.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/bindings-internal.h
${CMAKE_CURRENT_LIST_DIR}/internal/option-internal.cpp
${CMAKE_CURRENT_LIST_DIR}/internal/option-internal.h
${CMAKE_CURRENT_LIST_DIR}/option-observer.cpp
${CMAKE_CURRENT_LIST_DIR}/option.cpp
${CMAKE_CURRENT_LIST_DIR}/strutils.cpp
${CMAKE_CURRENT_LIST_DIR}/user-input.cpp
# Generated file.
${VBAM_GENERATED_DIR}/wx/config/internal/cmdtab.cpp
)
set(VBAM_LOCALIZABLE_WX_CONFIG_FILES
${VBAM_LOCALIZABLE_WX_CONFIG_FILES}
PARENT_SCOPE
)
target_sources(vbam-wx-config
PRIVATE
${VBAM_LOCALIZABLE_WX_CONFIG_FILES}
PUBLIC
bindings.h
command.h
cmdtab.h
emulated-gamepad.h
option-id.h
option-observer.h
option-proxy.h
option.h
strutils.h
user-input.h
)
target_link_libraries(vbam-wx-config
PUBLIC
nonstd-lib
vbam-core
)
configure_wx_deps(vbam-wx-config)
target_include_directories(vbam-wx-config PUBLIC ${NONSTD_INCLUDE_DIR})

View File

@ -8,7 +8,7 @@ SET(CMDTAB "${OUTDIR}/config/internal/cmdtab.cpp")
SET(EVPROTO "${OUTDIR}/cmdhandlers.h")
SET(EVTABLE "${OUTDIR}/cmd-evtable.h")
FILE(READ cmdevents.cpp MW)
FILE(READ ../cmdevents.cpp MW)
STRING(REGEX MATCHALL "\nEVT_HANDLER([^\")]|\"[^\"]*\")*\\)" MW "${MW}")
# cmdtab.cpp is a table of cmd-id-name/cmd-name pairs

View File

@ -1,96 +0,0 @@
#include "wx/config/strutils.h"
#include <gtest/gtest.h>
TEST(StrSplitTest, Basic) {
wxString foo = "foo|bar|baz";
auto vec = config::str_split(foo, '|');
EXPECT_EQ(vec.size(), 3);
EXPECT_EQ(vec[0], "foo");
EXPECT_EQ(vec[1], "bar");
EXPECT_EQ(vec[2], "baz");
}
TEST(StrSplitTest, MultiCharSep) {
wxString foo = "foo|-|bar|-|baz";
auto vec = config::str_split(foo, "|-|");
EXPECT_EQ(vec.size(), 3);
EXPECT_EQ(vec[0], "foo");
EXPECT_EQ(vec[1], "bar");
EXPECT_EQ(vec[2], "baz");
}
TEST(StrSplitTest, SkipEmptyToken) {
wxString foo = "|-|foo|-||-|bar|-|baz|-|";
auto vec = config::str_split(foo, "|-|");
EXPECT_EQ(vec.size(), 3);
EXPECT_EQ(vec[0], "foo");
EXPECT_EQ(vec[1], "bar");
EXPECT_EQ(vec[2], "baz");
}
TEST(StrSplitTest, EmptyInput) {
wxString foo;
auto vec = config::str_split(foo, "|-|");
EXPECT_EQ(vec.size(), 0);
}
TEST(StrSplitTest, NoTokens) {
wxString foo = "|-||-||-||-||-|";
auto vec = config::str_split(foo, "|-|");
EXPECT_EQ(vec.size(), 0);
}
TEST(StrSplitWithSepTest, Basic) {
wxString foo = "foo|bar|baz|";
auto vec = config::str_split_with_sep(foo, '|');
EXPECT_EQ(vec.size(), 4);
EXPECT_EQ(vec[0], "foo");
EXPECT_EQ(vec[1], "bar");
EXPECT_EQ(vec[2], "baz");
EXPECT_EQ(vec[3], "|");
}
TEST(StrSplitWithSepTest, MultiCharSep) {
wxString foo = "foo|-|bar|-|baz|-|";
auto vec = config::str_split_with_sep(foo, "|-|");
EXPECT_EQ(vec.size(), 4);
EXPECT_EQ(vec[0], "foo");
EXPECT_EQ(vec[1], "bar");
EXPECT_EQ(vec[2], "baz");
EXPECT_EQ(vec[3], "|-|");
}
TEST(StrSplitWithSepTest, MultipleSepTokens) {
wxString foo = "|-|foo|-||-|bar|-|baz|-|";
auto vec = config::str_split_with_sep(foo, "|-|");
EXPECT_EQ(vec.size(), 6);
EXPECT_EQ(vec[0], "|-|");
EXPECT_EQ(vec[1], "foo");
EXPECT_EQ(vec[2], "|-|");
EXPECT_EQ(vec[3], "bar");
EXPECT_EQ(vec[4], "baz");
EXPECT_EQ(vec[5], "|-|");
}