Skip to content

Commit

Permalink
Fix cross-platform build issues (#142)
Browse files Browse the repository at this point in the history
* Fix cross-platform build issues

* Remove UTF-16 create/statment support from sqlite_modern_cpp

* Tame warnings from external libs

* Help SQLite amalgamation on macOS

* Windows build fixes
  • Loading branch information
mr-smidge authored Jan 19, 2025
1 parent 65c2333 commit 2ab0d50
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 86 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,44 @@ jobs:
matrix:
config: [
{ os: ubuntu-20.04, c_compiler: gcc-10, cpp_compiler: g++-10 },
{ os: ubuntu-22.04, c_compiler: clang-14, cpp_compiler: clang++-14 },
{ os: ubuntu-22.04, c_compiler: clang-15, cpp_compiler: clang++-15 },
{ os: ubuntu-22.04, c_compiler: gcc-11, cpp_compiler: g++-11 },
{ os: ubuntu-22.04, c_compiler: gcc-12, cpp_compiler: g++-12 },
{ os: ubuntu-24.04, c_compiler: clang-16, cpp_compiler: clang++-16 },
{ os: ubuntu-24.04, c_compiler: clang-17, cpp_compiler: clang++-17 },
{ os: ubuntu-24.04, c_compiler: gcc-13, cpp_compiler: g++-13 },
{ os: ubuntu-24.04, c_compiler: gcc-14, cpp_compiler: g++-14 },
#{ os: windows-2019, c_compiler: cl, cpp_compiler: cl },
{ os: macos-13, c_compiler: cc, cpp_compiler: c++, cmake_args: "-DSYSTEM_SQLITE=OFF" },
{ os: windows-2019, c_compiler: cl, cpp_compiler: cl },
]

runs-on: ${{ matrix.config.os }}

steps:
- uses: actions/checkout@v3

- name: Install dependencies (Windows)
if: runner.os == 'Windows'
run: vcpkg install zlib sqlite3
- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: brew install zlib

- name: Install dependencies (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install --yes libz-dev libsqlite3-dev
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=${{matrix.config.c_compiler}} -DCMAKE_CXX_COMPILER=${{matrix.config.cpp_compiler}}
- name: Install dependencies (Windows)
if: runner.os == 'Windows'
run: vcpkg install zlib sqlite3

- name: Configure CMake (non-Windows)
if: runner.os != 'Windows'
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=${{matrix.config.c_compiler}} -DCMAKE_CXX_COMPILER=${{matrix.config.cpp_compiler}} ${{matrix.config.cmake_args}}

- name: Configure CMake (Windows)
if: runner.os == 'Windows'
run: cmake -B ${{github.workspace}}/build -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=${{matrix.config.c_compiler}} -DCMAKE_CXX_COMPILER=${{matrix.config.cpp_compiler}} ${{matrix.config.cmake_args}}

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
Expand Down
29 changes: 22 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)
project(libdjinterop
VERSION 0.24.0
VERSION 0.24.1
DESCRIPTION "C++ library providing access to DJ record libraries")
set(PROJECT_HOMEPAGE_URL "https://github.com/xsco/libdjinterop")

Expand All @@ -25,7 +25,11 @@ if(MSVC)
# Ask MSVC to populate the __cplusplus macro properly.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
else()
add_compile_options("$<$<CONFIG:DEBUG>:-Wall>" "-Wpedantic" "-Werror")
# Disabling -Wunused-variable needed as the library implementation doesn't
# use every variable in the public headers. Is there a better way?
# Disabling -Wunused-but-set-variable owing to XCode triggering on this
# in the SQLite amalgamation.
add_compile_options("-Wall" "-Wpedantic" "-Wno-unused-variable" "-Wno-unused-but-set-variable" "-Werror")
endif()

# Build shared a library by default.
Expand Down Expand Up @@ -215,11 +219,10 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${DJINTEROP_INSTALL_INCLUDEDIR}>)
target_include_directories(
DjInterop PRIVATE
DjInterop PRIVATE SYSTEM
${ZLIB_INCLUDE_DIRS}
ext/sqlite_modern_cpp
ext/date
src)
ext/date)

target_link_libraries(
DjInterop PUBLIC
Expand All @@ -231,7 +234,7 @@ if(SYSTEM_SQLITE)
set(SQLITE_MIN_VERSION 3.11)
find_package(SQLite3 ${SQLITE_MIN_VERSION} REQUIRED)
target_include_directories(
DjInterop PRIVATE
DjInterop PRIVATE SYSTEM
${SQLite3_INCLUDE_DIRS})
target_link_libraries(
DjInterop PUBLIC
Expand All @@ -246,7 +249,7 @@ else()
DjInterop PUBLIC
SQLITE_OMIT_LOAD_EXTENSION)
target_include_directories(
DjInterop PRIVATE
DjInterop PRIVATE SYSTEM
ext/sqlite-amalgamation)
endif()

Expand Down Expand Up @@ -291,6 +294,18 @@ install(FILES
include/djinterop/engine/v2/track_data_blob.hpp
include/djinterop/engine/v2/track_table.hpp
DESTINATION "${DJINTEROP_INSTALL_INCLUDEDIR}/engine/v2")
install(FILES
include/djinterop/engine/v3/beat_data_blob.hpp
include/djinterop/engine/v3/engine_library.hpp
include/djinterop/engine/v3/information_table.hpp
include/djinterop/engine/v3/loops_blob.hpp
include/djinterop/engine/v3/overview_waveform_data_blob.hpp
include/djinterop/engine/v3/playlist_entity_table.hpp
include/djinterop/engine/v3/playlist_table.hpp
include/djinterop/engine/v3/quick_cues_blob.hpp
include/djinterop/engine/v3/track_data_blob.hpp
include/djinterop/engine/v3/track_table.hpp
DESTINATION "${DJINTEROP_INSTALL_INCLUDEDIR}/engine/v3")


if (UNIX)
Expand Down
3 changes: 2 additions & 1 deletion ext/sqlite-amalgamation/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -114491,7 +114491,8 @@ SQLITE_PRIVATE void sqlite3DefaultRowEst(Index *pIdx){
if( x<99 ){
pIdx->pTable->nRowLogEst = x = 99;
}
if( pIdx->pPartIdxWhere!=0 ) x -= 10; assert( 10==sqlite3LogEst(2) );
if( pIdx->pPartIdxWhere!=0 ) x -= 10;
assert( 10==sqlite3LogEst(2) );
a[0] = x;

/* Estimate that a[1] is 10, a[2] is 9, a[3] is 8, a[4] is 7, a[5] is
Expand Down
20 changes: 0 additions & 20 deletions ext/sqlite_modern_cpp/sqlite_modern_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "sqlite_modern_cpp/errors.h"
#include "sqlite_modern_cpp/utility/function_traits.h"
#include "sqlite_modern_cpp/utility/uncaught_exceptions.h"
#include "sqlite_modern_cpp/utility/utf16_utf8.h"

namespace sqlite {

Expand Down Expand Up @@ -107,10 +106,6 @@ namespace sqlite {
return ++_inx;
}

sqlite3_stmt* _prepare(u16str_ref sql) {
return _prepare(utility::utf16_to_utf8(sql));
}

sqlite3_stmt* _prepare(str_ref sql) {
int hresult;
sqlite3_stmt* tmp = nullptr;
Expand All @@ -129,12 +124,6 @@ namespace sqlite {

public:

database_binder(std::shared_ptr<sqlite3> db, u16str_ref sql):
_db(db),
_stmt(_prepare(sql), sqlite3_finalize),
_inx(0) {
}

database_binder(std::shared_ptr<sqlite3> db, str_ref sql):
_db(db),
_stmt(_prepare(sql), sqlite3_finalize),
Expand Down Expand Up @@ -396,22 +385,13 @@ namespace sqlite {
*this << R"(PRAGMA encoding = "UTF-16";)";
}

database(const std::u16string &db_name, const sqlite_config &config = {}): database(utility::utf16_to_utf8(db_name), config) {
if (config.encoding == Encoding::ANY)
*this << R"(PRAGMA encoding = "UTF-16";)";
}

database(std::shared_ptr<sqlite3> db):
_db(db) {}

database_binder operator<<(str_ref sql) {
return database_binder(_db, sql);
}

database_binder operator<<(u16str_ref sql) {
return database_binder(_db, sql);
}

connection_type connection() const { return _db; }

sqlite3_int64 last_insert_rowid() const {
Expand Down
42 changes: 0 additions & 42 deletions ext/sqlite_modern_cpp/sqlite_modern_cpp/utility/utf16_utf8.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/djinterop/album_art.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
namespace djinterop
{
// Artwork for tracks
class album_art
class DJINTEROP_PUBLIC album_art
{
public:
using image_data_type = uint_least8_t;
Expand Down
10 changes: 5 additions & 5 deletions include/djinterop/engine/engine_schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
namespace djinterop::engine
{
/// Enumeration of Engine database schemas.
enum class engine_schema
enum class DJINTEROP_PUBLIC engine_schema
{
schema_1_6_0,
schema_1_7_1,
Expand All @@ -54,7 +54,7 @@ enum class engine_schema
};

/// Set of supported schema versions.
constexpr std::array<engine_schema, 19> supported_schemas{
constexpr std::array supported_schemas{
engine_schema::schema_1_6_0, engine_schema::schema_1_7_1,
engine_schema::schema_1_9_1, engine_schema::schema_1_11_1,
engine_schema::schema_1_13_0, engine_schema::schema_1_13_1,
Expand All @@ -67,7 +67,7 @@ constexpr std::array<engine_schema, 19> supported_schemas{
engine_schema::schema_3_0_0};

/// Set of supported schema 1.x versions.
constexpr std::array<engine_schema, 11> supported_v1_schemas{
constexpr std::array supported_v1_schemas{
engine_schema::schema_1_6_0, engine_schema::schema_1_7_1,
engine_schema::schema_1_9_1, engine_schema::schema_1_11_1,
engine_schema::schema_1_13_0, engine_schema::schema_1_13_1,
Expand All @@ -76,14 +76,14 @@ constexpr std::array<engine_schema, 11> supported_v1_schemas{
engine_schema::schema_1_18_0_os};

/// Set of supported schema 2.x versions.
constexpr std::array<engine_schema, 7> supported_v2_schemas{
constexpr std::array supported_v2_schemas{
engine_schema::schema_2_18_0, engine_schema::schema_2_20_1,
engine_schema::schema_2_20_2, engine_schema::schema_2_20_3,
engine_schema::schema_2_21_0, engine_schema::schema_2_21_1,
engine_schema::schema_2_21_2};

/// Set of supported schema 3.x versions.
constexpr std::array<engine_schema, 1> supported_v3_schemas{
constexpr std::array supported_v3_schemas{
engine_schema::schema_3_0_0};

/// The most recent schema version supported by the library.
Expand Down
4 changes: 2 additions & 2 deletions src/djinterop/engine/v1/engine_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#include <djinterop/engine/engine_schema.hpp>
#include <djinterop/exceptions.hpp>

#include "djinterop/engine/metadata_types.hpp"
#include "performance_data_format.hpp"
#include "../metadata_types.hpp"
#include "../schema/schema.hpp"
#include "performance_data_format.hpp"

namespace djinterop::engine::v1
{
Expand Down
2 changes: 1 addition & 1 deletion src/djinterop/engine/v1/engine_track_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "../../util/convert.hpp"
#include "../../util/filesystem.hpp"
#include "../../util/sqlite_transaction.hpp"
#include "djinterop/engine/track_utils.hpp"
#include "../track_utils.hpp"
#include "engine_crate_impl.hpp"
#include "engine_database_impl.hpp"
#include "engine_track_impl.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/djinterop/engine/v1/performance_data_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <djinterop/musical_key.hpp>

#include "../../util/convert.hpp"
#include "djinterop/engine/encode_decode_utils.hpp"
#include "../encode_decode_utils.hpp"
#include "performance_data_format.hpp"

namespace djinterop::engine::v1
Expand Down

0 comments on commit 2ab0d50

Please sign in to comment.