Skip to content

Commit

Permalink
Cleaned up FETCH_GMP logic and removed redundant FindNTL line
Browse files Browse the repository at this point in the history
  • Loading branch information
olimasters committed Mar 13, 2019
1 parent 23322c3 commit 9c38a43
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
23 changes: 11 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ option(PEDANTIC_BUILD "Use -Wall -Wpedantic -Wextra -Werror during build" OFF)
if (PACKAGE_BUILD)
# Properties to be enabled when using PACKAGE_BUILD
set(PACKAGE_DIR "" CACHE STRING "Folder with the compilation output directory (DEFAULT: helib_pack)")
option(DONT_FETCH_GMP "Do not fetch and compile the GMP library (DEFAULT: OFF)" OFF)
option(FETCH_GMP "Fetch and compile the GMP library (DEFAULT: ON)" ON)
else (PACKAGE_BUILD)
# Properties to be enabled when not using PACKAGE_BUILD
option(ENABLE_LEGACY_TEST "Build the legacy test files (does not work with PACKAGE_BUILD)" OFF)
option(BUILD_AES "Build homomorphic AES (does not work with PACKAGE_BUILD)" OFF)
endif(PACKAGE_BUILD)

# Allow GMP_DIR and search of it if not in PACKAGE_BUILD or in PACKAGE_BUILD and DONT_FETCH_GMP
if ((NOT PACKAGE_BUILD) OR DONT_FETCH_GMP)
# Allow GMP_DIR and search in it if not using PACKAGE_BUILD or using PACKAGE_BUILD and !FETCH_GMP
if ((NOT PACKAGE_BUILD) OR NOT FETCH_GMP)
set(GMP_DIR "" CACHE STRING "Prefix of the GMP library (ignored when PACKAGE_BUILD is ON)")
endif((NOT PACKAGE_BUILD) OR DONT_FETCH_GMP)
endif((NOT PACKAGE_BUILD) OR NOT FETCH_GMP)

# Allow NTL_DIR only if not PACKAGE_BUILD
if (NOT PACKAGE_BUILD)
Expand Down Expand Up @@ -120,12 +120,11 @@ if (PACKAGE_BUILD)

# Warn existing dependencies are ignored and rebuilt
if (GMP_DIR)
if (DONT_FETCH_GMP)
# FIXME: check if true
message(STATUS "GMP_DIR is not the system one. This may prevent relocatability of the package.")
else (DONT_FETCH_GMP)
if (FETCH_GMP)
message(WARNING "GMP_DIR is ignored when PACKAGE_BUILD is ON.")
endif (DONT_FETCH_GMP)
else (FETCH_GMP)
message(STATUS "GMP_DIR is not the system one. This may prevent relocatability of the package.")
endif(FETCH_GMP)
endif(GMP_DIR)

if (NTL_DIR)
Expand All @@ -139,7 +138,7 @@ if (PACKAGE_BUILD)
# RPATH will be empty since ntl, gmp, and helib are all in PACKAGE_DIR/lib
set(PACKAGE_RPATH "")

if (DONT_FETCH_GMP)
if (NOT FETCH_GMP)
# find GMP library
# Try to find the GMP package (using cmake/FindGMP.cmake script)
# REQUIRED arg make cmake to fail if GMP is not found
Expand All @@ -150,7 +149,7 @@ if (PACKAGE_BUILD)
INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_PATHS}"
IMPORTED_LOCATION "${GMP_LIBRARIES}"
)
endif(DONT_FETCH_GMP)
endif(NOT FETCH_GMP)

# Add the external dependencies (done in dependencies/CMakeLists.txt)
add_subdirectory(dependencies)
Expand Down Expand Up @@ -245,7 +244,7 @@ if (PACKAGE_BUILD)
-DHELIB_REQUIRES_PTHREADS=${HELIB_REQUIRES_PTHREADS}
-DBUILD_SHARED=${BUILD_SHARED}
-DPACKAGE_BUILD=${PACKAGE_BUILD}
-DDONT_FETCH_GMP=${DONT_FETCH_GMP}
-DFETCH_GMP=${FETCH_GMP}
-DENABLE_TEST=${ENABLE_TEST}
-DENABLE_LEGACY_TEST=OFF
-DBUILD_AES=OFF
Expand Down
1 change: 0 additions & 1 deletion cmake/FindNTL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ if (NTL_HEADERS AND NTL_LIB)
message(FATAL_ERROR "Failed to determine ntl version.")
endif()

string(REGEX REPLACE "[^ \t]*[ \t]+NTL_VERSION[ \t]+\"([0-9.]+)\"" "\\1" ntl_version_string "${ntl_version_string}")
string(REGEX REPLACE "([0-9]+)\.([0-9]+)\.([0-9]+)" "\\1" ntl_major "${ntl_version_string}")
string(REGEX REPLACE "([0-9]+)\.([0-9]+)\.([0-9]+)" "\\2" ntl_minor "${ntl_version_string}")
string(REGEX REPLACE "([0-9]+)\.([0-9]+)\.([0-9]+)" "\\3" ntl_patchlevel "${ntl_version_string}")
Expand Down
12 changes: 6 additions & 6 deletions cmake/rpath_fixer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function(change_rpath lib_name_noext depend_target_name lib_path package_relativ
VERBATIM)

# Change ID of GMP in the NTL library only if GMP is not the default one
if (lib_name_noext MATCHES "ntl" AND (NOT DONT_FETCH_GMP))
if (lib_name_noext MATCHES "ntl" AND FETCH_GMP)
# NOTE: Here we assume the ID of the gmp library is equal to its absolute path, including version name (i.e. not the symlink).
# If GMP changes this convention, the following command may break.
# Since gmp rpath fix has been delayed after ntl compilation due the configuration step dependencies we have to change ntl rpath to gmp.
Expand All @@ -39,7 +39,7 @@ function(change_rpath lib_name_noext depend_target_name lib_path package_relativ
COMMAND eval ARGS "${change_gmp_rpath_cmd}"
VERBATIM)
unset(change_gmp_rpath_cmd)
endif(lib_name_noext MATCHES "ntl" AND (NOT DONT_FETCH_GMP))
endif(lib_name_noext MATCHES "ntl" AND FETCH_GMP)
unset(change_id_command)
unset(add_rpath_command)

Expand All @@ -50,11 +50,11 @@ function(change_rpath lib_name_noext depend_target_name lib_path package_relativ
message(FATAL_ERROR "Cannot find patchelf, which is required for a package build.")
endif(NOT LINUX_RPATH_TOOL)

if (DONT_FETCH_GMP)
set(rpath_patch_args "--set-rpath" "$ORIGIN/${package_relative_rpath}:${gmp_library_dir}" "${lib_path}")
else (DONT_FETCH_GMP)
if (FETCH_GMP)
set(rpath_patch_args "--set-rpath" "$ORIGIN/${package_relative_rpath}" "${lib_path}")
endif(DONT_FETCH_GMP)
else (FETCH_GMP)
set(rpath_patch_args "--set-rpath" "$ORIGIN/${package_relative_rpath}:${gmp_library_dir}" "${lib_path}")
endif(FETCH_GMP)
# Adding $ORIGIN/${package_relative_rpath}
add_custom_command(TARGET ${depend_target_name}
POST_BUILD
Expand Down
12 changes: 6 additions & 6 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ if (NOT CMAKE_INSTALL_LIBDIR STREQUAL "lib")
VERBATIM)
endif()

if (NOT DONT_FETCH_GMP)
if (FETCH_GMP)
###########################################
# #
# Loading GMP #
# #
###########################################
add_subdirectory(gmp)
endif(NOT DONT_FETCH_GMP)
endif(FETCH_GMP)

###########################################
# #
Expand All @@ -37,9 +37,9 @@ endif(NOT DONT_FETCH_GMP)
add_subdirectory(ntl)


if (NOT DONT_FETCH_GMP)
if (FETCH_GMP)
add_dependencies(gmp_external dependencies_built)
endif(NOT DONT_FETCH_GMP)
endif(FETCH_GMP)
add_dependencies(ntl_external dependencies_built)

# Fixing rpaths
Expand All @@ -50,10 +50,10 @@ get_target_property(gmp_install_location gmp_external IMPORTED_LOCATION)
get_target_property(ntl_install_location ntl_external IMPORTED_LOCATION)
# Function definition
# change_rpath(lib_name_noext depend_target_name lib_path package_relative_rpath gmp_library_path)
if (NOT DONT_FETCH_GMP)
if (FETCH_GMP)
# Fixing gmp rpath
change_rpath("gmp" dependencies_built "${gmp_install_location}" "${PACKAGE_RPATH}" "")
endif(NOT DONT_FETCH_GMP)
endif(FETCH_GMP)
# Fixing ntl rpath
change_rpath("ntl" dependencies_built "${ntl_install_location}" "${PACKAGE_RPATH}" "${gmp_install_location}")

Expand Down
4 changes: 2 additions & 2 deletions dependencies/ntl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ set(ntl_superbuild_dependencies "setup_install_dir")

# If requiring GMP to be built then in compilation NTL depends to gmp_fetched
# because gmp_external is dependent on this (through dependencies_built) due to the rpath delay
if (NOT DONT_FETCH_GMP)
if (FETCH_GMP)
list(APPEND ntl_superbuild_dependencies "gmp_fetched")
endif(NOT DONT_FETCH_GMP)
endif(FETCH_GMP)

# get the file path of libgmp.(so|dylib) (set beforehand)
get_target_property(gmp_lib_path gmp_external IMPORTED_LOCATION)
Expand Down
8 changes: 4 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ if (PACKAGE_BUILD)

# Do the same for GMP iff GMP is not the system one. If the GMP that we use is on the system,
# we need to use an absolute path instead.
if (DONT_FETCH_GMP)
set(GMP_LIBRARIES_EXPORTED_PATH "${GMP_LIBRARIES}")
else (DONT_FETCH_GMP)
if (FETCH_GMP)
file(RELATIVE_PATH GMP_LIBRARIES_EXPORTED_PATH "${CMAKE_INSTALL_PREFIX}" "${GMP_LIBRARIES}")
set(GMP_LIBRARIES_EXPORTED_PATH "\${_IMPORT_PREFIX}/${GMP_LIBRARIES_EXPORTED_PATH}")
endif(DONT_FETCH_GMP)
else (FETCH_GMP)
set(GMP_LIBRARIES_EXPORTED_PATH "${GMP_LIBRARIES}")
endif(FETCH_GMP)
else (PACKAGE_BUILD)
set(NTL_INCLUDE_EXPORTED_PATH "${NTL_INCLUDE_PATHS}")
set(NTL_LIBRARIES_EXPORTED_PATH "${NTL_LIBRARIES}")
Expand Down

0 comments on commit 9c38a43

Please sign in to comment.