From 08ed96680876c960d5aab0aabebb25206f0bda06 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Mon, 15 Oct 2018 18:02:52 +0200 Subject: [PATCH] OSX: If OpenMP is installed with homebrew or macports, auto-detect its setup --- vendor/cryptopp/CMakeLists.txt | 40 ++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/vendor/cryptopp/CMakeLists.txt b/vendor/cryptopp/CMakeLists.txt index 518a4d2f..f92ec69c 100644 --- a/vendor/cryptopp/CMakeLists.txt +++ b/vendor/cryptopp/CMakeLists.txt @@ -14,18 +14,50 @@ if(NOT DISABLE_OPENMP) else() find_package(OpenMP) - if((NOT OPENMP_FOUND) AND (NOT OPENMP_CXX_FOUND)) # older cmake uses OPENMP_FOUND, newer cmake also sets OPENMP_CXX_FOUND, homebrew installations seem only to get the latter set. + if (OPENMP_FOUND OR OPENMP_CXX_FOUND) + message(STATUS "Found libomp without any special flags") + endif() + + # If OpenMP wasn't found, try if we can find it in the default Macports location + if((NOT OPENMP_FOUND) AND (NOT OPENMP_CXX_FOUND) AND EXISTS "/opt/local/lib/libomp/libomp.dylib") # older cmake uses OPENMP_FOUND, newer cmake also sets OPENMP_CXX_FOUND, homebrew installations seem only to get the latter set. + set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/opt/local/include/libomp/") + set(OpenMP_CXX_LIB_NAMES omp) + set(OpenMP_omp_LIBRARY /opt/local/lib/libomp/libomp.dylib) + + find_package(OpenMP) + if (OPENMP_FOUND OR OPENMP_CXX_FOUND) + message(STATUS "Found libomp in macports default location.") + else() + message(FATAL_ERROR "Didn't find libomp. Tried macports default location but also didn't find it.") + endif() + endif() + + # If OpenMP wasn't found, try if we can find it in the default Homebrew location + if((NOT OPENMP_FOUND) AND (NOT OPENMP_CXX_FOUND) AND EXISTS "/usr/local/opt/libomp/lib/libomp.dylib") + set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/opt/libomp/include") + set(OpenMP_CXX_LIB_NAMES omp) + set(OpenMP_omp_LIBRARY /usr/local/opt/libomp/lib/libomp.dylib) + + find_package(OpenMP) + if (OPENMP_FOUND OR OPENMP_CXX_FOUND) + message(STATUS "Found libomp in homebrew default location.") + else() + message(FATAL_ERROR "Didn't find libomp. Tried homebrew default location but also didn't find it.") + endif() + endif() + + set(Additional_OpenMP_Libraries_Workaround "") + + # Workaround because older cmake on apple doesn't support FindOpenMP + if((NOT OPENMP_FOUND) AND (NOT OPENMP_CXX_FOUND)) if((APPLE AND ((CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))) AND ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0") AND (CMAKE_VERSION VERSION_LESS "3.12.0"))) - # Workaround because older cmake on apple doesn't support FindOpenMP message(STATUS "Applying workaround for OSX OpenMP with old cmake that doesn't have FindOpenMP") set(OpenMP_CXX_FLAGS "-Xclang -fopenmp") set(Additional_OpenMP_Libraries_Workaround "-lomp") else() message(FATAL_ERROR "Did not find OpenMP. Build with -DDISABLE_OPENMP=ON if you want to allow this and are willing to take the performance hit.") endif() - else() - set(Additional_OpenMP_Libraries_Workaround "") endif() if(NOT TARGET OpenMP::OpenMP_CXX)