diff --git a/CMakeLists.txt b/CMakeLists.txt index ab4f6bec..c862ba12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,7 @@ find_package(Sanitizers) option(BUILD_LIBAUDIO "build audio output library" ON) option(BUILD_LIBEMU "build sound emulation library" ON) option(BUILD_LIBPLAYER "build player library" ON) +option(BUILD_LIBVGM "build unified libvgm library" ON) option(BUILD_TESTS "build test programs" OFF) option(BUILD_PLAYER "build player application" ON) option(BUILD_VGM2WAV "build sample vgm2wav application" ON) @@ -116,30 +117,35 @@ option(USE_SANITIZERS "use sanitizers" ON) # --- main library --- add_subdirectory(utils) if(USE_SANITIZERS) - add_sanitizers(utils) + add_sanitizers(vgm-utils_objlib) endif(USE_SANITIZERS) if(BUILD_LIBAUDIO) add_subdirectory(audio) if(USE_SANITIZERS) - add_sanitizers(vgm-audio) + add_sanitizers(vgm-audio_objlib) endif(USE_SANITIZERS) endif() if(BUILD_LIBEMU) add_subdirectory(emu) if(USE_SANITIZERS) - add_sanitizers(vgm-emu) + add_sanitizers(vgm-emu_objlib) endif(USE_SANITIZERS) endif() if(BUILD_LIBPLAYER) add_subdirectory(player) if(USE_SANITIZERS) - add_sanitizers(vgm-player) + add_sanitizers(vgm-player_objlib) endif(USE_SANITIZERS) endif() +if(BUILD_LIBVGM) + add_subdirectory(vgm) + # sanitizers are included via being added to objlib targets +endif() + # --- additional stuff --- if(BUILD_TESTS) diff --git a/audio/CMakeLists.txt b/audio/CMakeLists.txt index e6dfc473..83b5bcf9 100644 --- a/audio/CMakeLists.txt +++ b/audio/CMakeLists.txt @@ -144,30 +144,33 @@ if(AUDIODRV_LIBAO) set(AUDIO_PC_REQUIRES ${AUDIO_PC_REQUIRES} "ao") endif() +add_library(${PROJECT_NAME}_objlib OBJECT ${AUDIO_FILES}) +set_target_properties(${PROJECT_NAME}_objlib PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_compile_definitions(${PROJECT_NAME}_objlib PUBLIC ${AUDIO_DEFS}) +target_include_directories(${PROJECT_NAME}_objlib PRIVATE ${AUDIO_INCLUDES}) +target_link_libraries(${PROJECT_NAME}_objlib PRIVATE ${AUDIO_LIBS}) -add_library(${PROJECT_NAME} ${LIBRARY_TYPE} ${AUDIO_FILES}) -set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) +add_library(${PROJECT_NAME} ${LIBRARY_TYPE} $) target_compile_definitions(${PROJECT_NAME} PUBLIC ${AUDIO_DEFS}) target_include_directories(${PROJECT_NAME} PUBLIC $ $ - PRIVATE ${AUDIO_INCLUDES} ) -target_link_libraries(${PROJECT_NAME} PRIVATE ${AUDIO_LIBS} vgm-utils) +target_link_libraries(${PROJECT_NAME} PRIVATE vgm-utils ${AUDIO_LIBS}) if(WIN32) # for some Windows Audio APIs, we need WinAPI headers from special directories if(NOT MSVC) - target_include_directories(${PROJECT_NAME} PRIVATE + target_include_directories(${PROJECT_NAME}_objlib PRIVATE ${LIBVGM_SOURCE_DIR}/libs/include ${LIBVGM_SOURCE_DIR}/libs/include_mingw ) elseif(MSVC) - target_include_directories(${PROJECT_NAME} PRIVATE + target_include_directories(${PROJECT_NAME}_objlib PRIVATE ${LIBVGM_SOURCE_DIR}/libs/include ${LIBVGM_SOURCE_DIR}/libs/include_vc ) if(MSVC_VERSION LESS 1400) - target_include_directories(${PROJECT_NAME} PRIVATE + target_include_directories(${PROJECT_NAME}_objlib PRIVATE ${LIBVGM_SOURCE_DIR}/libs/include_vc6 ) endif() @@ -187,7 +190,7 @@ pkgcfg_configure("${LIBVGM_SOURCE_DIR}/cmake/libvgm.pc.in" "${CMAKE_CURRENT_BINA PKGS_PUB vgm-utils ) -install(TARGETS ${PROJECT_NAME} +install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_objlib EXPORT "${LIBVGM_NAME}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" diff --git a/emu/CMakeLists.txt b/emu/CMakeLists.txt index 9355d421..37ce77cb 100644 --- a/emu/CMakeLists.txt +++ b/emu/CMakeLists.txt @@ -3,7 +3,7 @@ project(vgm-emu) set(EMU_PC_CFLAGS) set(EMU_PC_LDFLAGS) - +set(EMU_LIBS) # Note: If multiple cores are present for a device, the core chosed by default is marked with *. @@ -598,22 +598,26 @@ if(SNDEMU_GA20_ALL) set(EMU_CORE_HEADERS ${EMU_CORE_HEADERS} cores/iremga20.h) endif() - -add_library(${PROJECT_NAME} ${LIBRARY_TYPE} ${EMU_FILES}) -set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) -target_compile_definitions(${PROJECT_NAME} PUBLIC ${EMU_DEFS}) -target_include_directories(${PROJECT_NAME} - PUBLIC $ $ - PRIVATE ${LIBVGM_SOURCE_DIR}/libs/include -) - if(CMAKE_COMPILER_IS_GNUCC OR UNIX) # link Math library - target_link_libraries(${PROJECT_NAME} PRIVATE m) + set(EMU_LIBS "m") set(EMU_PC_LDFLAGS "-lm") endif() +add_library(${PROJECT_NAME}_objlib OBJECT ${EMU_FILES}) +set_target_properties(${PROJECT_NAME}_objlib PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_compile_definitions(${PROJECT_NAME}_objlib PUBLIC ${EMU_DEFS}) +target_include_directories(${PROJECT_NAME}_objlib PRIVATE ${LIBVGM_SOURCE_DIR}/libs/include) +target_link_libraries(${PROJECT_NAME}_objlib PRIVATE ${EMU_LIBS}) + +add_library(${PROJECT_NAME} ${LIBRARY_TYPE} $) +target_compile_definitions(${PROJECT_NAME} PUBLIC ${EMU_DEFS}) +target_include_directories(${PROJECT_NAME} + PUBLIC $ $ +) +target_link_libraries(${PROJECT_NAME} PRIVATE ${EMU_LIBS}) + pkgcfg_configure("${LIBVGM_SOURCE_DIR}/cmake/libvgm.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/vgm-emu.pc" NAME "LibVGM Emu" DESC "LibVGM sound chip emulation library" @@ -624,7 +628,7 @@ pkgcfg_configure("${LIBVGM_SOURCE_DIR}/cmake/libvgm.pc.in" "${CMAKE_CURRENT_BINA LDFLAGS_PUB "-l${PROJECT_NAME}" ) -install(TARGETS ${PROJECT_NAME} +install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_objlib EXPORT "${LIBVGM_NAME}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" diff --git a/player/CMakeLists.txt b/player/CMakeLists.txt index 2df6b889..ab2310f0 100644 --- a/player/CMakeLists.txt +++ b/player/CMakeLists.txt @@ -30,15 +30,18 @@ set(PLAYER_PC_CFLAGS) set(PLAYER_PC_LDFLAGS) -add_library(${PROJECT_NAME} ${LIBRARY_TYPE} ${PLAYER_FILES}) -set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) +add_library(${PROJECT_NAME}_objlib OBJECT ${PLAYER_FILES}) +set_target_properties(${PROJECT_NAME}_objlib PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_compile_definitions(${PROJECT_NAME}_objlib PUBLIC ${PLAYER_DEFS}) +target_include_directories(${PROJECT_NAME}_objlib PRIVATE ${PLAYER_INCLUDES}) +target_link_libraries(${PROJECT_NAME}_objlib PRIVATE ${PLAYER_LIBS}) + +add_library(${PROJECT_NAME} ${LIBRARY_TYPE} $) target_compile_definitions(${PROJECT_NAME} PUBLIC ${PLAYER_DEFS}) target_include_directories(${PROJECT_NAME} PUBLIC $ $ - PRIVATE ${PLAYER_INCLUDES} ) -target_link_libraries(${PROJECT_NAME} PRIVATE ${PLAYER_LIBS} vgm-emu vgm-utils) - +target_link_libraries(${PROJECT_NAME} PRIVATE vgm-emu vgm-utils ${PLAYER_LIBS}) pkgcfg_configure("${LIBVGM_SOURCE_DIR}/cmake/libvgm.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/vgm-player.pc" NAME "LibVGM Player" @@ -51,7 +54,7 @@ pkgcfg_configure("${LIBVGM_SOURCE_DIR}/cmake/libvgm.pc.in" "${CMAKE_CURRENT_BINA PKGS_PRIV ${UTILS_PC_REQUIRES} vgm-emu vgm-utils ) -install(TARGETS ${PROJECT_NAME} +install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_objlib EXPORT "${LIBVGM_NAME}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 6d97778c..0fac5cbc 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -88,16 +88,18 @@ endif() endif(UTIL_CHARSET_CONV) +add_library(${PROJECT_NAME}_objlib OBJECT ${UTIL_FILES}) +set_target_properties(${PROJECT_NAME}_objlib PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_compile_definitions(${PROJECT_NAME}_objlib PUBLIC ${UTIL_DEFS}) +target_include_directories(${PROJECT_NAME}_objlib PRIVATE ${UTIL_INCLUDES}) +target_link_libraries(${PROJECT_NAME}_objlib PRIVATE ${UTIL_LIBS}) -add_library(${PROJECT_NAME} ${LIBRARY_TYPE} ${UTIL_FILES}) -set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) +add_library(${PROJECT_NAME} ${LIBRARY_TYPE} $) target_compile_definitions(${PROJECT_NAME} PUBLIC ${UTIL_DEFS}) target_include_directories(${PROJECT_NAME} PUBLIC $ $ - PRIVATE ${UTIL_INCLUDES} ) -target_link_libraries(${PROJECT_NAME} PUBLIC ${UTIL_LIBS}) - +target_link_libraries(${PROJECT_NAME} PRIVATE ${UTIL_LIBS}) pkgcfg_configure("${LIBVGM_SOURCE_DIR}/cmake/libvgm.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/vgm-utils.pc" NAME "LibVGM Utils" @@ -110,7 +112,7 @@ pkgcfg_configure("${LIBVGM_SOURCE_DIR}/cmake/libvgm.pc.in" "${CMAKE_CURRENT_BINA PKGS_PRIV ${UTIL_PC_PKGS} ) -install(TARGETS ${PROJECT_NAME} +install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_objlib EXPORT "${LIBVGM_NAME}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" @@ -119,3 +121,4 @@ install(TARGETS ${PROJECT_NAME} set(LIBVGM_INSTALL_TARGETS ${LIBVGM_INSTALL_TARGETS} "${PROJECT_NAME}" PARENT_SCOPE) install(FILES ${UTIL_HEADERS} DESTINATION "${LIBVGM_INSTALL_INCLUDE_DIR}/utils") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/vgm-utils.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + diff --git a/vgm/CMakeLists.txt b/vgm/CMakeLists.txt new file mode 100644 index 00000000..5f01dc07 --- /dev/null +++ b/vgm/CMakeLists.txt @@ -0,0 +1,23 @@ +### Wrapper library +project(vgm) + +add_library(${PROJECT_NAME} ${LIBRARY_TYPE}) + +target_link_libraries(${PROJECT_NAME} PRIVATE vgm-utils_objlib) + +if(BUILD_LIBAUDIO) + target_link_libraries(${PROJECT_NAME} PRIVATE vgm-audio_objlib) +endif() +if(BUILD_LIBEMU) + target_link_libraries(${PROJECT_NAME} PRIVATE vgm-emu_objlib) +endif() +if(BUILD_LIBPLAYER) + target_link_libraries(${PROJECT_NAME} PRIVATE vgm-player_objlib) +endif() + +install(TARGETS ${PROJECT_NAME} + EXPORT "${LIBVGM_NAME}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + )