All: Unify how feature defines work, allowing specific targets to not use them
@@ -97,6 +97,7 @@
add_definitions(-DBINARY_NAME="${BINARY_NAME}" -DPROJECT_NAME="${PROJECT_NAME}" -DPROJECT_VERSION="${LIB_VERSION_STRING}") # Feature dependencies +set(FEATURES) if(CMAKE_SYSTEM_NAME MATCHES .*BSD) set(LIBEDIT_LIBRARIES -ledit) else()@@ -171,13 +172,14 @@
# Features set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c) +set(FEATURE_SRC) set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6") if(USE_CLI_DEBUGGER) - add_definitions(-DUSE_CLI_DEBUGGER) - list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c) - list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c) - list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/cli.c) + list(APPEND FEATURES CLI_DEBUGGER) + list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/cli-debugger.c) + list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/debugger/parser.c) + list(APPEND FEATURE_SRC ${CMAKE_SOURCE_DIR}/src/gba/supervisor/cli.c) include_directories(AFTER ${LIBEDIT_INCLUDE_DIRS}) link_directories(${LIBEDIT_LIBRARY_DIRS}) set(DEBUGGER_LIB ${LIBEDIT_LIBRARIES})@@ -187,20 +189,20 @@ set(DEBUGGER_LIB "")
endif() if(USE_GDB_STUB) - add_definitions(-DUSE_GDB_STUB) + list(APPEND FEATURES GDB_STUB) list(APPEND DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/gdb-stub.c) endif() source_group("ARM debugger" FILES ${DEBUGGER_SRC}) if(USE_FFMPEG) - add_definitions(-DUSE_FFMPEG) + list(APPEND FEATURES FFMPEG) pkg_search_module(LIBSWRESAMPLE QUIET libswresample) if(NOT LIBSWRESAMPLE_FOUND) - add_definitions(-DUSE_LIBAV) + list(APPEND FEATURES LIBAV) endif() include_directories(AFTER ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVFORMAT_INCLUDE_DIRS} ${LIBAVRESAMPLE_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS}) link_directories(${LIBAVCODEC_LIBRARY_DIRS} ${LIBAVFORMAT_LIBRARY_DIRS} ${LIBAVRESAMPLE_LIBRARY_DIRS} ${LIBAVUTIL_LIBRARY_DIRS} ${LIBSWSCALE_LIBRARY_DIRS}) - list(APPEND UTIL_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c") + list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c") string(REGEX MATCH "^[0-9]+" LIBAVCODEC_VERSION_MAJOR ${libavcodec_VERSION}) string(REGEX MATCH "^[0-9]+" LIBAVFORMAT_VERSION_MAJOR ${libavformat_VERSION}) string(REGEX MATCH "^[0-9]+" LIBAVRESAMPLE_VERSION_MAJOR ${libavresample_VERSION})@@ -212,17 +214,17 @@ set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libavcodec-extra")
endif() if(USE_BLIP) - list(APPEND UTIL_SRC "${CMAKE_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c") + list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/third-party/blip_buf/blip_buf.c") add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_BLIP_BUF) else() add_definitions(-DRESAMPLE_LIBRARY=RESAMPLE_NN) endif() if(USE_MAGICK) - add_definitions(-DUSE_MAGICK) + list(APPEND FEATURES MAGICK) include_directories(AFTER ${MAGICKWAND_INCLUDE_DIRS}) link_directories(${MAGICKWAND_LIBRARY_DIRS}) - list(APPEND UTIL_SRC "${CMAKE_SOURCE_DIR}/src/platform/imagemagick/imagemagick-gif-encoder.c") + list(APPEND FEATURE_SRC "${CMAKE_SOURCE_DIR}/src/platform/imagemagick/imagemagick-gif-encoder.c") list(APPEND DEPENDENCY_LIB ${MAGICKWAND_LIBRARIES}) string(REGEX MATCH "^[0-9]+\\.[0-9]+" MAGICKWAND_VERSION_PARTIAL ${MagickWand_VERSION}) if(${MAGICKWAND_VERSION_PARTIAL} EQUAL "6.7")@@ -234,7 +236,7 @@ set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libmagickwand${MAGICKWAND_DEB_VERSION}")
endif() if(USE_PNG) - add_definitions(-DUSE_PNG) + list(APPEND FEATURES PNG) include_directories(AFTER ${PNG_INCLUDE_DIRS}) list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES}) set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libpng12-0,zlib1g")@@ -244,7 +246,7 @@ if(USE_LIBZIP)
include_directories(AFTER ${LIBZIP_INCLUDE_DIRS}) link_directories(${LIBZIP_LIBRARY_DIRS}) list(APPEND DEPENDENCY_LIB ${LIBZIP_LIBRARIES}) - add_definitions(-DENABLE_LIBZIP) + list(APPEND FEATURES LIBZIP) set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libzip2") endif()@@ -252,7 +254,6 @@ if (USE_LZMA)
include_directories(AFTER ${CMAKE_SOURCE_DIR}/third-party/lzma) add_definitions(-D_7ZIP_PPMD_SUPPPORT) set(LZMA_SRC - ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-lzma.c ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zAlloc.c ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zArcIn.c ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zBuf.c@@ -270,12 +271,17 @@ ${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7.c
${CMAKE_SOURCE_DIR}/src/third-party/lzma/Ppmd7Dec.c ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zFile.c ${CMAKE_SOURCE_DIR}/src/third-party/lzma/7zStream.c) - list(APPEND UTIL_SRC ${LZMA_SRC}) - add_definitions(-DENABLE_LZMA) + list(APPEND FEATURE_SRC ${LZMA_SRC}) + list(APPEND FEATURES LZMA) endif() +set(FEATURE_DEFINES) +foreach(FEATURE IN LISTS FEATURES) + list(APPEND FEATURE_DEFINES "USE_${FEATURE}") +endforeach() + # Binaries -set(SRC +set(CORE_SRC ${ARM_SRC} ${GBA_SRC} ${GBA_RR_SRC}@@ -287,6 +293,10 @@ ${VFS_SRC}
${OS_SRC} ${THIRD_PARTY_SRC}) +set(SRC + ${CORE_SRC} + ${FEATURE_SRC}) + if(NOT BUILD_STATIC AND NOT BUILD_SHARED) set(BUILD_SHARED ON) endif()@@ -295,6 +305,7 @@ if(BUILD_SHARED)
add_library(${BINARY_NAME} SHARED ${SRC}) if(BUILD_STATIC) add_library(${BINARY_NAME}-static STATIC ${SRC}) + target_compile_definitions(${BINARY_NAME}-static PRIVATE ${FEATURE_DEFINES}) install(TARGETS ${BINARY_NAME}-static DESTINATION lib COMPONENT lib${BINARY_NAME}) endif() else()@@ -302,15 +313,16 @@ add_library(${BINARY_NAME} STATIC ${SRC})
endif() target_link_libraries(${BINARY_NAME} m ${DEBUGGER_LIB} ${OS_LIB} ${DEPENDENCY_LIB}) +target_compile_definitions(${BINARY_NAME} PRIVATE ${FEATURE_DEFINES}) install(TARGETS ${BINARY_NAME} DESTINATION lib COMPONENT lib${BINARY_NAME}) set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI}) if(BUILD_LIBRETRO) - add_definitions(-DCOLOR_16_BIT -DCOLOR_5_6_5) file(GLOB RETRO_SRC ${CMAKE_SOURCE_DIR}/src/platform/libretro/*.c) - add_library(${BINARY_NAME}_libretro SHARED ${RETRO_SRC}) - set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "") - target_link_libraries(${BINARY_NAME}_libretro ${BINARY_NAME} m ${DEBUGGER_LIB} ${OS_LIB} ${DEPENDENCY_LIB}) + add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC}) + set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "") + target_compile_definitions(${BINARY_NAME}_libretro PRIVATE COLOR_16_BIT;COLOR_5_6_5 PUBLIC "" INTERFACE "") + target_link_libraries(${BINARY_NAME}_libretro m ${OS_LIB}) endif() if(BUILD_SDL)
@@ -177,7 +177,7 @@ }
if (threadContext->movie) { struct VDir* movieDir = VDirOpen(threadContext->movie); -#ifdef ENABLE_LIBZIP +#ifdef USE_LIBZIP if (!movieDir) { movieDir = VDirOpenZip(threadContext->movie, 0); }@@ -341,12 +341,12 @@ threadContext->stateDir = threadContext->gameDir;
} else { threadContext->rom = VFileOpen(args->fname, O_RDONLY); threadContext->gameDir = 0; -#if ENABLE_LIBZIP +#if USE_LIBZIP if (!threadContext->gameDir) { threadContext->gameDir = VDirOpenZip(args->fname, 0); } #endif -#if ENABLE_LZMA +#if USE_LZMA if (!threadContext->gameDir) { threadContext->gameDir = VDirOpen7z(args->fname, 0); }
@@ -109,6 +109,7 @@ if(WIN32)
list(APPEND RESOURCES ${CMAKE_SOURCE_DIR}/res/mgba.rc) endif() add_executable(${BINARY_NAME}-qt WIN32 MACOSX_BUNDLE main.cpp ${CMAKE_SOURCE_DIR}/res/mgba.icns ${SOURCE_FILES} ${PLATFORM_SRC} ${UI_FILES} ${AUDIO_SRC} ${RESOURCES}) +target_compile_definitions(${BINARY_NAME}-qt PRIVATE ${FEATURE_DEFINES}) set_target_properties(${BINARY_NAME}-qt PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/res/info.plist.in) list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::OpenGL)
@@ -216,12 +216,12 @@ m_threadContext.gameDir = VDirOpen(m_threadContext.fname);
m_threadContext.stateDir = m_threadContext.gameDir; } else { m_threadContext.rom = VFileOpen(m_threadContext.fname, O_RDONLY); -#if ENABLE_LIBZIP +#if USE_LIBZIP if (!m_threadContext.gameDir) { m_threadContext.gameDir = VDirOpenZip(m_threadContext.fname, 0); } #endif -#if ENABLE_LZMA +#if USE_LZMA if (!m_threadContext.gameDir) { m_threadContext.gameDir = VDirOpen7z(m_threadContext.fname, 0); }
@@ -38,6 +38,7 @@ set(EGL_MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/sdl/egl-sdl.c)
set(EGL_LIBRARY "-lEGL -lGLESv2 -lbcm_host") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fgnu89-inline") add_executable(${BINARY_NAME}-rpi ${PLATFORM_SRC} ${MAIN_SRC} ${EGL_MAIN_SRC}) + target_compile_definitions(${BINARY_NAME}-rpi PRIVATE ${FEATURE_DEFINES}) target_link_libraries(${BINARY_NAME}-rpi ${BINARY_NAME} ${PLATFORM_LIBRARY} ${EGL_LIBRARY}) install(TARGETS ${BINARY_NAME}-rpi DESTINATION bin COMPONENT ${BINARY_NAME}-rpi) endif()@@ -52,6 +53,7 @@ include_directories(${OPENGL_INCLUDE_DIR})
endif() add_executable(${BINARY_NAME}-sdl WIN32 ${PLATFORM_SRC} ${MAIN_SRC}) +target_compile_definitions(${BINARY_NAME}-sdl PRIVATE ${FEATURE_DEFINES}) target_link_libraries(${BINARY_NAME}-sdl ${BINARY_NAME} ${PLATFORM_LIBRARY} ${OPENGL_LIBRARY}) set_target_properties(${BINARY_NAME}-sdl PROPERTIES OUTPUT_NAME ${BINARY_NAME}) install(TARGETS ${BINARY_NAME}-sdl DESTINATION bin COMPONENT ${BINARY_NAME}-sdl)
@@ -42,11 +42,11 @@ struct VFile* VFileFromMemory(void* mem, size_t size);
struct VDir* VDirOpen(const char* path); -#ifdef ENABLE_LIBZIP +#ifdef USE_LIBZIP struct VDir* VDirOpenZip(const char* path, int flags); #endif -#ifdef ENABLE_LZMA +#ifdef USE_LZMA struct VDir* VDirOpen7z(const char* path, int flags); #endif
@@ -5,7 +5,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/vfs.h" -#ifdef ENABLE_LZMA +#ifdef USE_LZMA #include "util/string.h"
@@ -5,7 +5,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "util/vfs.h" -#ifdef ENABLE_LIBZIP +#ifdef USE_LIBZIP #include <zip.h>