Correct flag and libs for OpenMP on macOS

Apple's clang on macOS requires the libomp to link. Apple symlinks gcc
to clang, so it can't be detected as clang by executable name
This commit is contained in:
Bryan W. Weber 2019-06-11 17:14:40 -04:00
parent 3588be16f3
commit 142f533229
2 changed files with 16 additions and 3 deletions

View file

@ -253,7 +253,15 @@ defaults.noDebugLinkFlags = ''
defaults.warningFlags = '-Wall'
defaults.buildPch = False
env['pch_flags'] = []
env['openmp_flag'] = '-fopenmp' # used to generate sample build scripts
env['openmp_flag'] = ['-fopenmp'] # used to generate sample build scripts
env['using_apple_clang'] = False
# Check if this is actually Apple's clang on macOS
if env['OS'] == 'Darwin':
result = subprocess.check_output([env.subst('$CC'), '--version']).decode('utf-8')
if 'clang' in result.lower() and result.startswith('Apple LLVM'):
env['using_apple_clang'] = True
env['openmp_flag'].insert(0, '-Xpreprocessor')
if 'gcc' in env.subst('$CC') or 'gnu-cc' in env.subst('$CC'):
defaults.optimizeCcFlags += ' -Wno-inline'
@ -276,13 +284,13 @@ elif env['CC'] == 'cl': # Visual Studio
defaults.warningFlags = '/W3'
defaults.buildPch = True
env['pch_flags'] = ['/FIpch/system.h']
env['openmp_flag'] = '/openmp'
env['openmp_flag'] = ['/openmp']
elif 'icc' in env.subst('$CC'):
defaults.cxxFlags = '-std=c++0x'
defaults.ccFlags = '-vec-report0 -diag-disable 1478'
defaults.warningFlags = '-Wcheck'
env['openmp_flag'] = '-openmp'
env['openmp_flag'] = ['-openmp']
elif 'clang' in env.subst('$CC'):
defaults.ccFlags = '-fcolor-diagnostics'

View file

@ -18,6 +18,9 @@ for subdir, name, extensions, openmp in samples:
localenv = env.Clone()
if openmp:
localenv.Append(CXXFLAGS=env['openmp_flag'], LINKFLAGS=env['openmp_flag'])
if env['using_apple_clang']:
localenv.Append(LIBS=['omp'])
localenv['cmake_extra'] = """
find_package(OpenMP REQUIRED)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS})
@ -29,6 +32,8 @@ set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS})
if env["OS"] == "Darwin":
localenv["cmake_extra"] += "find_library(ACCELERATE_FRAMEWORK Accelerate)"
localenv.Append(LIBS=env['cantera_libs'])
buildSample(localenv.Program, pjoin(subdir, name),
mglob(localenv, subdir, *extensions),
CPPPATH=['#include', env['boost_inc_dir']])