Skip to content

Commit

Permalink
feat: libfmt setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Aug 30, 2024
1 parent 8906f1d commit ae2ceec
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 2 deletions.
43 changes: 41 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,52 @@ concurrency:
cancel-in-progress: true

jobs:
test-setup-libfmt:
name: test setup-libfmt on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-12, macos-14 ]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Run cmake script
run: |
cmake -B build/setup-libfmt -DROOT=$PWD tests/setup-libfmt
cmake --build build/setup-libfmt
- name: Test setup-libfmt
run: |
set -o errexit -o pipefail -o noclobber -o nounset
test -f build/setup-libfmt/deps/lib/libfmt.a
test -f build/setup-libfmt/deps/include/fmt/args.h
test -f build/setup-libfmt/deps/include/fmt/chrono.h
test -f build/setup-libfmt/deps/include/fmt/color.h
test -f build/setup-libfmt/deps/include/fmt/compile.h
test -f build/setup-libfmt/deps/include/fmt/core.h
test -f build/setup-libfmt/deps/include/fmt/format.h
test -f build/setup-libfmt/deps/include/fmt/format-inl.h
test -f build/setup-libfmt/deps/include/fmt/os.h
test -f build/setup-libfmt/deps/include/fmt/ostream.h
test -f build/setup-libfmt/deps/include/fmt/printf.h
test -f build/setup-libfmt/deps/include/fmt/ranges.h
test -f build/setup-libfmt/deps/include/fmt/std.h
test -f build/setup-libfmt/deps/include/fmt/xchar.h
test -f build/setup-libfmt/deps/lib/cmake/fmt/fmt-config.cmake
test -f build/setup-libfmt/deps/lib/cmake/fmt/fmt-config-version.cmake
test -f build/setup-libfmt/deps/lib/cmake/fmt/fmt-targets.cmake
test -f build/setup-libfmt/deps/lib/cmake/fmt/fmt-targets-release.cmake
test -f build/setup-libfmt/deps/lib/pkgconfig/fmt.pc
test-setup-librachive:
name: test setup-librachive on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-12 ]
os: [ ubuntu-20.04, macos-12, macos-14 ]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -67,7 +106,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, macos-12 ]
os: [ ubuntu-20.04, macos-12, macos-14 ]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
61 changes: 61 additions & 0 deletions cmake-scripts/setup-libfmt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com).
# All rights reserved.
# This file is a part of tebako
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

def_ext_prj_t(LIBFMT "10.2.1" "312151a2d13c8327f5c9c586ac6cf7cddc1658e8f53edae0ec56509c8fa516c9")

message(STATUS "Collecting libfmt - " v${LIBFMT_VER} " at " ${LIBFMT_SOURCE_DIR})

set(__LIBFMT "${DEPS}/lib/libfmt.a")

set(CMAKE_ARGUMENTS -DCMAKE_INSTALL_PREFIX=${DEPS}
-DFMT_DOC=OFF
-DFMT_TEST=OFF
-DFMT_FUZZ=OFF
-DFMT_CUDA_TEST=OFF
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
)

if(TEBAKO_BUILD_TARGET)
list(APPEND CMAKE_ARGUMENTS -DCMAKE_C_FLAGS=--target=${TEBAKO_BUILD_TARGET})
list(APPEND CMAKE_ARGUMENTS -DCMAKE_EXE_LINKER_FLAGS=--target=${TEBAKO_BUILD_TARGET})
list(APPEND CMAKE_ARGUMENTS -DCMAKE_SHARED_LINKER_FLAGS=--target=${TEBAKO_BUILD_TARGET})
endif(TEBAKO_BUILD_TARGET)

ExternalProject_Add(${LIBFMT_PRJ}
PREFIX "${DEPS}"
URL https://github.com/fmtlib/fmt/releases/download/${LIBFMT_VER}/fmt-${LIBFMT_VER}.zip
URL_HASH SHA256=${LIBFMT_HASH}
DOWNLOAD_NO_PROGRESS true
CMAKE_ARGS ${CMAKE_ARGUMENTS}
SOURCE_DIR ${LIBFMT_SOURCE_DIR}
BINARY_DIR ${LIBFMT_BINARY_DIR}
BUILD_BYPRODUCTS ${__LIBFMT}
)

add_library(_LIBFMT STATIC IMPORTED)
set_target_properties(_LIBFMT PROPERTIES IMPORTED_LOCATION ${__LIBFMT})
add_dependencies(_LIBFMT ${LIBFMT_PRJ})
35 changes: 35 additions & 0 deletions tests/setup-libfmt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2024, [Ribose Inc](https://www.ribose.com).
# All rights reserved.
# This file is a part of tebako
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

cmake_minimum_required(VERSION 3.24.0)
project(setup-libfmt-test)

include(ExternalProject)

set(ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
set(DEPS ${CMAKE_CURRENT_BINARY_DIR}/deps)

include(${ROOT}/cmake-scripts/def-external-project.cmake)
include(${ROOT}/cmake-scripts/setup-libfmt.cmake)

0 comments on commit ae2ceec

Please sign in to comment.