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)
61 changes: 47 additions & 14 deletions CMake/Finde2fs.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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 @@ -32,20 +32,53 @@ 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)
find_library(E2FS_LIBRARY ext2fs)
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()
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)
16 changes: 16 additions & 0 deletions CMake/Findgtest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
find_path(GTEST_INCLUDE_DIRS gtest/gtest.h)

find_library(GTEST_LIBRARIES gtest)

find_package_handle_standard_args(gtest DEFAULT_MSG GTEST_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()

mark_as_advanced(GTEST_INCLUDE_DIRS GTEST_LIBRARIES)
107 changes: 88 additions & 19 deletions CMake/Findphoton.cmake
Original file line number Diff line number Diff line change
@@ -1,34 +1,103 @@
include(FetchContent)
include(FindPackageHandleStandardArgs)
set(FETCHCONTENT_QUIET false)

# PHOTON_ENABLE_RESIZE is also consumed by our own sources, so define it
# regardless of where photon comes from. A locally installed photon is then
# expected to provide extfs and resize as well.
set(PHOTON_ENABLE_EXTFS ON)

if(NOT ORIGIN_EXT2FS)
set(PHOTON_ENABLE_RESIZE ON)
add_definitions(-DPHOTON_ENABLE_RESIZE)
endif()

FetchContent_Declare(
photon
GIT_REPOSITORY https://github.com/alibaba/PhotonLibOS.git
GIT_TAG 0178d14499d8639759a81e32ad58da5226df5e9b
)
if(DEPENDENCY_PHOTON_REPOSITORY)
FetchContent_Declare(photon
GIT_REPOSITORY ${DEPENDENCY_PHOTON_REPOSITORY}
GIT_TAG ${DEPENDENCY_PHOTON_TAG}
)

if(BUILD_TESTING)
set(BUILD_TESTING 0)
FetchContent_MakeAvailable(photon)
set(BUILD_TESTING 1)
else()
FetchContent_MakeAvailable(photon)
endif()

# photon_obj is only defined by photon's own build
if (BUILD_CURL_FROM_SOURCE)
find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)
add_dependencies(photon_obj CURL::libcurl OpenSSL::SSL OpenSSL::Crypto)
endif()

if(BUILD_TESTING)
set(BUILD_TESTING 0)
FetchContent_MakeAvailable(photon)
set(BUILD_TESTING 1)
if(NOT ORIGIN_EXT2FS)
add_dependencies(photon_obj libext2fs_build)
endif()

# Consume photon as plain archives rather than through its photon_static
# target: the latter also propagates photon's own third-party dependencies,
# whose declaration (which libraries, in which order) is an implementation
# detail that has changed between photon versions. overlaybd brings those
# dependencies itself, see the external_lib target in the top-level
# CMakeLists.txt.
set(PHOTON_INCLUDE_DIR ${photon_SOURCE_DIR}/include/)
set(PHOTON_LIBRARY ${photon_BINARY_DIR}/output/libphoton_sole.a)
set(PHOTON_EASY_WEAK_LIBRARY ${photon_BINARY_DIR}/output/libeasy_weak.a)
set(photon_FOUND yes)
else()
FetchContent_MakeAvailable(photon)
endif()
# A locally installed photon has no photon_BINARY_DIR, look the archives up
# instead. photon_sole is photon's own archive and the one paired with the
# separate weak-symbol archives; libphoton.a is the merged one, which already
# bundles them and is used as a fallback.
find_path(PHOTON_INCLUDE_DIR photon/photon.h)
find_library(PHOTON_LIBRARY NAMES photon_sole photon)
find_library(PHOTON_EASY_WEAK_LIBRARY NAMES easy_weak)

if (BUILD_CURL_FROM_SOURCE)
find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)
add_dependencies(photon_obj CURL::libcurl OpenSSL::SSL OpenSSL::Crypto)
find_package_handle_standard_args(photon DEFAULT_MSG PHOTON_LIBRARY
PHOTON_INCLUDE_DIR)
endif()

if(NOT ORIGIN_EXT2FS)
add_dependencies(photon_obj libext2fs)
endif()
if(photon_FOUND)
if(NOT TARGET PHOTON::photonlib)
add_library(PHOTON::photonlib STATIC IMPORTED)
set_target_properties(
PHOTON::photonlib
PROPERTIES IMPORTED_LOCATION "${PHOTON_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${PHOTON_INCLUDE_DIR}")
endif()
set(PHOTON_ARCHIVES PHOTON::photonlib)

# Absent when a locally installed photon only ships the merged libphoton.a.
if(PHOTON_EASY_WEAK_LIBRARY)
if(NOT TARGET PHOTON::easy_weak)
add_library(PHOTON::easy_weak STATIC IMPORTED)
set_target_properties(
PHOTON::easy_weak
PROPERTIES IMPORTED_LOCATION "${PHOTON_EASY_WEAK_LIBRARY}")
endif()
list(APPEND PHOTON_ARCHIVES PHOTON::easy_weak)
endif()

set(PHOTON_INCLUDE_DIR ${photon_SOURCE_DIR}/include/)
# The weak overrides have to follow the archive referring to them on the link
# line, hence the aggregate rather than a plain list at every call site.
if(NOT TARGET PHOTON::photon)
add_library(PHOTON::photon INTERFACE IMPORTED)
set_target_properties(
PHOTON::photon
PROPERTIES INTERFACE_LINK_LIBRARIES "${PHOTON_ARCHIVES}"
INTERFACE_INCLUDE_DIRECTORIES "${PHOTON_INCLUDE_DIR}")
endif()

# When photon is built here, the archives above only exist once its own
# targets have run. The dependency is followed through the aggregate, so
# everything linking PHOTON::photon waits for them.
if(DEPENDENCY_PHOTON_REPOSITORY)
add_dependencies(PHOTON::photonlib photon_static)
if(TARGET PHOTON::easy_weak)
add_dependencies(PHOTON::easy_weak easy_weak)
endif()
endif()
endif()
Loading
Loading