-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix compilation on macOS #34
base: master
Are you sure you want to change the base?
Conversation
dependencies installed via Homebrew (armadillo gsl libxc)
#!/bin/bash | ||
|
||
# Installation directory | ||
export target=$(pwd)/install # this installs the binaries under install/bin/ in the present directory | ||
|
||
if [[ ! -d objdir ]]; then | ||
mkdir objdir | ||
fi | ||
cd objdir | ||
|
||
ARMAFLAGS="-DARMA_NO_DEBUG -DARMA_DONT_USE_WRAPPER -llapack -lblas" | ||
export CXXFLAGS="-g -O2 -Wall -Wno-implicit-fallthrough -Wno-misleading-indentation ${ARMAFLAGS}" | ||
cmake .. \ | ||
-DUSE_OPENMP=ON \ | ||
-DHELFEM_FIND_DEPS=ON \ | ||
-DCMAKE_INSTALL_PREFIX=${target} \ | ||
-DCMAKE_BUILD_TYPE=Release | ||
|
||
make -j4 VERBOSE=1 install |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this file. Also, you appear to link to reference BLAS and LAPACK which is orders of magnitude slower than optimal versions. On Mac, I think the optimal library is Accelerate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otool -L install/bin/gensap
confirms that the above (-llapack -lblas
) has resulted in
../install/bin/gensap:
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib (compatibility version 1.0.0, current version 1.0.0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following CMake.system
# macOS with dependencies installed via Homebrew
add_definitions(-DHELFEM_FIND_DEPS=ON)
#
# link_libraries() is not a perfect option:
# https://stackoverflow.com/questions/17070101/why-i-cannot-link-the-mac-framework-file-with-cmake
# Unfortunately,
# target_link_libraries(helfem PRIVATE "-framework Accelerate")
# cannot be used here, as it must occur after add_executable() or add_library().
# Pragmatically, the following does successfully link against the wrappers from Apple's Accelerate framework
# https://developer.apple.com/documentation/accelerate/blas
# if no other BLAS and LAPACK are installed:
link_libraries(blas lapack)
enables compilation on my good old MacBook Pro M1 using compile.sh
.
Perhaps it could be useful to add as, e.g., CMake.macOS_with_Homebrew
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've added that file already, no? That one is OK. But this file duplicates compile.sh
and is not necessary.
CMakeLists.txt
Outdated
find_package(LibXc REQUIRED PATHS ".") | ||
message("LibXc_FOUND=${LibXc_FOUND}") | ||
message("LIBXC_INCLUDE_DIRS=${LIBXC_INCLUDE_DIRS}") | ||
message("LIBXC_LIBRARIES=${LIBXC_LIBRARIES}") | ||
message("LIBXC_INCLUDE_DIRS=${Libxc_INCLUDE_DIRS}") | ||
message("LIBXC_LIBRARIES=${Libxc_LIBRARIES}") | ||
|
||
include_directories("${HDF5_INCLUDE_DIRS}" "${LIBXC_INCLUDE_DIRS}") | ||
link_libraries("${HDF5_LIBRARIES}" "${LIBXC_LIBRARIES}") | ||
include_directories("${HDF5_INCLUDE_DIRS}" "${Libxc_INCLUDE_DIRS}") | ||
link_libraries("${HDF5_LIBRARIES}" "${Libxc_LIBRARIES}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was contributed by @mortenpi. On later examination, it looks like there is an issue with inconsistent capitalization. Libxc does have a working CMake system, as well. The usage should be something like
find_package(Libxc)
and the link should be against Libxc::xc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using -DHELFEM_FIND_DEPS=ON
, I can confirm that find_package(Libxc)
in CMakeLists.txt
works fine with the Libxc-6.2.2 (currently available as stable bottle from Homebrew). Without the correct capitalization of Libxc_INCLUDE_DIRS
and Libxc_LIBRARIES
, cmake
aborts:
LibXc_FOUND=1
LIBXC_INCLUDE_DIRS=
LIBXC_LIBRARIES=
CMake Error at CMakeLists.txt:85 (include_directories):
include_directories given empty-string as include directory.
dependencies installed via Homebrew (armadillo gsl libxc)