Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions CMake/FindCURL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ include(FetchContent)
if(${BUILD_CURL_FROM_SOURCE})
message("Add and build standalone libcurl")
include(FetchContent)
FetchContent_Declare(
curl_bundle
GIT_REPOSITORY https://github.com/curl/curl.git
GIT_TAG curl-7_42_1
FetchContent_Declare(curl_bundle
GIT_REPOSITORY ${DEPENDENCY_CURL_REPOSITORY}
GIT_TAG ${DEPENDENCY_CURL_TAG}
GIT_PROGRESS 1)

FetchContent_GetProperties(curl_bundle)
Expand Down
7 changes: 3 additions & 4 deletions CMake/FindOpenSSL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ if(${BUILD_CURL_FROM_SOURCE})
include(FetchContent)

# make openssl into bundle
FetchContent_Declare(
openssl102
GIT_REPOSITORY https://github.com/openssl/openssl.git
GIT_TAG OpenSSL_1_0_2-stable
FetchContent_Declare(openssl102
GIT_REPOSITORY ${DEPENDENCY_OPENSSL_REPOSITORY}
GIT_TAG ${DEPENDENCY_OPENSSL_TAG}
GIT_PROGRESS 1)

FetchContent_GetProperties(openssl102)
Expand Down
33 changes: 22 additions & 11 deletions CMake/FindRapidJSON.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(RAPIDJSON RapidJSON)
endif()
include(FetchContent)
include(FindPackageHandleStandardArgs)

if (NOT RAPIDJSON_FOUND)
if(DEPENDENCY_RAPIDJSON_REPOSITORY)
if (NOT rapidjson_POPULATED)
FetchContent_Populate(
rapidjson
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
GIT_TAG 80b6d1c83402a5785c486603c5611923159d0894
GIT_SUBMODULES ""
)
# header only, no need to build it
FetchContent_Populate(
rapidjson
GIT_REPOSITORY ${DEPENDENCY_RAPIDJSON_REPOSITORY}
GIT_TAG ${DEPENDENCY_RAPIDJSON_TAG}
GIT_SUBMODULES ""
)
endif()
FetchContent_GetProperties(rapidjson)
set(RAPIDJSON_INCLUDE_DIRS "${rapidjson_SOURCE_DIR}/include")
set(RapidJSON_FOUND yes)
else()
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(RAPIDJSON RapidJSON)
endif()

if (NOT RAPIDJSON_FOUND)
find_path(RAPIDJSON_INCLUDE_DIRS rapidjson/document.h)
find_package_handle_standard_args(RapidJSON DEFAULT_MSG
RAPIDJSON_INCLUDE_DIRS)
endif()
endif()

add_definitions("-DRAPIDJSON_HAS_STDSTRING=1")
9 changes: 9 additions & 0 deletions CMake/Findaio.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@ find_library(AIO_LIBRARIES aio)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(aio DEFAULT_MSG AIO_LIBRARIES AIO_INCLUDE_DIR)

if(AIO_FOUND AND NOT TARGET AIO::aio)
add_library(AIO::aio UNKNOWN IMPORTED)
set_target_properties(
AIO::aio
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${AIO_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${AIO_INCLUDE_DIR}")
endif()

mark_as_advanced(AIO_INCLUDE_DIR AIO_LIBRARIES)
83 changes: 67 additions & 16 deletions CMake/Finde2fs.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
include(FindPackageHandleStandardArgs)

if(NOT ORIGIN_EXT2FS)
if(DEPENDENCY_E2FSPROGS_REPOSITORY)
message("Add and build standalone libext2fs")
include(FetchContent)
FetchContent_Declare(
e2fsprogs
GIT_REPOSITORY https://github.com/data-accelerator/e2fsprogs.git
GIT_TAG 404deb95e6b0ed0ceb0148d289977e65bee7f8d0

FetchContent_Declare(e2fsprogs
GIT_REPOSITORY ${DEPENDENCY_E2FSPROGS_REPOSITORY}
GIT_TAG ${DEPENDENCY_E2FSPROGS_TAG}
)
FetchContent_GetProperties(e2fsprogs)

if(NOT TARGET libext2fs_build)
FetchContent_MakeAvailable(e2fsprogs)
set(LIBEXT2FS_INSTALL_DIR ${e2fsprogs_SOURCE_DIR}/build/libext2fs CACHE STRING "")
set(LIBEXT2FS_INSTALL_DIR ${e2fsprogs_SOURCE_DIR}/build/v1.47.0-opt CACHE STRING "")
set(E2FS_RESIZE_DIR ${e2fsprogs_SOURCE_DIR}/build/resize CACHE STRING "path to e2fsprogs resize build dir")
set(E2FS_INSTALL_LIB_DIR ${LIBEXT2FS_INSTALL_DIR}/lib CACHE STRING "path to e2fsprogs install-libs output")

Expand All @@ -23,6 +21,8 @@ if(NOT ORIGIN_EXT2FS)
# line, so setting CFLAGS via the environment is ignored -- we patch
# build.sh in place instead. `-std=gnu11` is supported by every
# compiler used across the release matrix (GCC 8+).
#
# build.sh also picks its own compiler, hence CC from the environment.
add_custom_command(
OUTPUT ${LIBEXT2FS_INSTALL_DIR}/lib
BYPRODUCTS
Expand All @@ -40,20 +40,71 @@ if(NOT ORIGIN_EXT2FS)
set(E2FS_FOUND yes)
set(E2FS_LIBRARY ${LIBEXT2FS_INSTALL_DIR}/lib/libext2fs.so)
set(E2FS_COM_ERR_LIBRARY ${e2fsprogs_SOURCE_DIR}/build/lib/libcom_err.a)
# E2FS_LIBRARIES is what photon's own build consumes, overlaybd links the
# imported targets below instead.
set(E2FS_LIBRARIES ${E2FS_LIBRARY} ${E2FS_COM_ERR_LIBRARY})
set(E2FS_INCLUDE_DIR ${LIBEXT2FS_INSTALL_DIR}/include)
set(E2FS_INCLUDE_DIRS ${E2FS_INCLUDE_DIR})

if(NOT TARGET libext2fs)
add_library(libext2fs UNKNOWN IMPORTED)
endif()
add_dependencies(libext2fs libext2fs_build)

# The libraries and headers only appear once libext2fs_build has run, but
# imported targets validate INTERFACE_INCLUDE_DIRECTORIES at configure time.
file(MAKE_DIRECTORY ${E2FS_INCLUDE_DIR})
else()
find_path(E2FS_INCLUDE_DIRS ext2fs/ext2fs.h)
find_library(E2FS_LIBRARIES ext2fs)

# libext2fs is LGPL, so it is linked dynamically no matter what: restore the
# normal suffix list for this lookup, which FULL_STATIC would otherwise
# narrow down to the archive. The build from source above does the same, by
# naming libext2fs.so directly.
set(_e2fs_suffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAVE})
find_library(E2FS_LIBRARY ext2fs)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_e2fs_suffixes})

find_library(E2FS_COM_ERR_LIBRARY com_err)
set(E2FS_LIBRARIES ${E2FS_LIBRARY})

find_package_handle_standard_args(e2fs DEFAULT_MSG E2FS_LIBRARY
E2FS_INCLUDE_DIRS)
endif()

find_package_handle_standard_args(e2fs DEFAULT_MSG E2FS_LIBRARIES E2FS_INCLUDE_DIRS)
if(E2FS_FOUND)
if(E2FS_COM_ERR_LIBRARY AND NOT TARGET E2FSPROGS::libcom_err)
add_library(E2FSPROGS::libcom_err UNKNOWN IMPORTED)
set_target_properties(
E2FSPROGS::libcom_err
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${E2FS_COM_ERR_LIBRARY}")
if(DEPENDENCY_E2FSPROGS_REPOSITORY)
add_dependencies(E2FSPROGS::libcom_err libext2fs_build)
endif()
endif()

if(NOT TARGET E2FSPROGS::libext2fs)
add_library(E2FSPROGS::libext2fs UNKNOWN IMPORTED)
set_target_properties(
E2FSPROGS::libext2fs
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${E2FS_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${E2FS_INCLUDE_DIRS}")
# libext2fs calls into com_err, which therefore has to follow it.
if(TARGET E2FSPROGS::libcom_err)
set_property(TARGET E2FSPROGS::libext2fs PROPERTY
INTERFACE_LINK_LIBRARIES E2FSPROGS::libcom_err)
endif()
if(DEPENDENCY_E2FSPROGS_REPOSITORY)
add_dependencies(E2FSPROGS::libext2fs libext2fs_build)
endif()
endif()

# photon's extfs.cpp/mkfs.cpp live inside the photon archive and reference
# the ext2fs_* symbols. An executable that links libext2fs directly gets it
# placed ahead of the transitively-pulled photon archive, and the
# --as-needed default on modern toolchains then drops libext2fs.so before
# those references are seen, leaving them undefined. Linking it through this
# list keeps it wherever CMake orders it; every consumer of libext2fs goes
# through photon's extfs, so keeping it unconditionally is correct.
set(E2FS_LIBEXT2FS_LINK -Wl,--no-as-needed E2FSPROGS::libext2fs -Wl,--as-needed)
endif()

mark_as_advanced(E2FS_INCLUDE_DIRS E2FS_LIBRARIES)
mark_as_advanced(E2FS_INCLUDE_DIRS E2FS_LIBRARY E2FS_COM_ERR_LIBRARY)
62 changes: 62 additions & 0 deletions CMake/Finderofsutils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
include(FetchContent)
include(FindPackageHandleStandardArgs)

if(DEPENDENCY_EROFS_UTILS_REPOSITORY)
FetchContent_Declare(erofs-utils
GIT_REPOSITORY ${DEPENDENCY_EROFS_UTILS_REPOSITORY}
GIT_TAG ${DEPENDENCY_EROFS_UTILS_TAG}
)
FetchContent_GetProperties(erofs-utils)
if(NOT erofs-utils_POPULATED)
FetchContent_Populate(erofs-utils)
endif()

set(EROFS_LIB_INCLUDE_DIR "${erofs-utils_SOURCE_DIR}/include/" CACHE PATH "erofs-utils include path.")
set(EROFS_CONFIG_FILE "${erofs-utils_SOURCE_DIR}/config.h" CACHE PATH "erofs-utils config file.")
set(EROFS_LIB_STATIC "${erofs-utils_SOURCE_DIR}/lib/.libs/liberofs.a" CACHE PATH "erofs-utils static lib.")

# liberofs.a and config.h are produced at build time; make sure the include
# dir exists at configure time so EROFS::utils' INTERFACE_INCLUDE_DIRECTORIES
# passes CMake's imported-target path validation.
file(MAKE_DIRECTORY ${EROFS_LIB_INCLUDE_DIR})

# build erofs-utils with its own autotools at build time (not configure time)
if(NOT TARGET liberofs_build)
add_custom_command(
OUTPUT ${EROFS_LIB_STATIC}
WORKING_DIRECTORY ${erofs-utils_SOURCE_DIR}
COMMAND ./autogen.sh &&
./configure --disable-lz4 --disable-lzma --without-libzstd
--without-uuid --disable-multithreading &&
make)
add_custom_target(liberofs_build DEPENDS ${EROFS_LIB_STATIC})
endif()

set(erofsutils_FOUND yes)
if(NOT TARGET EROFS::utils)
add_library(EROFS::utils STATIC IMPORTED)
endif()
add_dependencies(EROFS::utils liberofs_build)
else()
find_path(EROFS_LIB_INCLUDE_DIR erofs/tar.h)
find_library(EROFS_LIB_STATIC erofs)
# config.h is generated by erofs-utils' own configure and force-included as
# a compile option below, so a local installation has to provide it as well
find_file(EROFS_CONFIG_FILE erofs/config.h)

find_package_handle_standard_args(erofsutils DEFAULT_MSG EROFS_LIB_STATIC
EROFS_LIB_INCLUDE_DIR EROFS_CONFIG_FILE)

if(erofsutils_FOUND AND NOT TARGET EROFS::utils)
add_library(EROFS::utils STATIC IMPORTED)
endif()
endif()

if(TARGET EROFS::utils)
set_target_properties(
EROFS::utils
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${EROFS_LIB_STATIC}"
INTERFACE_INCLUDE_DIRECTORIES "${EROFS_LIB_INCLUDE_DIR}"
INTERFACE_COMPILE_OPTIONS "-include${EROFS_CONFIG_FILE}")
endif()
16 changes: 16 additions & 0 deletions CMake/Findgflags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
find_path(GFLAGS_INCLUDE_DIRS gflags/gflags.h)

find_library(GFLAGS_LIBRARIES gflags)

find_package_handle_standard_args(gflags DEFAULT_MSG GFLAGS_LIBRARIES
GFLAGS_INCLUDE_DIRS)

if(gflags_FOUND AND NOT TARGET GFLAGS::gflags)
add_library(GFLAGS::gflags UNKNOWN IMPORTED)
set_target_properties(
GFLAGS::gflags
PROPERTIES IMPORTED_LOCATION "${GFLAGS_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${GFLAGS_INCLUDE_DIRS}")
endif()

mark_as_advanced(GFLAGS_INCLUDE_DIRS GFLAGS_LIBRARIES)
27 changes: 27 additions & 0 deletions CMake/Findgtest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
find_path(GTEST_INCLUDE_DIRS gtest/gtest.h)

find_library(GTEST_LIBRARIES gtest)

# gtest_main is only needed by the tests that do not bring their own main()
find_library(GTEST_MAIN_LIBRARIES gtest_main)

find_package_handle_standard_args(gtest DEFAULT_MSG GTEST_LIBRARIES
GTEST_MAIN_LIBRARIES GTEST_INCLUDE_DIRS)

if(gtest_FOUND AND NOT TARGET GTEST::gtest)
add_library(GTEST::gtest UNKNOWN IMPORTED)
set_target_properties(
GTEST::gtest
PROPERTIES IMPORTED_LOCATION "${GTEST_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIRS}")
endif()

if(gtest_FOUND AND NOT TARGET GTEST::gtest_main)
add_library(GTEST::gtest_main UNKNOWN IMPORTED)
set_target_properties(
GTEST::gtest_main
PROPERTIES IMPORTED_LOCATION "${GTEST_MAIN_LIBRARIES}"
INTERFACE_LINK_LIBRARIES GTEST::gtest)
endif()

mark_as_advanced(GTEST_INCLUDE_DIRS GTEST_LIBRARIES GTEST_MAIN_LIBRARIES)
4 changes: 2 additions & 2 deletions CMake/Findliburing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ endif()

FetchContent_Declare(
liburing
GIT_REPOSITORY https://github.com/axboe/liburing.git
GIT_TAG liburing-2.8
GIT_REPOSITORY ${DEPENDENCY_LIBURING_REPOSITORY}
GIT_TAG ${DEPENDENCY_LIBURING_TAG}
)

# download only, no add_subdirectory (liburing is a plain Makefile project)
Expand Down
Loading
Loading