Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option to build shared library #34

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 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 @@ -84,10 +86,12 @@ jobs:
apt-get install -y clang

- name: Adjust environment
run: echo "SEXP_INSTALL_PATH=$PWD/install" >> $GITHUB_ENV
run: |
echo "SEXP_INSTALL_PATH=$PWD/install" >> $GITHUB_ENV
echo "SHARED_LIB=${{ matrix.shared }}" >> $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_LIBS=${{ matrix.shared }}

- name: Build
run: cmake --build build --config Release
Expand Down
8 changes: 6 additions & 2 deletions .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 @@ -66,10 +68,12 @@ jobs:

- name: Adjust environment
shell: bash
run: echo "SEXP_INSTALL_PATH=$(cygpath -u $PWD/install)" >> $GITHUB_ENV
run: |
echo "SEXP_INSTALL_PATH=$(cygpath -u $PWD/install)" >> $GITHUB_ENV
echo "SHARED_LIB=${{ matrix.shared }}" >> $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_LIBS=${{ matrix.shared }}

- name: Build
run: cmake --build build --config Release
Expand Down
9 changes: 6 additions & 3 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 @@ -70,10 +71,12 @@ jobs:
fetch-depth: 1

- name: Adjust environment
run: echo "SEXP_INSTALL_PATH=$PWD/install" >> $GITHUB_ENV
run: |
echo "SEXP_INSTALL_PATH=$PWD/install" >> $GITHUB_ENV
echo "SHARED_LIB=${{ matrix.shared }}" >> $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_LIBS=${{ matrix.shared }}

- name: Build
run: cmake --build build --config Release
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,39 @@ 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 }
# Builds sexp dll with MSVC is not supported
exclude:
- { os: windows-2019, env: { }, shared: on }

env: ${{ matrix.env }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1

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

- name: Adjust environment for Windows build
if: runner.os == 'Windows'
shell: bash
run: echo "OSTYPE=windows" >> $GITHUB_ENV

- name: Adjust environment
run: echo "SHARED_LIB=${{ matrix.shared }}" >> $GITHUB_ENV

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

- name: Build
run: cmake --build build --config Release

Expand Down
30 changes: 26 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,23 @@ 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_LIBS "Build shared library" OFF)

include(GNUInstallDirs)
include(CheckCXXSourceCompiles)

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

if (BUILD_SHARED_LIBS AND MSVC)
message(FATAL_ERROR "Building sexp shared library with MSVC is not supported")
endif(BUILD_SHARED_LIBS AND MSVC)


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

if (WITH_SANITIZERS)
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand All @@ -53,7 +66,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 +77,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 +115,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 All @@ -121,6 +134,7 @@ target_include_directories(sexp PUBLIC
$<INSTALL_INTERFACE:include>
)
set_target_properties(sexp PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(sexp PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

if(WITH_SEXP_CLI)
add_executable (sexp-cli
Expand All @@ -132,6 +146,7 @@ if(WITH_SEXP_CLI)
target_link_libraries(sexp-cli PRIVATE sexp)
target_compile_features(sexp-cli PUBLIC cxx_std_11)
set_target_properties(sexp-cli PROPERTIES RUNTIME_OUTPUT_NAME sexp)
set_target_properties(sexp-cli PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif(WITH_SEXP_CLI)


Expand Down Expand Up @@ -222,6 +237,7 @@ if(WITH_SEXP_TESTS)
)

target_compile_features(sexp-tests PUBLIC cxx_std_11)
set_target_properties(sexp-tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

gtest_discover_tests(sexp-tests)
endif(WITH_SEXP_TESTS)
Expand All @@ -233,7 +249,13 @@ configure_file(
@ONLY
)

install(TARGETS sexp DESTINATION "${CMAKE_INSTALL_LIBDIR}")
if (WIN32 AND BUILD_SHARED_LIBS)
install(TARGETS sexp RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(TARGETS sexp ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
else(WIN32 AND BUILD_SHARED_LIBS)
install(TARGETS sexp DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif(WIN32 AND BUILD_SHARED_LIBS)

install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(FILES "${CONFIGURED_PC}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
if(WITH_SEXP_CLI)
Expand Down
3 changes: 3 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ cmake --install .

== CMake script options

`BUILD_SHARED_LIBS:BOOL`::
build shared library (default: `OFF`)

`WITH_SEXP_TESTS:BOOL`::
build tests (default: `ON`)

Expand Down
42 changes: 37 additions & 5 deletions tests/scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,43 @@ assert_installed_var() {
test_install_script() {
echo "==> Install script test"

if [[ "$OSTYPE" == "windows" ]]; then
assert_installed "$DIR_INS_B/sexp.exe"
assert_installed "$DIR_INS_L/sexp.lib"
if [[ "${SHARED_LIB:-}" == "on" ]]; then
case "$OSTYPE" in
darwin*)
assert_installed "$DIR_INS_B/sexp"
assert_installed "$DIR_INS_L/libsexp.dylib"
;;
windows )
assert_installed "$DIR_INS_B/sexp.exe"
assert_installed "$DIR_INS_B/sexp.dll"
assert_installed "$DIR_INS_L/sexp.lib"
;;
msys)

assert_installed "$DIR_INS_B/sexp.exe"
assert_installed "$DIR_INS_B/libsexp.dll"
assert_installed "$DIR_INS_L/libsexp.dll.a"
;;
*)
assert_installed "$DIR_INS_B/sexp"
assert_installed_var "$DIR_INS_L" "$DIR_INS_L64" "libsexp.so"
;;
esac
else
assert_installed "$DIR_INS_B/sexp"
assert_installed_var "$DIR_INS_L" "$DIR_INS_L64" "libsexp.a"
case "$OSTYPE" in
windows)
assert_installed "$DIR_INS_B/sexp.exe"
assert_installed "$DIR_INS_L/sexp.lib"
;;
msys)
assert_installed "$DIR_INS_B/sexp.exe"
assert_installed "$DIR_INS_L/libsexp.a"
;;
*)
assert_installed "$DIR_INS_B/sexp"
assert_installed_var "$DIR_INS_L" "$DIR_INS_L64" "libsexp.a"
;;
esac
fi

assert_installed_var "$DIR_INS_P" "$DIR_INS_P64" "sexp.pc"
Expand All @@ -75,6 +106,7 @@ Input:

Writing base64 (of canonical) output to certificate.dat
EOM
export LD_LIBRARY_PATH="$DIR_INS_L":"$DIR_INS_L64"
echo "(aa bb (cc dd))" > input1.dat
output=$("$app" -o certificate.dat -p -b < input1.dat)
# $expected possibly includes extra EOL at the end -- it depends on OS
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.4
0.8.5
Loading