From 4c6ff55b5a23a9a38b12db40cbb5cd847cae1408 Mon Sep 17 00:00:00 2001 From: Enwei Jiao Date: Sat, 28 May 2022 14:01:58 +0800 Subject: [PATCH] fix compile on Mac when HOMEBREW_PREFIX is /opt/homebrew (#197) Signed-off-by: Enwei Jiao --- CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c6cc8750..8890dfddb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,8 +22,13 @@ add_definitions( -DAUTO_INITIALIZE_EASYLOGGINGPP ) if ( APPLE ) set ( CMAKE_CROSSCOMPILING TRUE ) set ( RUN_HAVE_GNU_POSIX_REGEX 0 ) - set ( CMAKE_C_COMPILER "/usr/local/opt/llvm/bin/clang" ) - set ( CMAKE_CXX_COMPILER "/usr/local/opt/llvm/bin/clang++" ) + if ( DEFINED ENV{HOMEBREW_PREFIX} ) + set( APPLE_LLVM_PREFIX $ENV{HOMEBREW_PREFIX} ) + else() + set( APPLE_LLVM_PREFIX "/usr/local" ) + endif() + set ( CMAKE_C_COMPILER "${APPLE_LLVM_PREFIX}/opt/llvm/bin/clang" ) + set ( CMAKE_CXX_COMPILER "${APPLE_LLVM_PREFIX}/opt/llvm/bin/clang++" ) endif () set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ) @@ -74,7 +79,7 @@ include( CheckCXXCompilerFlag ) if ( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" ) message(STATUS "MacOS") set ( MACOS TRUE ) - set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L/usr/local/opt/libomp/lib" ) + set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${APPLE_LLVM_PREFIX}/opt/libomp/lib" ) elseif ( "${CMAKE_SYSTEM}" MATCHES "Linux" ) message( STATUS "Linux") set ( LINUX TRUE )