All,
I think I might be an idiot, but I’m not sure what’s going on. I’m having issues with CMake because it seems to be finding the “wrong clang”. In an autotools build (controlled by CMake/ExternalProject_Add), it’s trying to run a program that is essentially:
#include <stdio.h>
int main() {
  printf("Hello world\n");
}
and it’s failing. Why? Because it’s calling the “wrong” clang. This works:
❯ /usr/bin/clang -o conftest -fPIC test.c
❯ echo $?
0
This does not:
❯ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -o conftest -fPIC test.c
test.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.
❯ echo $?
1
So, I start drilling down and I see some oddness. I made up this CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
project(test VERSION 1.0.0 LANGUAGES C)
message(STATUS "CC from ENV: $ENV{CC}")
set(SERIAL_C_COMPILER ${CMAKE_C_COMPILER})
message(STATUS "SERIAL_C_COMPILER: ${SERIAL_C_COMPILER}")
Now I try and use it. First I load my module and echo out CC as set by the modulefile:
❯ ml purge
❯ ml intel-clang
❯ echo $CC
/usr/bin/clang
Now I run cmake:
❯ cmake ..
-- The C compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- CC from ENV: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- SERIAL_C_COMPILER: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mathomp4/CmakeTest/build
Instead of using the CC from my environment, it’s using…a different one.
So is there a way for CMake to use what I have in CC for determining the C compiler? Or do I just always need to pass in -DCMAKE_C_COMPILER=$CC which seems to work:
❯ cmake .. -DCMAKE_C_COMPILER=$CC
-- The C compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- CC from ENV: /usr/bin/clang
-- SERIAL_C_COMPILER: /usr/bin/clang
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mathomp4/CmakeTest/build
to have CMake use the CC in my environment?
Or is there a way to tell CMake don’t use the /deep/inside/xcode/usr/bin/clang but actually /usr/bin/clang?
