Skip to content

Commit

Permalink
Added an option to build shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Jun 15, 2023
1 parent b6bf033 commit cb328b2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build-and-test-deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ env:

jobs:
build-and-test:
name: ${{ matrix.image }}-${{ matrix.env.CC }}
name: ${{ matrix.image }}-${{ matrix.env.CC }} shared lib ${{ matrix.shared }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
image: [ 'i386/debian:10', 'i386/debian:11', 'amd64/debian:11' ]
env: [ {CC: gcc, CXX: g++}, {CC: clang, CXX: clang++} ]
shared: [on, off]

container: ${{ matrix.image }}
env: ${{ matrix.env }}
steps:
Expand Down Expand Up @@ -87,7 +89,7 @@ jobs:
run: echo "SEXP_INSTALL_PATH=$PWD/install" >> $GITHUB_ENV

- name: Configure
run: cmake . -Bbuild -DCMAKE_INSTALL_PREFIX=${{ env.SEXP_INSTALL_PATH }} -DCMAKE_BUILD_TYPE=Release
run: cmake . -Bbuild -DCMAKE_INSTALL_PREFIX=${{ env.SEXP_INSTALL_PATH }} -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIB=${{ matrix.shared }}

- name: Build
run: cmake --build build --config Release
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/build-and-test-msys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ defaults:
shell: msys2 {0}
jobs:
build-and-test:
name: MSys-${{ matrix.msystem }} shared lib ${{ matrix.shared }}
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
msystem: [ ucrt64, mingw64, clang64 ]
shared: [on, off]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -69,7 +71,7 @@ jobs:
run: echo "SEXP_INSTALL_PATH=$(cygpath -u $PWD/install)" >> $GITHUB_ENV

- name: Configure
run: cmake -Bbuild -DCMAKE_INSTALL_PREFIX=${{ env.SEXP_INSTALL_PATH }} -DCMAKE_BUILD_TYPE=Release
run: cmake -Bbuild -DCMAKE_INSTALL_PREFIX=${{ env.SEXP_INSTALL_PATH }} -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIB=${{ matrix.shared }}

- name: Build
run: cmake --build build --config Release
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/build-and-test-rh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ env:

jobs:
build-and-test:
name: ${{ matrix.image }}-${{ matrix.env.CC }}
name: ${{ matrix.image }}-${{ matrix.env.CC }} shared lib ${{ matrix.shared }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
image: [ 'centos:7', 'tgagor/centos:stream8', 'quay.io/centos/centos:stream9', 'fedora:35', 'fedora:36' ]
env: [ {CC: gcc, CXX: g++}, {CC: clang, CXX: clang++} ]
shared: [ on, off ]
container: ${{ matrix.image }}
env: ${{ matrix.env }}
steps:
Expand All @@ -73,7 +74,7 @@ jobs:
run: echo "SEXP_INSTALL_PATH=$PWD/install" >> $GITHUB_ENV

- name: Configure
run: cmake . -Bbuild -DCMAKE_INSTALL_PREFIX=${{ env.SEXP_INSTALL_PATH }} -DCMAKE_BUILD_TYPE=Release
run: cmake . -Bbuild -DCMAKE_INSTALL_PREFIX=${{ env.SEXP_INSTALL_PATH }} -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIB=${{ matrix.shared }}

- name: Build
run: cmake --build build --config Release
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ env:
jobs:
build-and-test:
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }}-${{ matrix.env.CC }} shared lib ${{ matrix.shared }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-11, windows-2019 ]
env: [ { } ]
shared: [on, off]
# on macos gcc is an alias to clang by default, so there is no real value in macos clang run
include:
- { os: ubuntu-20.04, env: { CC: clang, CXX: clang++ } }
- { os: ubuntu-20.04, env: { CC: clang, CXX: clang++ }, shared: on }
- { os: ubuntu-20.04, env: { CC: clang, CXX: clang++ }, shared: off }
env: ${{ matrix.env }}
steps:
- name: Checkout
Expand All @@ -58,7 +61,7 @@ jobs:
fetch-depth: 1

- name: Configure
run: cmake -Bbuild -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/install -DCMAKE_BUILD_TYPE=Release
run: cmake -Bbuild -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/install -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIB=${{ matrix.shared }}

- name: Adjust environment for Windows build
if: runner.os == 'Windows'
Expand Down
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ option(WITH_SEXP_CLI "Build sexp console application" ON)
option(WITH_SANITIZERS "Enable ASAN and other sanitizers" OFF)
option(WITH_COVERAGE "Enable coverage report" OFF)
option(DOWNLOAD_GTEST "Download googletest" ON)
option(BUILD_SHARED_LIB "Build shared library" OFF)

include(GNUInstallDirs)
include(CheckCXXSourceCompiles)

if (BUILD_SHARED_LIB)
set(TYPE "SHARED")
else (BUILD_SHARED_LIB)
set(TYPE "STATIC")
endif (BUILD_SHARED_LIB)

message(STATUS "Building ${TYPE} library")

if (WITH_SANITIZERS)
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand All @@ -53,7 +61,7 @@ if (WITH_SANITIZERS)
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
message(STATUS "Forcing build type to Debug for sanitizers")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type. Forced to Debug" FORCE)
set(WITH_TESTS ON CACHE STRING "BForced to ON" FORCE)
set(WITH_TESTS ON CACHE STRING "Forced to ON" FORCE)
endif()
endif()

Expand All @@ -64,7 +72,7 @@ if (WITH_COVERAGE)
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
message(STATUS "Forcing build type to Debug for coverage")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type. Forced to Debug" FORCE)
set(WITH_TESTS ON CACHE STRING "BForced to ON" FORCE)
set(WITH_TESTS ON CACHE STRING "Forced to ON" FORCE)
endif()
endif()

Expand Down Expand Up @@ -102,7 +110,7 @@ if(NOT MSVC)

endif(NOT MSVC)

add_library(sexp STATIC
add_library(sexp ${TYPE}
"src/sexp-input.cpp"
"src/sexp-output.cpp"
"src/sexp-object.cpp"
Expand Down

0 comments on commit cb328b2

Please sign in to comment.