diff --git a/.github/workflows/macos-build.yaml b/.github/workflows/macos-build.yaml index f70e5aa..0341218 100644 --- a/.github/workflows/macos-build.yaml +++ b/.github/workflows/macos-build.yaml @@ -15,15 +15,23 @@ jobs: fail-fast: false matrix: include: - - { name: "MacOS 11", os: macos-11, osx_arch: "x86_64;arm64", build_type: "Debug" } - - { name: "MacOS 11", os: macos-11, osx_arch: "x86_64;arm64", build_type: "Release" } - - { name: "MacOS 12", os: macos-12, osx_arch: "x86_64;arm64", build_type: "Debug" } - - { name: "MacOS 12", os: macos-12, osx_arch: "x86_64;arm64", build_type: "Release" } + - { name: "MacOS 11", os: macos-11, osx_arch: "x86_64;arm64", build_type: "Debug", fetch_deps: YES } + - { name: "MacOS 11", os: macos-11, osx_arch: "x86_64", build_type: "Release", fetch_deps: NO } + - { name: "MacOS 12", os: macos-12, osx_arch: "x86_64", build_type: "Debug", fetch_deps: NO } + - { name: "MacOS 12", os: macos-12, osx_arch: "x86_64;arm64", build_type: "Release", fetch_deps: YES } name: ${{ matrix.name }} build (static/${{ matrix.build_type }}) runs-on: ${{ matrix.os }} steps: + - name: Install dependencies + # Homebrew doesn't support universal binaries so only install dependencies for x86_64 builds + if: ${{ matrix.fetch_deps == 'NO' }} + run: | + brew install mbedtls@2 + brew install argp-standalone + echo "MbedTLS_ROOT=$(brew --prefix mbedtls@2)" >> $GITHUB_ENV + - name: Checkout uses: actions/checkout@v3 with: @@ -31,7 +39,7 @@ jobs: - run: git describe --always --dirty - name: Configure CMake - run: cmake -B build -DCMAKE_OSX_ARCHITECTURES="${{ matrix.osx_arch }}" -DCMAKE_BUILD_TYPE="${{ matrix.build_type }}" -DFETCH_MBEDTLS=YES -DFETCH_ARGP=YES + run: cmake -B build -DCMAKE_OSX_ARCHITECTURES="${{ matrix.osx_arch }}" -DCMAKE_BUILD_TYPE="${{ matrix.build_type }}" -DFETCH_MBEDTLS=${{ matrix.fetch_deps }} -DFETCH_ARGP=${{ matrix.fetch_deps }} -DMbedTLS_ROOT=${{ env.MbedTLS_ROOT }} - name: Build run: cmake --build build diff --git a/cmake/Modules/Findargp.cmake b/cmake/Modules/Findargp.cmake index 376292d..3788c34 100644 --- a/cmake/Modules/Findargp.cmake +++ b/cmake/Modules/Findargp.cmake @@ -19,59 +19,72 @@ include(CheckIncludeFile) include(CheckSymbolExists) include(FindPackageHandleStandardArgs) -# Check whether libc provides argp_parse -check_function_exists("argp_parse" argp_parse_FOUND) - -# Check for argp.h header +# Check whether system provides argp.h header CHECK_INCLUDE_FILE( argp.h argp_header_FOUND ) -if(argp_header_FOUND) +if(NOT argp_header_FOUND) + # Search for argp.h header elsewhere find_path(argp_INCLUDE_DIR NAMES argp.h ) + if(argp_INCLUDE_DIR) + # Ensure that compiler can use argp.h header + unset(argp_header_FOUND CACHE) + set(CMAKE_REQUIRED_INCLUDES "${argp_INCLUDE_DIR}") + CHECK_INCLUDE_FILE( + argp.h + argp_header_FOUND + ) + endif() +endif() + +# Check whether libc provides argp_parse +check_function_exists(argp_parse argp_parse_FOUND) + +if(NOT arg_parse_FOUND) + # Search for argp library find_library(argp_LIBRARY NAMES argp ) - if(argp_LIBRARY AND NOT argp_parse_FOUND) + if(argp_LIBRARY) + # Ensure that compiler can use argp library + unset(argp_parse_FOUND CACHE) set(CMAKE_REQUIRED_LIBRARIES ${argp_LIBRARY}) - check_symbol_exists("argp_parse" "argp.h" argp_parse_FOUND) + check_symbol_exists(argp_parse "argp.h" argp_parse_FOUND) endif() +endif() - if(argp_parse_FOUND) - if(argp_LIBRARY) - set(argp_FOUND_MSG ${argp_LIBRARY}) - else() - set(argp_FOUND_MSG "provided by libc") - endif() +if(argp_header_FOUND AND argp_parse_FOUND) + if(argp_LIBRARY) + set(argp_FOUND_MSG ${argp_LIBRARY}) + else() + set(argp_FOUND_MSG "provided by libc") endif() endif() find_package_handle_standard_args(argp REQUIRED_VARS - argp_FOUND_MSG # NOTE: argp_LIBRARY is not required + argp_FOUND_MSG # NOTE: argp_INCLUDE_DIR and argp_LIBRARY are not required argp_parse_FOUND argp_header_FOUND - argp_INCLUDE_DIR ) if(argp_FOUND) set(argp_INCLUDE_DIRS ${argp_INCLUDE_DIR}) set(argp_LIBRARIES ${argp_LIBRARY}) - if(NOT TARGET libargp::argp) - if(argp_LIBRARY) - add_library(libargp::argp UNKNOWN IMPORTED) - set_target_properties(libargp::argp - PROPERTIES - IMPORTED_LOCATION "${argp_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${argp_INCLUDE_DIR}" - ) - endif() + if(argp_LIBRARY AND NOT TARGET libargp::argp) + add_library(libargp::argp UNKNOWN IMPORTED) + set_target_properties(libargp::argp + PROPERTIES + IMPORTED_LOCATION "${argp_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${argp_INCLUDE_DIR}" + ) endif() endif()