Skip to content

Commit

Permalink
Refactor buildsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
complexlogic committed Sep 9, 2023
1 parent 5c719b2 commit cd3694b
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 26 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ permissions:
security-events: none
statuses: read

env:
VCPKG_COMMITTISH: 962e5e39f8a25f42522f51fffc574e05a3efd26b

jobs:
build_windows:
name: Windows
Expand All @@ -49,7 +52,8 @@ jobs:

- name: Setup vcpkg
uses: friendlyanon/setup-vcpkg@v1
with: { committish: 51de327421f4bd99b828a97b4e4adde54db032a6 }
with:
committish: ${{env.VCPKG_COMMITTISH}}

- name: Setup Overlays
uses: actions/checkout@v3
Expand Down Expand Up @@ -120,7 +124,7 @@ jobs:
- name: "Install dependencies"
run: |
if [[ "${{matrix.config.name}}" == "Debian" ]]; then
apt update && apt install -y curl zip unzip tar build-essential git cmake pkg-config libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libebur128-dev libinih-dev
apt update && apt install -y curl zip unzip tar build-essential git cmake pkg-config libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libebur128-dev libtag1-dev libinih-dev
fi
if [[ "${{matrix.config.name}}" == "Fedora" ]]; then
dnf install -y curl zip unzip tar git make pkg-config gcc-c++ fedora-packager rpmdevtools cmake libavcodec-free-devel libavformat-free-devel libswresample-free-devel libavutil-free-devel libebur128-devel taglib-devel inih-devel
Expand All @@ -129,7 +133,7 @@ jobs:
- name: Setup vcpkg
uses: friendlyanon/setup-vcpkg@v1
with:
committish: ${{env.VCPKG_COMMITISH}}
committish: ${{env.VCPKG_COMMITTISH}}
cache-key: vcpkg-${{matrix.config.name}}-${{env.VCPKG_COMMITISH}}
cache-restore-keys: vcpkg-${{matrix.config.name}}-${{env.VCPKG_COMMITISH}}

Expand Down
54 changes: 39 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# This file is released under the 2 clause BSD license, see COPYING

cmake_minimum_required(VERSION 3.13)
option(VCPKG "Build dependencies with vcpkg" OFF)
if (VCPKG)
include("${CMAKE_SOURCE_DIR}/config/vcpkg.cmake")
endif ()

project(rsgain
VERSION 3.3
DESCRIPTION "ReplayGain 2.0 loudness normalizer"
Expand Down Expand Up @@ -38,6 +43,27 @@ if (WIN32)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${EXECUTABLE_TITLE})
endif ()

# Embed Git information
find_package(Git QUIET)
if (Git_FOUND)
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --long --tags
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_OUTPUT
RESULT_VARIABLE GIT_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (GIT_RESULT EQUAL 0)
string(REPLACE "-" ";" GIT_LIST "${GIT_OUTPUT}")
list(GET GIT_LIST 1 COMMITS_SINCE_TAG)
if (NOT COMMITS_SINCE_TAG STREQUAL "0")
list(GET GIT_LIST 2 COMMIT_HASH)
string(REPLACE "g" "" COMMIT_HASH "${COMMIT_HASH}")
add_compile_definitions(COMMITS_SINCE_TAG=\"${COMMITS_SINCE_TAG}\")
add_compile_definitions(COMMIT_HASH=\"${COMMIT_HASH}\")
endif ()
endif ()
endif ()

# Find dependencies - Windows
if (WIN32)
find_path(FFMPEG_INCLUDE_DIR "libavformat/avformat.h" REQUIRED)
Expand All @@ -63,10 +89,6 @@ if (WIN32)

# Find dependencies - Linux/Mac
elseif (UNIX)
if (APPLE)
link_directories(/usr/local/lib) # Fix linking on 10.14+. See https://stackoverflow.com/questions/54068035
endif (APPLE)

find_package(PkgConfig MODULE REQUIRED)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -143,8 +165,10 @@ elseif (UNIX)
# Build Debian packages
if (PACKAGE STREQUAL "DEB")
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_DEBIAN_PACKAGE_VERSION ${CMAKE_PROJECT_VERSION})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libavcodec59 (>= 5.1), libavutil57 (>= 5.1), libswresample4 (>= 5.1), libavformat59 (>= 5.1), libebur128-1 (>=1.2.4), libinih1, libc6 (>=2.29), libstdc++6 (>=10.2), zlib1g")
if (COMMITS_SINCE_TAG AND COMMIT_HASH)
set(CPACK_DEBIAN_PACKAGE_VERSION "${PROJECT_VERSION}-r${COMMITS_SINCE_TAG}-${COMMIT_HASH}")
endif ()
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libavcodec59 (>= 5.1), libavutil57 (>= 5.1), libswresample4 (>= 5.1), libavformat59 (>= 5.1), libebur128-1 (>=1.2.4), libtag1v5, libinih1, libc6 (>=2.29), libstdc++6 (>=10.2), zlib1g")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "complexlogic")
set(CPACK_DEBIAN_PACKAGE_SECTION "utils")
set(CPACK_DEBIAN_ARCHIVE_TYPE "gnutar")
Expand All @@ -154,10 +178,13 @@ elseif (UNIX)
# Build Fedora packages
elseif (PACKAGE STREQUAL "RPM")
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
if (COMMITS_SINCE_TAG AND COMMIT_HASH)
set(CPACK_RPM_PACKAGE_VERSION "${PROJECT_VERSION}-r${COMMITS_SINCE_TAG}-${COMMIT_HASH}")
endif ()
set(CPACK_RPM_PACKAGE_LICENSE "BSD")
set(CPACK_RPM_PACKAGE_GROUP "Applications/Multimedia")
set(CPACK_RPM_PACKAGE_AUTOREQPROV 0)
set(CPACK_RPM_PACKAGE_REQUIRES "libavcodec-free >= 6, libavformat-free >= 6, libswresample-free >= 6, libavutil-free >= 6, libebur128, zlib, inih")
set(CPACK_RPM_PACKAGE_REQUIRES "libavcodec-free >= 6, libavformat-free >= 6, libswresample-free >= 6, libavutil-free >= 6, libebur128, taglib, zlib, inih")
endif ()
if (PACKAGE)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_DESCRIPTION})
Expand All @@ -167,14 +194,11 @@ elseif (UNIX)
include(CPack)
endif ()

# Provide 'uninstall' target
if(NOT TARGET uninstall)
configure_file(
"${PROJECT_SOURCE_DIR}/config/cmake_uninstall.cmake.in"
"${PROJECT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
configure_file(
"${PROJECT_SOURCE_DIR}/config/cmake_uninstall.cmake.in"
"${PROJECT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake_uninstall.cmake)
endif()

configure_file("${PROJECT_SOURCE_DIR}/config/config.h.in" "${PROJECT_BINARY_DIR}/config.h")
28 changes: 28 additions & 0 deletions config/vcpkg.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
message("Setting up vcpkg...")
include(FetchContent)
FetchContent_Declare(
vcpkg
GIT_REPOSITORY https://github.com/microsoft/vcpkg.git
GIT_SHALLOW TRUE
SOURCE_DIR ${PROJECT_BINARY_DIR}
)
FetchContent_Declare(
vcpkg_overlay
GIT_REPOSITORY https://github.com/complexlogic/vcpkg.git
GIT_TAG origin/rsgain
GIT_SHALLOW TRUE
SOURCE_DIR ${PROJECT_BINARY_DIR}
)
FetchContent_MakeAvailable(vcpkg vcpkg_overlay)
set(VCPKG_OVERLAY_PORTS "${CMAKE_BINARY_DIR}/_deps/vcpkg_overlay-src/ports")

if (WIN32)
if (NOT VCPKG_OVERLAY_TRIPLETS)
list(APPEND VCPKG_OVERLAY_TRIPLETS "${CMAKE_SOURCE_DIR}/config/vcpkg_triplets")
endif ()
if (NOT VCPKG_TARGET_TRIPLET)
set (VCPKG_TARGET_TRIPLET "custom-triplet")
endif ()
endif ()

set(CMAKE_TOOLCHAIN_FILE "${CMAKE_BINARY_DIR}/_deps/vcpkg-src/scripts/buildsystems/vcpkg.cmake")
3 changes: 1 addition & 2 deletions docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ cd build
Build the dependencies and generate the Visual Studio project files:

```bash
git clone https://github.com/microsoft/vcpkg
cmake .. -DCMAKE_TOOLCHAIN_FILE=".\vcpkg\scripts\buildsystems\vcpkg.cmake" -DVCPKG_OVERLAY_TRIPLETS="..\config\vcpkg_triplets" -DVCPKG_TARGET_TRIPLET="custom-triplet"
cmake .. -DVCPKG=ON
```

Build and test the program:
Expand Down
9 changes: 8 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
set(SOURCE_FILES
rsgain.cpp
rsgain.hpp
scan.cpp
scan.hpp
output.cpp
output.hpp
tag.cpp
tag.hpp
easymode.cpp
easymode.hpp
)
if (WIN32)
add_executable(${EXECUTABLE_TITLE} ${SOURCE_FILES} "${PROJECT_BINARY_DIR}/rsgain.manifest" "${PROJECT_BINARY_DIR}/versioninfo.rc")
Expand Down Expand Up @@ -31,6 +36,7 @@ if (WIN32)
if (VCPKG_TARGET_TRIPLET STREQUAL "custom-triplet")
target_link_libraries(${EXECUTABLE_TITLE} ${STATIC_LIBS})
endif ()
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)

elseif (UNIX)
add_executable(${EXECUTABLE_TITLE} ${SOURCE_FILES})
Expand All @@ -50,7 +56,8 @@ elseif (UNIX)
)
endif()
set (EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}")

string(TIMESTAMP BUILD_DATE "%Y-%m-%d")
add_compile_definitions("BUILD_DATE=\"${BUILD_DATE}\"")
if (MAXPROGBARWIDTH GREATER_EQUAL 20)
target_compile_definitions(${EXECUTABLE_TITLE} PUBLIC "MAXPROGBARWIDTH=${MAXPROGBARWIDTH}")
endif ()
9 changes: 7 additions & 2 deletions src/rsgain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,12 @@ static void version() {
int ebur128_v_major = 0;
int ebur128_v_minor = 0;
int ebur128_v_patch = 0;
fmt::print(COLOR_GREEN PROJECT_NAME COLOR_OFF " " PROJECT_VERSION " - using:\n");
fmt::print(COLOR_GREEN PROJECT_NAME COLOR_OFF " " PROJECT_VERSION
#if defined COMMITS_SINCE_TAG && defined COMMIT_HASH
"-r" COMMITS_SINCE_TAG "-" COMMIT_HASH
#endif
" - using:\n"
);

// Library versions
ebur128_get_version(&ebur128_v_major, &ebur128_v_minor, &ebur128_v_patch);
Expand Down Expand Up @@ -494,5 +499,5 @@ static void version() {
fmt::print(COLOR_YELLOW "{:<17}" COLOR_OFF " Microsoft C/C++ {:.2f}\n", "Compiler:", (float) _MSC_VER / 100.0f);
#endif

fmt::print(COLOR_YELLOW "{:<17}" COLOR_OFF " " __DATE__ "\n", "Build Date:");
fmt::print(COLOR_YELLOW "{:<17}" COLOR_OFF " " BUILD_DATE "\n", "Build Date:");
}
4 changes: 2 additions & 2 deletions src/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static FileType determine_filetype(const std::string &extension)
{".spx", FileType::OGG},
{".opus", FileType::OPUS},
{".m4a", FileType::M4A},
{".mp4", FileType::M4A},
{".mp4", FileType::M4A},
{".wma", FileType::WMA},
{".wav", FileType::WAV},
{".aiff", FileType::AIFF},
Expand Down Expand Up @@ -126,7 +126,7 @@ ScanJob* ScanJob::factory(char **files, size_t nb_files, const Config &config)
}
if (tracks.empty())
return nullptr;
return new ScanJob("", tracks, config);
return new ScanJob(tracks, config);
}

void free_ebur128(ebur128_state *ebur128_state)
Expand Down
1 change: 1 addition & 0 deletions src/scan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ScanJob {
size_t skipped = 0;

ScanJob(const std::string &path, std::vector<Track> &tracks, const Config &config) : path(path), nb_files(tracks.size()), config(config), tracks(std::move(tracks)) {}
ScanJob(std::vector<Track> &tracks, const Config &config) : nb_files(tracks.size()), config(config), tracks(std::move(tracks)) {}
static ScanJob* factory(char **files, size_t nb_files, const Config &config);
static ScanJob* factory(const std::filesystem::path &path);
bool scan(std::mutex *ffmpeg_mutex = nullptr);
Expand Down
5 changes: 4 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"name": "libebur128",
"platform": "windows"
},
"taglib",
{
"name": "taglib",
"platform": "windows"
},
{
"name": "ffmpeg",
"platform": "windows",
Expand Down

0 comments on commit cd3694b

Please sign in to comment.