From: Kefu Chai Date: Fri, 23 Jul 2021 09:52:12 +0000 (+0800) Subject: cmake: add an option "WITH_FMT_HEADER_ONLY" X-Git-Tag: v17.1.0~1304^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d81478b5690f9e3d36a7738223c737fc96a34d28;p=ceph.git cmake: add an option "WITH_FMT_HEADER_ONLY" in this change: * an interface library named "fmt-header-only" is introduced. it brings the support to the header only fmt library. * fmt::fmt is renamed to fmt * an option named "WITH_FMT_HEADER_ONLY" is introduced * fmt::fmt is an alias of "fmt-header-only" if "WITH_FMT_HEADER_ONLY" is "ON", and an alias of "fmt" otherwise. because fmt is packaged in EPEL, while librados is packaged in RHEL, so we cannot have fmt as a runtime dependency of librados. to address this issue an option "WITH_FMT_HEADER_ONLY" is introduced, so that we can enable it when building Ceph with the header version of fmt. and the built packages won't have runtime dependency of fmt. Signed-off-by: Kefu Chai --- diff --git a/cmake/modules/Findfmt.cmake b/cmake/modules/Findfmt.cmake index 747d924e901e..734c2b0571c2 100644 --- a/cmake/modules/Findfmt.cmake +++ b/cmake/modules/Findfmt.cmake @@ -35,9 +35,27 @@ mark_as_advanced( fmt_VERSION_STRING) if(fmt_FOUND AND NOT (TARGET fmt::fmt)) - add_library(fmt::fmt UNKNOWN IMPORTED) - set_target_properties(fmt::fmt PROPERTIES + add_library(fmt-header-only INTERFACE) + set_target_properties(fmt-header-only PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${fmt_INCLUDE_DIR}" + INTERFACE_COMPILE_DEFINITIONS FMT_HEADER_ONLY=1 + INTERFACE_COMPILE_FEATURES cxx_std_11) + + add_library(fmt UNKNOWN IMPORTED GLOBAL) + set_target_properties(fmt PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${fmt_INCLUDE_DIR}" + INTERFACE_COMPILE_FEATURES cxx_std_11 IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" IMPORTED_LOCATION "${fmt_LIBRARY}") + + if(WITH_FMT_HEADER_ONLY) + # please note, this is different from how upstream defines fmt::fmt. + # in order to force 3rd party libraries to link against fmt-header-only if + # WITH_FMT_HEADER_ONLY is ON, we have to point fmt::fmt to fmt-header-only + # in this case. + add_library(fmt::fmt ALIAS fmt-header-only) + else() + add_library(fmt::fmt ALIAS fmt) + endif() + endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eb957cdcf634..815e2963e9be 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -326,6 +326,7 @@ add_subdirectory(json_spirit) include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/src/xxHash") include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/src/rapidjson/include") +option(WITH_FMT_HEADER_ONLY "use header-only version of fmt library" OFF) find_package(fmt 6.0.0 QUIET) if(fmt_FOUND) include_directories(SYSTEM "${fmt_INCLUDE_DIR}") @@ -387,6 +388,15 @@ set(CMAKE_EXTRA_INCLUDE_FILES "sys/time.h") CHECK_TYPE_SIZE(suseconds_t SUSECONDS_T) unset(CMAKE_EXTRA_INCLUDE_FILES) +function(compile_with_fmt target) + get_target_property(fmt_compile_definitions + fmt::fmt INTERFACE_COMPILE_DEFINITIONS) + if(fmt_compile_definitions) + target_compile_definitions(${target} PUBLIC + ${fmt_compile_definitions}) + endif() +endfunction() + set(libcommon_files ${CMAKE_BINARY_DIR}/src/include/ceph_ver.h ceph_ver.c @@ -424,6 +434,7 @@ endif() set_source_files_properties(ceph_ver.c APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_BINARY_DIR}/src/include/ceph_ver.h) add_library(common-objs OBJECT ${libcommon_files}) +compile_with_fmt(common-objs) add_dependencies(common-objs legacy-option-headers) if(WITH_JAEGER) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index e16b5aba346b..d905c9f974ab 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -189,6 +189,7 @@ target_compile_definitions(common-common-objs PRIVATE "CMAKE_INSTALL_LIBDIR=\"${CMAKE_INSTALL_LIBDIR}\"" "CEPH_INSTALL_FULL_PKGLIBDIR=\"${CEPH_INSTALL_FULL_PKGLIBDIR}\"" "CEPH_INSTALL_DATADIR=\"${CEPH_INSTALL_DATADIR}\"") +compile_with_fmt(common-common-objs) add_dependencies(common-common-objs legacy-option-headers) set(common_mountcephfs_srcs diff --git a/src/mon/CMakeLists.txt b/src/mon/CMakeLists.txt index 088fa6a0cdd6..b4056fdb1ecd 100644 --- a/src/mon/CMakeLists.txt +++ b/src/mon/CMakeLists.txt @@ -33,7 +33,10 @@ endif() add_library(mon STATIC ${lib_mon_srcs}) -target_link_libraries(mon kv heap_profiler) +target_link_libraries(mon + kv + heap_profiler + fmt::fmt) if(WITH_JAEGER) target_link_libraries(mon jaeger-base) endif() diff --git a/src/msg/CMakeLists.txt b/src/msg/CMakeLists.txt index e6d0b589b429..9cca15c81555 100644 --- a/src/msg/CMakeLists.txt +++ b/src/msg/CMakeLists.txt @@ -38,6 +38,7 @@ if(HAVE_RDMA) endif() add_library(common-msg-objs OBJECT ${msg_srcs}) +compile_with_fmt(common-msg-objs) target_include_directories(common-msg-objs PRIVATE ${OPENSSL_INCLUDE_DIR}) if(WITH_DPDK) diff --git a/src/neorados/CMakeLists.txt b/src/neorados/CMakeLists.txt index 50272374d2b5..8695b48f0f92 100644 --- a/src/neorados/CMakeLists.txt +++ b/src/neorados/CMakeLists.txt @@ -1,7 +1,9 @@ add_library(neorados_objs OBJECT RADOSImpl.cc) +compile_with_fmt(neorados_objs) add_library(neorados_api_obj OBJECT RADOS.cc) +compile_with_fmt(neorados_api_obj) add_library(libneorados STATIC $ diff --git a/src/osd/CMakeLists.txt b/src/osd/CMakeLists.txt index 0d0ca63b347b..373456fc65d4 100644 --- a/src/osd/CMakeLists.txt +++ b/src/osd/CMakeLists.txt @@ -50,7 +50,7 @@ endif() add_library(osd STATIC ${osd_srcs}) target_link_libraries(osd PUBLIC dmclock::dmclock Boost::MPL - PRIVATE os heap_profiler cpu_profiler ${CMAKE_DL_LIBS}) + PRIVATE os heap_profiler cpu_profiler fmt::fmt ${CMAKE_DL_LIBS}) if(WITH_LTTNG) add_dependencies(osd osd-tp pg-tp) endif() diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 1a92898c571e..fdfde4f34ef9 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -20,7 +20,7 @@ if(NOT WIN32) set(neorados_srcs neorados.cc) add_executable(neorados ${neorados_srcs}) - target_link_libraries(neorados libneorados spawn ${CMAKE_DL_LIBS}) + target_link_libraries(neorados libneorados spawn fmt::fmt ${CMAKE_DL_LIBS}) #install(TARGETS neorados DESTINATION bin) endif()