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

fix compilation on macOS #34

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

joerg-meyer-jm
Copy link

dependencies installed via Homebrew (armadillo gsl libxc)

dependencies installed via Homebrew (armadillo gsl libxc)
Comment on lines +1 to +19
#!/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
Copy link
Owner

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

Copy link
Author

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)

Copy link
Author

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?

Copy link
Owner

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
Comment on lines 80 to 86
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}")
Copy link
Owner

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

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants