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

Support shared library build #686

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
106 changes: 106 additions & 0 deletions .github/workflows/build_library.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
name: Build Unity library

on:
push:
pull_request:

jobs:
build:
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- {
name: "Windows: MSVC - Release Static",
os: windows-latest,
build_type: "Release",
cc: "cl",
cxx: "cl",
environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat",
generators: "Visual Studio 17 2022",
shared_build: false
}
- {
name: "Ubuntu: GCC - Release Static",
os: ubuntu-latest,
build_type: "Release",
cc: "gcc",
cxx: "g++",
generators: "Ninja",
shared_build: false
}
- {
name: "Apple OSX: Clang - Release Static",
os: macos-latest,
build_type: "Release",
cc: "clang",
cxx: "clang++",
generators: "Ninja",
shared_build: false
}
- {
name: "Windows: MSVC - Release Shared",
os: windows-latest,
build_type: "Release",
cc: "cl",
cxx: "cl",
environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvars64.bat",
generators: "Visual Studio 17 2022",
shared_build: true
}
- {
name: "Ubuntu: GCC - Release Shared",
os: ubuntu-latest,
build_type: "Release",
cc: "gcc",
cxx: "g++",
generators: "Ninja",
shared_build: true
}
- {
name: "Apple OSX: Clang - Release Shared",
os: macos-latest,
build_type: "Release",
cc: "clang",
cxx: "clang++",
generators: "Ninja",
shared_build: true
}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install dependencies
run: pip install cmake ninja

- name: Prepare Visual Studio environment
if: startsWith(matrix.config.os, 'windows')
run: cmd "${{ matrix.config.environment_script }}"

- name: CMake configure
shell: bash
run: |
cmake \
-S . \
-B build \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-G "${{ matrix.config.generators }}" \
-DCMAKE_INSTALL_PREFIX:PATH=install \
-DBUILD_SHARED_LIBS:BOOL=${{ matrix.config.shared_build }} \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DUNITY_EXTENSION_FIXTURES:BOOL=ON \
-DUNITY_EXTENSION_MEMORY:BOOL=ON

- name: CMake build
shell: bash
run: cmake --build build --config ${{ matrix.config.build_type }}

- name: CMake install
shell: bash
run: cmake --build build --config ${{ matrix.config.build_type }} --target install
24 changes: 16 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cmake_minimum_required(VERSION 3.12)
# Read src/unity.h file and get project version from it
set(UNITY_HEADER "src/unity.h")

file(STRINGS "${UNITY_HEADER}" UNITY_HEADER_CONTENT
file(STRINGS "${UNITY_HEADER}" UNITY_HEADER_CONTENT
REGEX "^#define UNITY_VERSION_(MAJOR|MINOR|BUILD) +[0-9]+$"
)

Expand All @@ -24,8 +24,8 @@ set(UNITY_HEADER_VERSION_BUILD 0)

foreach(VERSION_LINE IN LISTS UNITY_HEADER_CONTENT)
foreach(VERSION_PART MAJOR MINOR BUILD)
string(CONCAT REGEX_STRING "#define UNITY_VERSION_"
"${VERSION_PART}"
string(CONCAT REGEX_STRING "#define UNITY_VERSION_"
"${VERSION_PART}"
" +([0-9]+)"
)

Expand Down Expand Up @@ -57,7 +57,7 @@ if(${UNITY_EXTENSION_MEMORY})
endif()

# Main target ------------------------------------------------------------------
add_library(${PROJECT_NAME} STATIC)
add_library(${PROJECT_NAME})
add_library(${PROJECT_NAME}::framework ALIAS ${PROJECT_NAME})

# Includes ---------------------------------------------------------------------
Expand Down Expand Up @@ -89,12 +89,13 @@ set(${PROJECT_NAME}_PUBLIC_HEADERS
)

set_target_properties(${PROJECT_NAME}
PROPERTIES
PROPERTIES
C_STANDARD 11
C_STANDARD_REQUIRED ON
C_EXTENSIONS OFF
PUBLIC_HEADER "${${PROJECT_NAME}_PUBLIC_HEADERS}"
EXPORT_NAME framework
WINDOWS_EXPORT_ALL_SYMBOLS ON
)

target_compile_options(${PROJECT_NAME}
Expand All @@ -104,7 +105,7 @@ target_compile_options(${PROJECT_NAME}
-Wcast-align
-Wcast-qual
-Wconversion
-Wexit-time-destructors
-Wexit-time-destructors
-Wglobal-constructors
-Wmissing-noreturn
-Wmissing-prototypes
Expand All @@ -116,7 +117,7 @@ target_compile_options(${PROJECT_NAME}
-Wall
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,8.0.0>:-Wextra-semi-stmt>
>

# GCC
$<$<C_COMPILER_ID:GNU>:
-Waddress
Expand Down Expand Up @@ -144,16 +145,23 @@ target_compile_options(${PROJECT_NAME}
>
)

target_compile_definitions(${PROJECT_NAME}
PRIVATE
# Enable shared library
$<$<BOOL:${BUILD_SHARED_LIBS}>:UNITY_SKIP_DEFAULT_RUNNER>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding option for BUILD_SHARED_LIBS, as described in cmake docs?

)

write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
COMPATIBILITY SameMajorVersion
)

## Target installation
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
COMPONENT library
)
Expand Down