Skip to content

Commit

Permalink
Correct flag and libs for OpenMP on macOS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bryanwweber committed Jun 12, 2019
1 parent a36b16d commit 076dece
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 11 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions samples/cxx/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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']])
Expand Down

0 comments on commit 076dece

Please sign in to comment.