Added FetchContent for Unix-like. SEAL's dependencies are not yet transitive.

This commit is contained in:
Wei Dai 2020-10-14 08:27:56 -07:00
Родитель 72c91810d0
Коммит c691a875c5
5 изменённых файлов: 170 добавлений и 242 удалений

Просмотреть файл

@ -104,13 +104,20 @@ include(SEALMacros)
#########################
# External dependencies #
#########################
if(NOT MSVC) ## TODO: remove
# [option] SEAL_BUILD_DEPS (default: ON)
# Download and build missing dependencies, throw error if disabled.
set(SEAL_BUILD_DEPS_OPTION_STR "Automatically downloand and build missing dependencies")
set(SEAL_BUILD_DEPS_OPTION_STR "Automatically downloand and build unmet dependencies")
option(SEAL_BUILD_DEPS ${SEAL_BUILD_DEPS_OPTION_STR} ON)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR ${SEAL_THIRDPARTY_DIR}/external CACHE STRING "" FORCE)
if(SEAL_BUILD_DEPS)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR ${SEAL_THIRDPARTY_DIR}/external CACHE STRING "" FORCE)
mark_as_advanced(FETCHCONTENT_BASE_DIR)
mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED)
mark_as_advanced(FETCHCONTENT_QUIET)
endif()
function(seal_create_cache_entries dir_name)
set(cce_file_name ${dir_name}/cache_init.txt)
@ -127,24 +134,77 @@ function(seal_create_cache_entries dir_name)
file(APPEND "${cce_file_name}" "set(CMAKE_SYSTEM_VERSION ${CMAKE_SYSTEM_VERSION} CACHE STRING \"\" FORCE)\n")
endfunction()
# [option] SEAL_USE_MSGSL
# [option] SEAL_USE_MSGSL (default: ON)
set(SEAL_USE_MSGSL_OPTION_STR "Use Microsoft GSL")
option(SEAL_USE_MSGSL ${SEAL_USE_MSGSL_OPTION_STR} ON)
include(ExternalMSGSL)
if(SEAL_USE_MSGSL)
find_package(Microsoft.GSL CONFIG)
if(Microsoft.GSL_FOUND)
set(GSL "Microsoft.GSL::GSL")
else()
if (SEAL_BUILD_DEPS)
message(STATUS "Download Microsoft.GSL ...")
include(ExternalMSGSL)
set(GSL "GSL")
else()
message(FATAL_ERROR "Failed to find Microsoft.GSL.")
endif()
endif()
endif()
# [option] SEAL_USE_ZLIB
# [option] SEAL_USE_ZLIB (default: ON)
set(SEAL_USE_ZLIB_OPTION_STR "Use ZLIB for compressed serialization")
option(SEAL_USE_ZLIB ${SEAL_USE_ZLIB_OPTION_STR} ON)
include(ExternalZLIB)
if(SEAL_USE_ZLIB)
find_package(ZLIB 1.2.11)
if(ZLIB_FOUND)
set(ZLIB "ZLIB::ZLIB")
else()
if (SEAL_BUILD_DEPS)
message(STATUS "Download ZLIB ...")
include(ExternalZLIB)
set(ZLIB "zlibstatic")
else()
message(FATAL_ERROR "Failed to find ZLIB")
endif()
endif()
endif()
# [option] SEAL_USE_ZSTD
# [option] SEAL_USE_ZSTD (default: ON)
set(SEAL_USE_ZSTD_OPTION_STR "Use Zstandard for compressed serialization")
option(SEAL_USE_ZSTD ${SEAL_USE_ZSTD_OPTION_STR} ON)
include(ExternalZSTD)
if(SEAL_USE_ZSTD)
find_package(zstd CONFIG)
if(zstd_FOUND)
set(ZSTD "libzstd")
else()
if (SEAL_BUILD_DEPS)
message(STATUS "Download ZSTD ...")
include(ExternalZSTD)
set(ZSTD "libzstd_static")
else()
message(FATAL_ERROR "Failed to find ZSTD")
endif()
endif()
endif()
# if SEAL_BUILD_TESTS is ON, use googletest
include(ExternalGTest)
if(SEAL_BUILD_TESTS)
find_package(GTest 1.10.0 CONFIG)
if(GTest_FOUND)
set(GTEST "GTest::gtest")
else()
if (SEAL_BUILD_DEPS)
message(STATUS "Download GTest ...")
include(ExternalGTest)
set(GTEST "gtest")
else()
message(FATAL_ERROR "Failed to find GTest")
endif()
endif()
endif()
endif()
####################
# SEAL C++ library #
####################
@ -264,15 +324,16 @@ seal_set_language(seal_obj)
seal_set_include_directories(seal_obj)
if(SEAL_USE_MSGSL AND NOT MSVC)
target_link_libraries(seal_obj PRIVATE GSL)
target_link_libraries(seal_obj PRIVATE ${GSL})
target_include_directories(seal PUBLIC $<BUILD_INTERFACE:${SEAL_MSGSL_INCLUDE_DIR}>)
endif()
if(SEAL_USE_ZLIB AND NOT MSVC)
target_link_libraries(seal_obj PRIVATE zlibstatic)
target_link_libraries(seal_obj PRIVATE ${ZLIB})
endif()
if(SEAL_USE_ZSTD AND NOT MSVC)
target_link_libraries(seal_obj PRIVATE libzstd_static)
target_link_libraries(seal_obj PRIVATE ${ZSTD})
target_include_directories(seal_obj PRIVATE $<BUILD_INTERFACE:${SEAL_ZSTD_INCLUDE_DIR}>)
endif()
@ -285,11 +346,6 @@ seal_set_include_directories(seal)
seal_link_threads(seal)
seal_install_target(seal SEALTargets)
# Conditionally add MSGSL include directory to build interface
if(SEAL_USE_MSGSL AND NOT MSVC)
target_include_directories(seal PUBLIC $<BUILD_INTERFACE:${SEAL_MSGSL_INCLUDE_DIR}>)
endif()
# Conditionally build the shared library
if(BUILD_SHARED_LIBS)
add_library(seal_shared SHARED $<TARGET_OBJECTS:seal_obj>)
@ -303,16 +359,6 @@ if(BUILD_SHARED_LIBS)
seal_install_target(seal_shared SEALTargets)
endif()
# In UNIX-like platforms combine manually seal and zlibstatic into a single archive
if(SEAL_USE_ZLIB AND NOT MSVC)
seal_combine_archives(seal zlibstatic)
endif()
# In UNIX-like platforms combine manually seal and libzstd_static into a single archive
if(SEAL_USE_ZSTD AND NOT MSVC)
seal_combine_archives(seal libzstd_static)
endif()
#########################
# SEAL C export library #
#########################
@ -386,16 +432,6 @@ export(
NAMESPACE SEAL::
FILE ${SEAL_TARGETS_FILENAME})
# In UNIX-like platforms install MSGSL header files
if(SEAL_USE_MSGSL AND NOT MSVC)
install(
DIRECTORY
${SEAL_MSGSL_INCLUDE_DIR}/gsl
DESTINATION
${SEAL_INCLUDES_INSTALL_DIR}
)
endif()
#####################
# SEAL C++ examples #
#####################

Просмотреть файл

@ -1,40 +1,18 @@
# Google Test
# This follows the example in
# https://github.com/google/googletest/blob/release-1.10.0/googletest/README.md.
# Download and configure
if(SEAL_BUILD_TESTS AND NOT MSVC)
message(STATUS "Setting up Google Test ...")
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
OUTPUT_QUIET
RESULT_VARIABLE result
WORKING_DIRECTORY ${SEAL_THIRDPARTY_DIR}/googletest)
if(result)
message(WARNING "Failed to download Google Test (${result}); disabling `SEAL_BUILD_TESTS`")
endif()
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
mark_as_advanced(BUILD_GMOCK)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
mark_as_advanced(INSTALL_GTEST)
endif()
# Build
if(SEAL_BUILD_TESTS AND NOT MSVC)
execute_process(COMMAND ${CMAKE_COMMAND} --build .
OUTPUT_QUIET
RESULT_VARIABLE result
WORKING_DIRECTORY ${SEAL_THIRDPARTY_DIR}/googletest)
if(result)
message(WARNING "Failed to build Google Test (${result}); disabling `SEAL_BUILD_TESTS`")
endif()
endif()
# Set up the targets
if(SEAL_BUILD_TESTS AND NOT MSVC)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(
${SEAL_THIRDPARTY_DIR}/googletest/src
${SEAL_THIRDPARTY_DIR}/googletest/build
EXCLUDE_FROM_ALL)
endif()
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # 1.10.0
)
FetchContent_GetProperties(googletest)
FetchContent_Populate(googletest)
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
mark_as_advanced(BUILD_GMOCK)
mark_as_advanced(INSTALL_GTEST)
mark_as_advanced(FETCHCONTENT_SOURCE_DIR_GOOGLETEST)
mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_GOOGLETEST)
add_subdirectory(
${googletest_SOURCE_DIR}
${googletest_BINARY_DIR}
EXCLUDE_FROM_ALL)

Просмотреть файл

@ -1,50 +1,16 @@
# Download and configure
if(SEAL_USE_MSGSL AND NOT MSVC)
message(STATUS "Setting up MSGSL ...")
if(NOT CMAKE_TOOLCHAIN_FILE)
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
OUTPUT_QUIET
RESULT_VARIABLE result
WORKING_DIRECTORY ${SEAL_THIRDPARTY_DIR}/msgsl)
else()
seal_create_cache_entries(${SEAL_THIRDPARTY_DIR}/msgsl)
if(EXISTS ${SEAL_THIRDPARTY_DIR}/msgsl/CMakeCache.txt)
# Force regenerating make files. When cross compiling we might be
# compiling more than one platform at a time.
file(REMOVE ${SEAL_THIRDPARTY_DIR}/msgsl/CMakeCache.txt)
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . -Ccache_init.txt
OUTPUT_QUIET
RESULT_VARIABLE result
WORKING_DIRECTORY ${SEAL_THIRDPARTY_DIR}/msgsl)
endif()
if(result)
message(WARNING "Failed to download MSGSL (${result}); disabling `SEAL_USE_MSGSL`")
endif()
endif()
# Build
if(SEAL_USE_MSGSL AND NOT MSVC)
execute_process(
COMMAND ${CMAKE_COMMAND} --build .
OUTPUT_QUIET
RESULT_VARIABLE result
WORKING_DIRECTORY ${SEAL_THIRDPARTY_DIR}/msgsl)
if(result)
message(WARNING "Failed to build MSGSL (${result}); disabling `SEAL_USE_MSGSL`")
endif()
set(GSL_CXX_STANDARD "14" CACHE STRING "" FORCE)
mark_as_advanced(GSL_CXX_STANDARD )
set(GSL_TEST OFF CACHE BOOL "" FORCE)
mark_as_advanced(GSL_TEST)
endif()
# Set up the targets
if(SEAL_USE_MSGSL AND NOT MSVC)
add_subdirectory(
${SEAL_THIRDPARTY_DIR}/msgsl/src
EXCLUDE_FROM_ALL)
set(SEAL_MSGSL_INCLUDE_DIR ${SEAL_THIRDPARTY_DIR}/msgsl/src/include)
endif()
FetchContent_Declare(
msgsl
GIT_REPOSITORY https://github.com/microsoft/GSL.git
GIT_TAG 0f6dbc9e2915ef5c16830f3fa3565738de2a9230 # 3.1.0
)
FetchContent_GetProperties(msgsl)
FetchContent_Populate(msgsl)
set(GSL_CXX_STANDARD "14" CACHE STRING "" FORCE)
set(GSL_TEST OFF CACHE BOOL "" FORCE)
mark_as_advanced(GSL_CXX_STANDARD )
mark_as_advanced(GSL_TEST)
mark_as_advanced(FETCHCONTENT_SOURCE_DIR_MSGSL)
mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_MSGSL)
add_subdirectory(
${msgsl_SOURCE_DIR}
EXCLUDE_FROM_ALL)

Просмотреть файл

@ -1,68 +1,35 @@
FetchContent_Declare(
zlib
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG cacf7f1d4e3d44d871b605da3b647f07d718623f # 1.2.11
)
FetchContent_GetProperties(zlib)
FetchContent_Populate(zlib)
set(SKIP_INSTALL_ALL ON CACHE BOOL "" FORCE)
mark_as_advanced(AMD64)
mark_as_advanced(ASM686)
mark_as_advanced(EXECUTABLE_OUTPUT_PATH)
mark_as_advanced(CMAKE_INSTALL_PREFIX)
mark_as_advanced(INSTALL_BIN_DIR)
mark_as_advanced(INSTALL_INC_DIR)
mark_as_advanced(INSTALL_LIB_DIR)
mark_as_advanced(INSTALL_MAN_DIR)
mark_as_advanced(INSTALL_PKGCONFIG_DIR)
mark_as_advanced(LIBRARY_OUTPUT_PATH)
mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY)
mark_as_advanced(ZLIB_BUILD_STATIC)
mark_as_advanced(SKIP_INSTALL_ALL)
mark_as_advanced(FETCHCONTENT_SOURCE_DIR_ZLIB)
mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_ZLIB)
# ZLIB has no VERSION given to project(), needs to suppress CMP0048 warning
if(SEAL_USE_ZLIB AND NOT MSVC)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS TRUE CACHE INTERNAL "Suppress CMP0048 warning" FORCE)
endif()
# Download and configure
if(SEAL_USE_ZLIB AND NOT MSVC)
message(STATUS "Setting up ZLIB ...")
if(NOT CMAKE_TOOLCHAIN_FILE)
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
OUTPUT_QUIET
RESULT_VARIABLE result
WORKING_DIRECTORY ${SEAL_THIRDPARTY_DIR}/zlib)
else()
seal_create_cache_entries(${SEAL_THIRDPARTY_DIR}/zlib)
if(EXISTS ${SEAL_THIRDPARTY_DIR}/zlib/build/CMakeCache.txt)
# Force regenerating make files. When cross compiling we might be
# compiling more than one platform at a time.
file(REMOVE ${SEAL_THIRDPARTY_DIR}/zlib/build/CMakeCache.txt)
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . -Ccache_init.txt
OUTPUT_QUIET
RESULT_VARIABLE result
WORKING_DIRECTORY ${SEAL_THIRDPARTY_DIR}/zlib)
endif()
if(result)
message(WARNING "Failed to download ZLIB (${result}); disabling `SEAL_USE_ZLIB`")
endif()
mark_as_advanced(AMD64)
mark_as_advanced(ASM686)
mark_as_advanced(EXECUTABLE_OUTPUT_PATH)
mark_as_advanced(CMAKE_INSTALL_PREFIX)
mark_as_advanced(INSTALL_BIN_DIR)
mark_as_advanced(INSTALL_INC_DIR)
mark_as_advanced(INSTALL_LIB_DIR)
mark_as_advanced(INSTALL_MAN_DIR)
mark_as_advanced(INSTALL_PKGCONFIG_DIR)
mark_as_advanced(LIBRARY_OUTPUT_PATH)
mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY)
endif()
# Build
if(SEAL_USE_ZLIB AND NOT MSVC)
execute_process(COMMAND ${CMAKE_COMMAND} --build .
OUTPUT_QUIET
RESULT_VARIABLE result
WORKING_DIRECTORY ${SEAL_THIRDPARTY_DIR}/zlib)
if(result)
message(WARNING "Failed to build ZLIB (${result}); disabling `SEAL_USE_ZLIB`")
endif()
endif()
# Set up the targets
if(SEAL_USE_ZLIB AND NOT MSVC)
add_subdirectory(
${SEAL_THIRDPARTY_DIR}/zlib/src
EXCLUDE_FROM_ALL)
# Set the ZLIB include directories; we have to include also ZLIB binary directory because
# ZLIB creates a file zconf.h into it, which must be visible to the compiler.
set(SEAL_ZLIB_INCLUDE_DIRS
${CMAKE_CURRENT_BINARY_DIR}/thirdparty/zlib/src
${SEAL_THIRDPARTY_DIR}/zlib/src)
set_target_properties(zlibstatic PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SEAL_ZLIB_INCLUDE_DIRS}")
endif()
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS TRUE CACHE INTERNAL "Suppress CMP0048 warning" FORCE)
add_subdirectory(
${zlib_SOURCE_DIR}
EXCLUDE_FROM_ALL)
# Set the ZLIB include directories; we have to include also ZLIB binary directory because
# ZLIB creates a file zconf.h into it, which must be visible to the compiler.
set(SEAL_ZLIB_INCLUDE_DIRS
${CMAKE_CURRENT_BINARY_DIR}/thirdparty/zlib-src
${zlib_SOURCE_DIR})
set_target_properties(zlibstatic PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SEAL_ZLIB_INCLUDE_DIRS}")

Просмотреть файл

@ -1,47 +1,28 @@
# Download and configure
if(SEAL_USE_ZSTD AND NOT MSVC)
message(STATUS "Setting up Zstandard ...")
if(NOT CMAKE_TOOLCHAIN_FILE)
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
OUTPUT_QUIET
RESULT_VARIABLE result
WORKING_DIRECTORY ${SEAL_THIRDPARTY_DIR}/zstd)
else()
seal_create_cache_entries(${SEAL_THIRDPARTY_DIR}/zstd)
if(EXISTS ${SEAL_THIRDPARTY_DIR}/zstd/build/CMakeCache.txt)
# Force regenerating make files. When cross compiling we might be
# compiling more than one platform at a time.
file(REMOVE ${SEAL_THIRDPARTY_DIR}/zstd/build/CMakeCache.txt)
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . -Ccache_init.txt
OUTPUT_QUIET
RESULT_VARIABLE result
WORKING_DIRECTORY ${SEAL_THIRDPARTY_DIR}/zstd)
endif()
if(result)
message(WARNING "Failed to download ZSTD (${result}); disabling `SEAL_USE_ZSTD`")
endif()
endif()
# Build
if(SEAL_USE_ZSTD AND NOT MSVC)
execute_process(COMMAND ${CMAKE_COMMAND} --build .
OUTPUT_QUIET
RESULT_VARIABLE result
WORKING_DIRECTORY ${SEAL_THIRDPARTY_DIR}/zstd)
if(result)
message(WARNING "Failed to build ZSTD (${result}); disabling `SEAL_USE_ZSTD`")
endif()
endif()
# Set up the targets
if(SEAL_USE_ZSTD AND NOT MSVC)
add_subdirectory(
${SEAL_THIRDPARTY_DIR}/zstd/src/build/cmake
EXCLUDE_FROM_ALL)
# Set the ZSTD include directory
set(SEAL_ZSTD_INCLUDE_DIR ${SEAL_THIRDPARTY_DIR}/zstd/src/lib)
endif()
FetchContent_Declare(
zstd
GIT_REPOSITORY https://github.com/facebook/zstd.git
GIT_TAG b706286adbba780006a47ef92df0ad7a785666b6 # 1.4.5
)
FetchContent_GetProperties(zstd)
FetchContent_Populate(zstd)
set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "" FORCE)
set(ZSTD_BUILD_SHARED ON CACHE BOOL "" FORCE)
set(ZLIB_BUILD_STATIC ON CACHE BOOL "" FORCE)
set(ZSTD_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(ZSTD_MULTITHREAD_SUPPORT OFF CACHE BOOL "" FORCE)
mark_as_advanced(ZSTD_BUILD_CONTRIB)
mark_as_advanced(ZSTD_BUILD_PROGRAMS)
mark_as_advanced(ZSTD_BUILD_SHARED)
mark_as_advanced(ZSTD_BUILD_STATIC)
mark_as_advanced(ZSTD_BUILD_TESTS)
mark_as_advanced(ZSTD_LEGACY_SUPPORT)
mark_as_advanced(ZSTD_MULTITHREAD_SUPPORT)
mark_as_advanced(ZSTD_PROGRAMS_LINK_SHARED)
mark_as_advanced(FETCHCONTENT_SOURCE_DIR_ZSTD)
mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_ZSTD)
add_subdirectory(
${zstd_SOURCE_DIR}/build/cmake
EXCLUDE_FROM_ALL)
set(SEAL_ZSTD_INCLUDE_DIRS
${zstd_SOURCE_DIR}/lib
${zstd_SOURCE_DIR}/lib/common)