Build libfmt on demand if we can't find a usable version

This commit is contained in:
Marcus Holland-Moritz 2022-06-11 09:53:22 +02:00
parent 898b2b859a
commit ce11821fd2
3 changed files with 41 additions and 12 deletions

View File

@ -86,6 +86,31 @@ if(STATIC_BUILD_DO_NOT_USE)
CACHE BOOL "disable exception tracer") CACHE BOOL "disable exception tracer")
endif() endif()
if(NOT STATIC_BUILD_DO_NOT_USE)
find_package(fmt 8 CONFIG)
endif()
if(STATIC_BUILD_DO_NOT_USE OR NOT fmt_FOUND)
configure_file(CMakeLists.txt.fmtlib fmtlib-download/CMakeLists.txt)
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fmtlib-download)
if(result)
message(FATAL_ERROR "CMake step for fmtlib failed: ${result}")
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fmtlib-download)
if(result)
message(FATAL_ERROR "Build step for fmtlib failed: ${result}")
endif()
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install;${CMAKE_PREFIX_PATH}")
include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install/include")
find_package(fmt 8 REQUIRED CONFIG PATHS "${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install" NO_DEFAULT_PATH)
endif()
list(APPEND DWARFS_BOOST_MODULES date_time filesystem program_options system) list(APPEND DWARFS_BOOST_MODULES date_time filesystem program_options system)
if(WITH_PYTHON) if(WITH_PYTHON)
@ -154,9 +179,6 @@ set(compiler_only
ON ON
CACHE BOOL "only build thrift compiler") CACHE BOOL "only build thrift compiler")
# TODO: this is due to a bug in fbthrift's CMakeLists.txt
find_package(fmt CONFIG REQUIRED)
# TODO: this is due to a bug in folly's Portability.h # TODO: this is due to a bug in folly's Portability.h
add_compile_definitions(FOLLY_CFG_NO_COROUTINES) add_compile_definitions(FOLLY_CFG_NO_COROUTINES)
@ -771,7 +793,7 @@ add_custom_target(
rm -rf CMake* CPack* CTest* Makefile Testing bin lib man folly fbthrift rm -rf CMake* CPack* CTest* Makefile Testing bin lib man folly fbthrift
thrift zstd dwarfs* mkdwarfs mount.dwarfs mount.dwarfs2 lib*.a *.cmake thrift zstd dwarfs* mkdwarfs mount.dwarfs mount.dwarfs2 lib*.a *.cmake
googletest-* _CPack_Packages install_manifest.txt share build.ninja googletest-* _CPack_Packages install_manifest.txt share build.ninja
compile_commands.json .ninja_* man1 man5 libarchive) compile_commands.json .ninja_* rules.ninja man1 man5 libarchive fmtlib*)
install( install(
TARGETS ${BINARY_TARGETS} TARGETS ${BINARY_TARGETS}

15
CMakeLists.txt.fmtlib Normal file
View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.13.4)
project(fmtlib-download NONE)
include(ExternalProject)
ExternalProject_Add(
fmtlib
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/fmtlib
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 8.1.1
CMAKE_ARGS -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install
-DCMAKE_BUILD_TYPE=Release
)

View File

@ -254,14 +254,6 @@ $ apt install ccache ninja libacl1-dev
``` ```
`ccache` and `ninja` are optional, but help with a speedy compile. `ccache` and `ninja` are optional, but help with a speedy compile.
Next, we need to build and install a static library for libfmt:
```
$ git clone https://github.com/fmtlib/fmt
$ cd fmt && mkdir build && cd build
$ cmake .. -GNinja && ninja && sudo ninja install
```
That's it! Now you can try building static binaries for DwarFS: That's it! Now you can try building static binaries for DwarFS:
``` ```