Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop modifications to libsharp #6407

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions .github/workflows/Tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ jobs:
run: |
cd $GITHUB_WORKSPACE
echo "Using 'black' to check Python formatting..."
black --check .
black --check --extend-exclude '/external/' .
echo "Using 'isort' to check Python formatting..."
isort --check-only .
isort --check-only --extend-skip external .
- name: Test script
run: |
cd $GITHUB_WORKSPACE
Expand Down
66 changes: 54 additions & 12 deletions cmake/AddCxxFlag.cmake
Original file line number Diff line number Diff line change
@@ -1,40 +1,61 @@
# Distributed under the MIT License.
# See LICENSE.txt for details.

# Checks if a CXX flag is supported by the compiler and creates the target
# Checks if a flag is supported by the compiler and creates the target
# TARGET_NAME whose INTERFACE_COMPILE_OPTIONS are set to the FLAG_TO_CHECK
# - LANGUAGE: language to check, setting the compiler and generated property
# - XTYPE: language as passed to the -x compiler flag
# - FLAG_TO_CHECK: the CXX flag to add if the compiler supports it
# - TARGET_NAME: the name of the target whose INTERFACE_COMPILE_OPTIONS are
# set
function(create_cxx_flag_target FLAG_TO_CHECK TARGET_NAME)
function(create_compile_flag_target LANGUAGE XTYPE FLAG_TO_CHECK TARGET_NAME)
# In order to check for a -Wno-* flag in gcc, you have to check the
# -W* version instead. See http://gcc.gnu.org/wiki/FAQ#wnowarning
string(REGEX REPLACE ^-Wno- -W POSITIVE_FLAG_TO_CHECK ${FLAG_TO_CHECK})
execute_process(
COMMAND
bash -c
"LC_ALL=POSIX ${CMAKE_CXX_COMPILER} -Werror ${POSITIVE_FLAG_TO_CHECK} \
-x c++ -c - <<< \"\" -o /dev/null"
"LC_ALL=POSIX ${CMAKE_${LANGUAGE}_COMPILER} -Werror \
${POSITIVE_FLAG_TO_CHECK} -x ${XTYPE} -c - <<< \"\" -o /dev/null"
RESULT_VARIABLE RESULT
ERROR_VARIABLE ERROR_FROM_COMPILATION
OUTPUT_QUIET)
add_library(${TARGET_NAME} INTERFACE)
if(NOT TARGET ${TARGET_NAME})
add_library(${TARGET_NAME} INTERFACE)
endif(NOT TARGET ${TARGET_NAME})
if(${RESULT} EQUAL 0)
set_property(TARGET ${TARGET_NAME}
APPEND PROPERTY
INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CXX>:${FLAG_TO_CHECK}>)
INTERFACE_COMPILE_OPTIONS
$<$<COMPILE_LANGUAGE:${LANGUAGE}>:${FLAG_TO_CHECK}>)
endif(${RESULT} EQUAL 0)
endfunction()

# Checks if a CXX flag is supported by the compiler and creates the target
# TARGET_NAME whose INTERFACE_COMPILE_OPTIONS are set to the FLAG_TO_CHECK
# - FLAG_TO_CHECK: the CXX flag to add if the compiler supports it
# - TARGET_NAME: the name of the target whose INTERFACE_COMPILE_OPTIONS are
# set
function(create_cxx_flag_target FLAG_TO_CHECK TARGET_NAME)
create_compile_flag_target(CXX c++ "${FLAG_TO_CHECK}" "${TARGET_NAME}")
endfunction()

# Same, but for C.
function(create_c_flag_target FLAG_TO_CHECK TARGET_NAME)
create_compile_flag_target(C c "${FLAG_TO_CHECK}" "${TARGET_NAME}")
endfunction()

# Checks which of the CXX FLAGS_TO_CHECK are supported by the compiler
# and creates the target TARGET_NAME whose INTERFACE_COMPILE_OPTIONS
# are set to the FLAGS_TO_CHECK that are supported. If adding many flags,
# this will be much faster than calling create_cxx_flags_target multiple times.
# - LANGUAGE: language to check, setting the compiler and generated property
# - XTYPE: language as passed to the -x compiler flag
# - FLAGS_TO_CHECK: a semicolon separated string of CXX flags to try to add
# for compilation.
# - TARGET_NAME: the name of the target whose INTERFACE_COMPILE_OPTIONS are
# set
function(create_cxx_flags_target FLAGS_TO_CHECK TARGET_NAME)
function(create_compile_flags_target LANGUAGE XTYPE FLAGS_TO_CHECK TARGET_NAME)
# In order to check for a -Wno-* flag in gcc, you have to check the
# -W* version instead. See http://gcc.gnu.org/wiki/FAQ#wnowarning
set(POSITIVE_FLAGS_TO_CHECK)
Expand All @@ -47,17 +68,20 @@ function(create_cxx_flags_target FLAGS_TO_CHECK TARGET_NAME)
execute_process(
COMMAND
bash -c
"LC_ALL=POSIX ${CMAKE_CXX_COMPILER} -Werror ${POSITIVE_FLAGS_WITH_SPACES} \
-x c++ -c - <<< \"\" -o /dev/null"
"LC_ALL=POSIX ${CMAKE_${LANGUAGE}_COMPILER} -Werror \
${POSITIVE_FLAGS_WITH_SPACES} -x ${XTYPE} -c - <<< \"\" -o /dev/null"
RESULT_VARIABLE RESULT
ERROR_VARIABLE ERROR_FROM_COMPILATION
OUTPUT_QUIET)

add_library(${TARGET_NAME} INTERFACE)
if(NOT TARGET ${TARGET_NAME})
add_library(${TARGET_NAME} INTERFACE)
endif(NOT TARGET ${TARGET_NAME})
if(${RESULT} EQUAL 0)
set_property(TARGET ${TARGET_NAME}
APPEND PROPERTY
INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CXX>:${FLAGS_TO_CHECK}>)
INTERFACE_COMPILE_OPTIONS
$<$<COMPILE_LANGUAGE:${LANGUAGE}>:${FLAGS_TO_CHECK}>)
else(${RESULT} EQUAL 0)
# Check each flag to see if it was marked as "invalid" in the output
unset(FLAGS_TO_ADD)
Expand Down Expand Up @@ -96,11 +120,29 @@ function(create_cxx_flags_target FLAGS_TO_CHECK TARGET_NAME)
endforeach(FLAG ${FLAGS_TO_CHECK})
set_property(TARGET ${TARGET_NAME}
APPEND PROPERTY
INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CXX>:${FLAGS_TO_ADD}>)
INTERFACE_COMPILE_OPTIONS
$<$<COMPILE_LANGUAGE:${LANGUAGE}>:${FLAGS_TO_ADD}>)

endif(${RESULT} EQUAL 0)
endfunction()

# Checks which of the CXX FLAGS_TO_CHECK are supported by the compiler
# and creates the target TARGET_NAME whose INTERFACE_COMPILE_OPTIONS
# are set to the FLAGS_TO_CHECK that are supported. If adding many flags,
# this will be much faster than calling create_cxx_flags_target multiple times.
# - FLAGS_TO_CHECK: a semicolon separated string of CXX flags to try to add
# for compilation.
# - TARGET_NAME: the name of the target whose INTERFACE_COMPILE_OPTIONS are
# set
function(create_cxx_flags_target FLAGS_TO_CHECK TARGET_NAME)
create_compile_flags_target(CXX c++ "${FLAGS_TO_CHECK}" "${TARGET_NAME}")
endfunction()

# Same, but for C.
function(create_c_flags_target FLAGS_TO_CHECK TARGET_NAME)
create_compile_flags_target(C c "${FLAGS_TO_CHECK}" "${TARGET_NAME}")
endfunction()

set(CMAKE_SUPPORTS_LINK_OPTIONS OFF)
if(CMAKE_VERSION VERSION_EQUAL 3.13 OR CMAKE_VERSION VERSION_GREATER 3.13)
set(CMAKE_SUPPORTS_LINK_OPTIONS ON)
Expand Down
4 changes: 4 additions & 0 deletions cmake/SetupCxxFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ set_property(TARGET SpectreFlags
# floating point exceptions are ignored.
# -fnon-call-exceptions - By default, GCC does not allow signal handlers to
# throw exceptions.
create_c_flags_target(
"-ffp-exception-behavior=maytrap;-fnon-call-exceptions"
SpectreFpExceptions
)
create_cxx_flags_target(
"-ffp-exception-behavior=maytrap;-fnon-call-exceptions"
SpectreFpExceptions
Expand Down
1 change: 1 addition & 0 deletions docs/Installation/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ apt), or AppleClang 13.0.0 or later
* BLAS & LAPACK (e.g. [OpenBLAS](http://www.openblas.net))
* [Boost](http://www.boost.org/) 1.60.0 or later
* [GSL](https://www.gnu.org/software/gsl/) \cite Gsl
* [GNU make](https://www.gnu.org/software/make/)
* [HDF5](https://support.hdfgroup.org/HDF5/) (non-mpi version on macOS)
\cite Hdf5
* [Python](https://www.python.org/) 3.8 or later.
Expand Down
102 changes: 101 additions & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,105 @@
# See LICENSE.txt for details.

add_subdirectory(brigand)
add_subdirectory(libsharp)
add_subdirectory(SPHEREPACK)

set(LIBRARY Libsharp)
set(LIBSHARP_LIBDIR ${CMAKE_CURRENT_BINARY_DIR}/libsharp/auto/lib)
set(LIBSHARP_LIB_libsharp ${LIBSHARP_LIBDIR}/libsharp.a)
set(LIBSHARP_LIB_libfftpack ${LIBSHARP_LIBDIR}/libfftpack.a)
set(LIBSHARP_LIB_libc_utils ${LIBSHARP_LIBDIR}/libc_utils.a)
set(LIBSHARP_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/libsharp/auto/include)

find_program(MAKE NAMES gmake make REQUIRED)
set(LIBSHARP_BUILD ${MAKE})
# When using the Unix Makefile generator, verbosity is inherited from
# the main build and works acceptably well. There's no way to
# dynamically detect the verbosity with ninja, so silence it
# unconditionally because ninja is quieter than make.
if (NOT CMAKE_GENERATOR STREQUAL "Unix Makefiles")
list(APPEND LIBSHARP_BUILD > /dev/null)
endif()

set(JOB_SERVER "")
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
set(JOB_SERVER BUILD_JOB_SERVER_AWARE TRUE)
endif()

include(ExternalProject)
ExternalProject_Add(
Libsharp-external
PREFIX ${CMAKE_BINARY_DIR}/external/libsharp
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/libsharp
DOWNLOAD_COMMAND
cp -r ${CMAKE_CURRENT_SOURCE_DIR}/libsharp ${CMAKE_CURRENT_BINARY_DIR}
# libsharp has an autoconf build system, but it doesn't do anything
# except set CFLAGS, so we can skip it to avoid depending on
# autoconf and set the flags below by manually writing config.auto.
CONFIGURE_COMMAND ""
# out-of-tree builds don't work
BUILD_IN_SOURCE TRUE
BUILD_COMMAND "${LIBSHARP_BUILD}"
${JOB_SERVER}
BUILD_BYPRODUCTS
${LIBSHARP_LIB_libsharp}
${LIBSHARP_LIB_libfftpack}
${LIBSHARP_LIB_libc_utils}
INSTALL_COMMAND ""
)

# Always build libsharp with optimization, since there is a big speed
# difference and we're not interested in debugging it.
file(
GENERATE OUTPUT "libsharp/config/config.auto"
CONTENT
"CC=${CMAKE_C_COMPILER}
CL=\$(CC)
SPECTRE_FLAGS=\\
\$(subst ;, ,$<TARGET_PROPERTY:SpectreFlags,INTERFACE_COMPILE_OPTIONS>)
CCFLAGS=\$(SPECTRE_FLAGS) -fno-openmp -O3 -c
CLFLAGS=-L. -L\$(LIBDIR) \$(SPECTRE_FLAGS) -fno-openmp -O3 -lm
ARCREATE=ar cr"
CONDITION "$<COMPILE_LANGUAGE:C>"
)

add_library(Libsharp::libsharp STATIC IMPORTED GLOBAL)
set_target_properties(
Libsharp::libsharp
PROPERTIES
IMPORTED_LOCATION
${LIBSHARP_LIB_libsharp}
)
add_library(Libsharp::libfftpack STATIC IMPORTED GLOBAL)
set_target_properties(
Libsharp::libfftpack
PROPERTIES
IMPORTED_LOCATION
${LIBSHARP_LIB_libfftpack}
)
add_library(Libsharp::libc_utils STATIC IMPORTED GLOBAL)
set_target_properties(
Libsharp::libc_utils
PROPERTIES
IMPORTED_LOCATION
${LIBSHARP_LIB_libc_utils}
)
add_library(Libsharp INTERFACE IMPORTED GLOBAL)
target_link_libraries(
${LIBRARY}
INTERFACE
Libsharp::libsharp
Libsharp::libfftpack
Libsharp::libc_utils
)
# cmake issue #15052
file(MAKE_DIRECTORY ${LIBSHARP_INCLUDE})
target_include_directories(
${LIBRARY}
SYSTEM
INTERFACE
${LIBSHARP_INCLUDE}
)
add_dependencies(
${LIBRARY}
Libsharp-external
)
17 changes: 17 additions & 0 deletions external/libsharp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.o
*.so
#*
*~
*.pyc
*.pyo

/auto
/autom4te.cache
/config.log
/config.status
/config/config.auto
/configure
/sharp_oracle.inc

/python/libsharp/libsharp.c
/python/libsharp/libsharp_mpi.c
54 changes: 0 additions & 54 deletions external/libsharp/CMakeLists.txt

This file was deleted.

Loading
Loading