From 493c12916ce020d28ef8cf28980d46ac57a65a3b Mon Sep 17 00:00:00 2001 From: KatieFrogs <23621460+KatieFrogs@users.noreply.github.com> Date: Mon, 25 Oct 2021 10:06:59 +0300 Subject: [PATCH 1/2] Cmake: Build mpg123 and jansson for wasm target --- .github/workflows/cmake-wasm.yml | 15 ++++++++ CMakeLists.txt | 3 +- cli/CMakeLists.txt | 1 + cmake/dependencies/jansson.cmake | 61 ++++++++++++++++++++++++++------ cmake/dependencies/mpg123.cmake | 15 +++++++- src/CMakeLists.txt | 26 +++++++------- 6 files changed, 96 insertions(+), 25 deletions(-) diff --git a/.github/workflows/cmake-wasm.yml b/.github/workflows/cmake-wasm.yml index 9b4d1cec..8f1e15c4 100644 --- a/.github/workflows/cmake-wasm.yml +++ b/.github/workflows/cmake-wasm.yml @@ -49,6 +49,13 @@ jobs: ${{runner.workspace}}/embuild/dependencies/ffmpeg/bin/usr/local/lib key: wasm-ffmpeg-${{ hashFiles('cmake/dependencies/ffmpeg.cmake') }} + - name: Cache jansson + uses: actions/cache@v2 + with: + path: | + ${{runner.workspace}}/embuild/dependencies/jansson/src/.libs + key: wasm-jansson-${{ hashFiles('cmake/dependencies/jansson.cmake') }} + - name: Cache atrac9 uses: actions/cache@v2 with: @@ -63,6 +70,14 @@ jobs: ${{runner.workspace}}/embuild/dependencies/libg719_decode/libg719_decode.a key: wasm-g719-${{ hashFiles('cmake/dependencies/g719.cmake') }} + - name: Cache mpg123 + uses: actions/cache@v2 + with: + path: | + ${{runner.workspace}}/dependencies/mpg123 + ${{runner.workspace}}/embuild/dependencies/mpg123/src/libmpg123/.libs + key: wasm-mpg123-${{ hashFiles('cmake/dependencies/mpg123.cmake') }} + - name: Cache speex uses: actions/cache@v2 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f942078..e90cedbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,7 @@ if(NOT WIN32) set(CELT0061_PATH CACHE PATH "Path to CELT version 0.6.1") set(CELT0110_PATH CACHE PATH "Path to CELT version 0.11.0") set(LIBAO_PATH CACHE PATH "Path to libao") + set(JANSSON_PATH CACHE PATH "Path to jansson") endif() # Build choices @@ -99,8 +100,6 @@ else() endif() if(EMSCRIPTEN) - set(USE_MPEG OFF) - set(USE_JANSSON OFF) set(BUILD_V123 OFF) set(BUILD_AUDACIOUS OFF) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index c83b39b9..9b360758 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -19,6 +19,7 @@ target_link_libraries(vgmstream_cli libvgmstream) # Link to Jansson, if we have it if (USE_JANSSON AND JANSSON_FOUND) target_compile_definitions(vgmstream_cli PRIVATE HAVE_JSON) + target_include_directories(vgmstream_cli PRIVATE ${JANSSON_INCLUDE_DIRS}) target_link_libraries(vgmstream_cli jansson) endif() diff --git a/cmake/dependencies/jansson.cmake b/cmake/dependencies/jansson.cmake index 4aab2a6b..42fb8b7c 100644 --- a/cmake/dependencies/jansson.cmake +++ b/cmake/dependencies/jansson.cmake @@ -1,15 +1,56 @@ if(NOT WIN32 AND USE_JANSSON) - find_package(PkgConfig REQUIRED) - pkg_check_modules(JANSSON jansson>=2.3) - - if(JANSSON_FOUND) - set(JANSSON_SOURCE "(system)") - set(JANSSON_PKG libjansson) + if(NOT JANSSON_PATH AND NOT EMSCRIPTEN) + find_package(PkgConfig REQUIRED) + pkg_check_modules(JANSSON jansson>=2.3) - include_directories(${JANSSON_INCLUDE_DIRS}) - link_directories(${JANSSON_LIBRARY_DIRS}) - else() - set(USE_JANSSON OFF) + if(JANSSON_FOUND) + set(JANSSON_SOURCE "(system)") + set(JANSSON_PKG libjansson) + + link_directories(${JANSSON_LIBRARY_DIRS}) + endif() + endif() + if(JANSSON_PATH OR EMSCRIPTEN OR NOT JANSSON_FOUND) + FetchDependency(JANSSON + DIR jansson + GIT_REPOSITORY https://github.com/akheron/jansson + GIT_TAG 684e18c927e89615c2d501737e90018f4930d6c5 + ) + + if(JANSSON_PATH) + set(JANSSON_LINK_PATH ${JANSSON_BIN}/src/.libs/libjansson.a) + set(JANSSON_INCLUDE_DIRS ${JANSSON_PATH}/src) + + if(NOT EXISTS ${JANSSON_PATH}/configure) + add_custom_target(JANSSON_AUTORECONF + COMMAND autoreconf -iv + BYPRODUCTS ${JANSSON_PATH}/configure + WORKING_DIRECTORY ${JANSSON_PATH} + ) + endif() + + file(MAKE_DIRECTORY ${JANSSON_BIN}) + add_custom_target(JANSSON_CONFIGURE + COMMAND "${JANSSON_PATH}/configure" --enable-static --disable-shared CC="${CMAKE_C_COMPILER}" AR="${CMAKE_AR}" RANLIB="${CMAKE_RANLIB}" + DEPENDS ${JANSSON_PATH}/configure + BYPRODUCTS ${JANSSON_BIN}/Makefile + WORKING_DIRECTORY ${JANSSON_BIN} + ) + add_custom_target(JANSSON_MAKE + COMMAND make + DEPENDS ${JANSSON_BIN}/Makefile + BYPRODUCTS ${JANSSON_LINK_PATH} ${JANSSON_BIN} + WORKING_DIRECTORY ${JANSSON_BIN} + ) + + add_library(jansson STATIC IMPORTED) + if(NOT EXISTS ${JANSSON_LINK_PATH}) + add_dependencies(jansson JANSSON_MAKE) + endif() + set_target_properties(jansson PROPERTIES + IMPORTED_LOCATION ${JANSSON_LINK_PATH} + ) + endif() endif() endif() if(NOT USE_JANSSON) diff --git a/cmake/dependencies/mpg123.cmake b/cmake/dependencies/mpg123.cmake index 9d04f038..143360c5 100644 --- a/cmake/dependencies/mpg123.cmake +++ b/cmake/dependencies/mpg123.cmake @@ -36,9 +36,22 @@ if(NOT WIN32 AND USE_MPEG) ) endif() + set(MPEG_CONFIGURE + --enable-static + --disable-shared + CC="${CMAKE_C_COMPILER}" + AR="${CMAKE_AR}" + RANLIB="${CMAKE_RANLIB}" + ) + if(EMSCRIPTEN) + list(APPEND MPEG_CONFIGURE + --with-cpu=generic_fpu + ) + endif() + file(MAKE_DIRECTORY ${MPEG_BIN}) add_custom_target(MPEG_CONFIGURE - COMMAND "${MPEG_PATH}/configure" --enable-static --disable-shared CC="${CMAKE_C_COMPILER}" AR="${CMAKE_AR}" + COMMAND "${MPEG_PATH}/configure" ${MPEG_CONFIGURE} DEPENDS ${MPEG_PATH}/configure BYPRODUCTS ${MPEG_BIN}/Makefile WORKING_DIRECTORY ${MPEG_BIN} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2413c773..f09d3eed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,16 +60,18 @@ setup_target(libvgmstream) target_include_directories(libvgmstream PRIVATE ${libvgmstream_includes}) # libvgmstream.so -add_library(libvgmstream_shared SHARED EXCLUDE_FROM_ALL ${libvgmstream_sources}) -set_target_properties(libvgmstream_shared PROPERTIES - PREFIX "" - OUTPUT_NAME "libvgmstream" -) - -if(USE_FFMPEG AND FFMPEG_COMPILE) - add_dependencies(libvgmstream_shared avcodec) +if(NOT EMSCRIPTEN) + add_library(libvgmstream_shared SHARED EXCLUDE_FROM_ALL ${libvgmstream_sources}) + set_target_properties(libvgmstream_shared PROPERTIES + PREFIX "" + OUTPUT_NAME "libvgmstream" + ) + + if(USE_FFMPEG AND FFMPEG_COMPILE) + add_dependencies(libvgmstream_shared avcodec) + endif() + + setup_target(libvgmstream_shared TRUE) + + target_include_directories(libvgmstream_shared PRIVATE ${libvgmstream_includes}) endif() - -setup_target(libvgmstream_shared TRUE) - -target_include_directories(libvgmstream_shared PRIVATE ${libvgmstream_includes}) From 21af22ac2b3ec160914b7e3d754af49d17020791 Mon Sep 17 00:00:00 2001 From: KatieFrogs <23621460+KatieFrogs@users.noreply.github.com> Date: Mon, 25 Oct 2021 11:03:15 +0300 Subject: [PATCH 2/2] Fix jansson not building --- cli/CMakeLists.txt | 2 +- cmake/dependencies/jansson.cmake | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 9b360758..af06a841 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -17,7 +17,7 @@ endif() target_link_libraries(vgmstream_cli libvgmstream) # Link to Jansson, if we have it -if (USE_JANSSON AND JANSSON_FOUND) +if (USE_JANSSON) target_compile_definitions(vgmstream_cli PRIVATE HAVE_JSON) target_include_directories(vgmstream_cli PRIVATE ${JANSSON_INCLUDE_DIRS}) target_link_libraries(vgmstream_cli jansson) diff --git a/cmake/dependencies/jansson.cmake b/cmake/dependencies/jansson.cmake index 42fb8b7c..0d87c16c 100644 --- a/cmake/dependencies/jansson.cmake +++ b/cmake/dependencies/jansson.cmake @@ -6,7 +6,6 @@ if(NOT WIN32 AND USE_JANSSON) if(JANSSON_FOUND) set(JANSSON_SOURCE "(system)") set(JANSSON_PKG libjansson) - link_directories(${JANSSON_LIBRARY_DIRS}) endif() endif()