mrklein / openfoam-os-x

Patches for OpenFOAM(R) to build it on OS X
93 stars 33 forks source link

Changing `xcrun c++` to `clang++` #63

Closed BrushXue closed 3 years ago

BrushXue commented 3 years ago

Hello. I have a question regarding wmake/rules/darwin64Clang/c++ https://github.com/mrklein/openfoam-os-x/blob/f220ac0353eae847662dbbbdbf2f6eed7ce728a8/OpenFOAM-v2012.patch#L881 I'm trying to use the new wmake-with-bear feature but bear doesn't recongnize xcrun c++. By changing it to clang++, bear can generate the compilation database. And seems like everything's fine in my build.

So is there any specific reason to use xcrun?

mrklein commented 3 years ago

Hi,

clang++ can be located in different places:

$ xcrun -f c++
/Library/Developer/CommandLineTools/usr/bin/c++
$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/
$ xcrun -f c++
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++

I think initially xcrun c++ appeared because at some point people were happy with CLT and did not want to install Xcode.

Guess, you can configure bear to use whatever compile you like: https://github.com/rizsotto/Bear/wiki/Config-file.

BrushXue commented 3 years ago

I tried but didn't resolve the issue: https://github.com/rizsotto/Bear/issues/360. Changed to clang++ and immediately passed. Are these two commands 100% equivalent if the code is CLI only?

mrklein commented 3 years ago

I can propose the following solution using conditional parts of Makefiles (should be added to wmake/rules/darwin64Clang/c++):

ifeq ($(WM_CXX),)
CC          = xcrun c++ -std=c++14
else
CC          = $(WM_CXX) -std=c++14
endif

and the same for WM_CC.

So the command for compilation is

WM_CXX=clang++ wmake -with-bear

Concerning xcrun:

$ xcrun -l c++
env SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk /Library/Developer/CommandLineTools/usr/bin/c++

So, final command is a little bit more complicated. I did not check Apple sources to figure out clang++ symlink behaviour.

BrushXue commented 3 years ago

WM_CC and WM_CXX are no longer used in .com version https://www.openfoam.com/news/main-news/openfoam-v1906/portability

mrklein commented 3 years ago

OK, these variables are not used, so we are free to use them, this will not create conflicts. I propose to use them to cope with bear inability to parse compiler output.

Alternatively you can checkout Apple's LLVM sources and check what clang does if executable name in clang++.

olesenm commented 3 years ago

Should be hesitant to use/reuse WM_CXX etc. since they will be picked up on by the ThirdParty compilations (as a fallback).

olesenm commented 3 years ago

So the command for compilation is

WM_CXX=clang++ wmake -with-bear

This runs counter to how we've added bear support into OpenFOAM (.com). We have wmake -with-bear or even Allwmake -with-bear as the top-level wrapping and not on the compiler level. Seemed less intrusive.

mrklein commented 3 years ago

I will choose bear author approach and mark the issue as wontfix and close it.