Skip to content

Commit

Permalink
Add cmake option to compile library in shared or static (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-PLACET authored Feb 19, 2025
1 parent bf3a430 commit 2843af5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ defaults:
jobs:
build:
runs-on: ${{ matrix.sys.image }}
name: ${{ matrix.sys.compiler }} / ${{ matrix.sys.version }} / ${{ matrix.sys.stdlib }} / ${{ matrix.config.name }} / date-polyfill ${{ matrix.sys.date-polyfill}}
name: ${{ matrix.sys.compiler }} / ${{ matrix.sys.version }} / ${{ matrix.sys.stdlib }} / ${{ matrix.config.name }} / date-polyfill ${{ matrix.sys.date-polyfill}} / shared ${{ matrix.sys.shared }}
env:
SCCACHE_GHA_ENABLED: "true"
strategy:
fail-fast: false
matrix:
sys:
- {image: ubuntu-24.04, compiler: clang, version: '17', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON'}
- {image: ubuntu-24.04, compiler: clang, version: '17', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON', shared : 'ON'}
# - {compiler: clang, version: '17', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17', date-polyfill: 'ON' }
- {image: ubuntu-24.04, compiler: clang, version: '18', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON'}
- {image: ubuntu-24.04, compiler: clang, version: '18', config-flags: '', stdlib: 'libstdc++-12', date-polyfill: 'ON', shared : 'ON'}
# - {compiler: clang, version: '16', config-flags: '-DCMAKE_CXX_FLAGS=-stdlib=libc++', stdlib: 'libc++-17', date-polyfill: 'ON' }

- {image: ubuntu-24.04, compiler: gcc, version: '12', config-flags: '', date-polyfill: 'ON'}
- {image: ubuntu-24.04, compiler: gcc, version: '13', config-flags: '', date-polyfill: 'ON'}
- {image: ubuntu-24.04, compiler: gcc, version: '13', config-flags: '', date-polyfill: 'OFF'}
- {image: ubuntu-24.04, compiler: gcc, version: '12', config-flags: '', date-polyfill: 'ON', shared : 'ON'}
- {image: ubuntu-24.04, compiler: gcc, version: '13', config-flags: '', date-polyfill: 'ON', shared : 'ON'}
- {image: ubuntu-24.04, compiler: gcc, version: '13', config-flags: '', date-polyfill: 'ON', shared : 'OFF'}
- {image: ubuntu-24.04, compiler: gcc, version: '13', config-flags: '', date-polyfill: 'OFF', shared : 'ON'}

config:
- {name: Debug}
Expand Down Expand Up @@ -82,7 +83,8 @@ jobs:
-DBUILD_EXAMPLES=ON \
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
-DFETCH_DEPENDENCIES_WITH_CMAKE=MISSING
-DFETCH_DEPENDENCIES_WITH_CMAKE=MISSING \
-DSPARROW_BUILD_SHARED=${{matrix.sys.shared}}
- name: Build library
working-directory: build
Expand All @@ -108,7 +110,7 @@ jobs:
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test_sparrow_lib_report_Linux_${{ matrix.sys.compiler }}_${{ matrix.sys.version }}_${{ matrix.sys.stdlib }}_${{ matrix.config.name }}_date-polyfill_${{ matrix.sys.date-polyfill}}
name: test_sparrow_lib_report_Linux_${{ matrix.sys.compiler }}_${{ matrix.sys.version }}_${{ matrix.sys.stdlib }}_${{ matrix.config.name }}_date-polyfill_${{ matrix.sys.date-polyfill}}_shared_${{ matrix.sys.shared }}
path: ./**/test*.xml
if-no-files-found: error

Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ defaults:
jobs:
build:
runs-on: ${{ matrix.runs-on }}
name: ${{ matrix.toolchain.compiler }} / ${{ matrix.build-system.name }} / ${{ matrix.config.name }} / targets ${{ matrix.target-arch.name }} / date-polyfill ${{ matrix.toolchain.date-polyfill}}
name: ${{ matrix.toolchain.compiler }} / ${{ matrix.build-system.name }} / ${{ matrix.config.name }} / targets ${{ matrix.target-arch.name }} / date-polyfill ${{ matrix.toolchain.date-polyfill}} / shared ${{ matrix.toolchain.shared }}
strategy:
fail-fast: false
matrix:
runs-on: [windows-latest]
toolchain:
- {compiler: msvc, date-polyfill: 'ON', use-large-int-placeholders: 'ON'}
- {compiler: msvc, date-polyfill: 'OFF', use-large-int-placeholders: 'ON'}
- {compiler: clang, date-polyfill: 'ON', version: 18, use-large-int-placeholders: 'ON'}
- {compiler: clang, date-polyfill: 'OFF', version: 18, use-large-int-placeholders: 'ON'}
- {compiler: msvc, date-polyfill: 'ON', use-large-int-placeholders: 'ON', shared: 'ON'}
- {compiler: msvc, date-polyfill: 'ON', use-large-int-placeholders: 'ON', shared: 'OFF'}
- {compiler: msvc, date-polyfill: 'OFF', use-large-int-placeholders: 'ON', shared: 'ON'}
- {compiler: clang, date-polyfill: 'ON', version: 18, use-large-int-placeholders: 'ON', shared: 'ON'}
- {compiler: clang, date-polyfill: 'ON', version: 18, use-large-int-placeholders: 'ON', shared: 'OFF'}
- {compiler: clang, date-polyfill: 'OFF', version: 18, use-large-int-placeholders: 'ON', shared: 'ON'}
target-arch:
- {
name: "Win64",
Expand Down Expand Up @@ -166,6 +168,7 @@ jobs:
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DFETCH_DEPENDENCIES_WITH_CMAKE=MISSING \
-DSPARROW_BUILD_SHARED=${{matrix.toolchain.shared}} \
$TEST_COVERAGE_ACTIVATION
- name: Build library
Expand All @@ -188,7 +191,7 @@ jobs:
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test_sparrow_lib_report_Windows_${{ matrix.toolchain.compiler }}_${{ matrix.build-system.name }}_${{ matrix.config.name }}_${{ matrix.target-arch.name }}_date-polyfill_${{ matrix.toolchain.date-polyfill}}
name: test_sparrow_lib_report_Windows_${{ matrix.toolchain.compiler }}_${{ matrix.build-system.name }}_${{ matrix.config.name }}_${{ matrix.target-arch.name }}_date-polyfill_${{ matrix.toolchain.date-polyfill}}_shared_${{ matrix.toolchain.shared }}
path: ./**/test*.xml
if-no-files-found: error

Expand Down
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,20 @@ else()
)
endif()

add_library(sparrow SHARED ${SPARROW_HEADERS} ${SPARROW_SRC})
OPTION(SPARROW_BUILD_SHARED "Build sparrow as a shared library" ON)
if(SPARROW_BUILD_SHARED)
message(STATUS "🔧 Build shared library")
set(SPARROW_LIBRARY_TYPE SHARED)
else()
message(STATUS "🔧 Build static library")
set(SPARROW_LIBRARY_TYPE STATIC)
list(APPEND SPARROW_COMPILE_DEFINITIONS SPARROW_STATIC_LIB)
endif()

add_library(sparrow ${SPARROW_LIBRARY_TYPE} ${SPARROW_SRC} ${SPARROW_HEADERS})

target_compile_definitions(sparrow PUBLIC ${SPARROW_COMPILE_DEFINITIONS})

# TODO: handle static lib
if (UNIX)
# CMake does not compute the version number of so files as libtool
# does on Linux. Strictly speaking, we should exclude FreeBSD and
Expand Down Expand Up @@ -310,11 +320,11 @@ if(ENABLE_COVERAGE)
enable_coverage(sparrow)
endif()

if (BUILD_TESTS)
if(BUILD_TESTS)
message(STATUS "🧪 Create tests targets")
enable_testing()
add_subdirectory(test)
endif ()
endif()

# Docs
# ====
Expand Down
4 changes: 2 additions & 2 deletions include/sparrow/record_batch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ namespace sparrow

namespace detail
{
std::vector<record_batch::name_type> get_names(const std::vector<array>& array_list)
inline std::vector<record_batch::name_type> get_names(const std::vector<array>& array_list)
{
const auto names = array_list
| std::views::transform(
Expand Down Expand Up @@ -280,7 +280,7 @@ struct std::formatter<sparrow::record_batch>
}
};

std::ostream& operator<<(std::ostream& os, const sparrow::record_batch& value)
inline std::ostream& operator<<(std::ostream& os, const sparrow::record_batch& value)
{
os << std::format("{}", value);
return os;
Expand Down

0 comments on commit 2843af5

Please sign in to comment.