diff --git a/.github/workflows/build_library.yml b/.github/workflows/build_library.yml new file mode 100644 index 00000000..5e06e9d9 --- /dev/null +++ b/.github/workflows/build_library.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 348266d5..a3583e2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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]+$" ) @@ -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]+)" ) @@ -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 --------------------------------------------------------------------- @@ -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} @@ -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 @@ -116,7 +117,7 @@ target_compile_options(${PROJECT_NAME} -Wall $<$,8.0.0>:-Wextra-semi-stmt> > - + # GCC $<$: -Waddress @@ -144,9 +145,15 @@ target_compile_options(${PROJECT_NAME} > ) +target_compile_definitions(${PROJECT_NAME} + PRIVATE + # Enable shared library + $<$:UNITY_SKIP_DEFAULT_RUNNER> +) + write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake VERSION ${PROJECT_VERSION} - COMPATIBILITY SameMajorVersion + COMPATIBILITY SameMajorVersion ) ## Target installation @@ -154,6 +161,7 @@ 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 )