CMake build failure - Clang vs GCC?

Hi,

Not sure if this is the right place to ask this question, but I’ve already tried every SO solution I could find, and thought maybe someone from the CMake community might help.

I’m learning Cpp using exercism, and the tests for this simple program:

#include "leap.h"

namespace leap {
    bool is_leap_year(int year) {
        return (year % 4 == 0) && ((year % 400 == 0) || (year % 100 != 0));
    }
}  // namespace leap

are done using CMake. This is the CMakeLists.txt file:

# Get the exercise name from the current directory
get_filename_component(exercise ${CMAKE_CURRENT_SOURCE_DIR} NAME)

# Basic CMake project
cmake_minimum_required(VERSION 3.5.1)

# Name the project after the exercise
project(${exercise} CXX)

# Get a source filename from the exercise name by replacing -'s with _'s
string(REPLACE "-" "_" file ${exercise})

# Implementation could be only a header
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.cpp)
    set(exercise_cpp ${file}.cpp)
else()
    set(exercise_cpp "")
endif()

# Use the common Catch library?
if(EXERCISM_COMMON_CATCH)
    # For Exercism track development only
    add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h $<TARGET_OBJECTS:catchlib>)
else()
    # Build executable from sources and headers
    add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h test/tests-main.cpp)
endif()

set_target_properties(${exercise} PROPERTIES
    CXX_STANDARD 14
    CXX_STANDARD_REQUIRED OFF
    CXX_EXTENSIONS OFF
)

set(CMAKE_BUILD_TYPE Debug)

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
    set_target_properties(${exercise} PROPERTIES
        COMPILE_FLAGS "-Wall -Wextra -Wpedantic -Werror"
    )
endif()

# Configure to run all the tests?
if(${EXERCISM_RUN_ALL_TESTS})
    target_compile_definitions(${exercise} PRIVATE EXERCISM_RUN_ALL_TESTS)
endif()

# Tell MSVC not to warn us about unchecked iterators in debug builds
if(${MSVC})
    set_target_properties(${exercise} PROPERTIES
        COMPILE_DEFINITIONS_DEBUG _SCL_SECURE_NO_WARNINGS)
endif()

# Run the tests on every build
add_custom_target(test_${exercise} ALL DEPENDS ${exercise} COMMAND ${exercise})

Following the instructions, I did:

mkdir build
cd build
cmake ..

And got:

(base) adamhaber-s-macbookpro1:build adamhaber$ cmake -G Xcode ..
-- The CXX compiler identification is unknown
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - broken
CMake Error at /usr/local/Cellar/cmake/3.19.2/share/cmake/Modules/CMakeTestCXXCompiler.cmake:59 (message):
  The C++ compiler

    "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_d7a05 -configuration Debug -hideShellScriptEnvironment && User defaults from command line:
        HideShellScriptEnvironment = YES
    
    Prepare build
    note: Using legacy build system
    === BUILD TARGET cmTC_d7a05 OF PROJECT CMAKE_TRY_COMPILE WITH CONFIGURATION Debug ===
    
    Check dependencies
    
    Write auxiliary files
    /bin/mkdir -p /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/Objects-normal/x86_64
    write-file /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/Objects-normal/x86_64/cmTC_d7a05.LinkFileList
    
    CompileC CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/Objects-normal/x86_64/testCXXCompiler.o testCXXCompiler.cxx normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
        cd /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp
        /Users/adamhaber/miniconda3/bin/x86_64-apple-darwin13.4.0-clang -x c++ -target x86_64-apple-macos10.14 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -stdlib=libc++ -Wno-trigraphs -fpascal-strings -O2 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR=\"Debug\" -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -I/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/Debug/include -I/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/DerivedSources-normal/x86_64 -I/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/DerivedSources/x86_64 -I/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/DerivedSources -F/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/Debug -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -pipe -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0 -MMD -MT dependencies -MF /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/Objects-normal/x86_64/testCXXCompiler.d --serialize-diagnostics /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/Objects-normal/x86_64/testCXXCompiler.dia -c /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx -o /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/Objects-normal/x86_64/testCXXCompiler.o
    
    Ld Debug/cmTC_d7a05 normal x86_64
        cd /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target x86_64-apple-macos10.14 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -L/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/Debug -F/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/Debug -filelist /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/Objects-normal/x86_64/cmTC_d7a05.LinkFileList -stdlib=libc++ -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Xlinker -dependency_info -Xlinker /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/Objects-normal/x86_64/cmTC_d7a05_dependency_info.dat -o /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/Debug/cmTC_d7a05
    ld: warning: ignoring file /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_d7a05.build/Objects-normal/x86_64/testCXXCompiler.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
    Undefined symbols for architecture x86_64:
      "_main", referenced from:
         implicit entry/start for main executable
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
    ** BUILD FAILED **
    
    
    The following build commands failed:
        Ld Debug/cmTC_d7a05 normal x86_64
    (1 failure)
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:8 (project)


-- Configuring incomplete, errors occurred!

After going over many SO answers, I’ve realised that the problem is that CMake is using Clang and not Homebrew’s GCC. I’ve fixed this using a symlink, and now I get a different CMake error:

(base) adamhaber-s-macbookpro1:build adamhaber$ cmake ..
-- The CXX compiler identification is unknown
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /usr/local/bin/g++
-- Check for working CXX compiler: /usr/local/bin/g++ - broken
CMake Error at /usr/local/Cellar/cmake/3.19.2/share/cmake/Modules/CMakeTestCXXCompiler.cmake:59 (message):
  The C++ compiler

    "/usr/local/bin/g++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_82cfa -configuration Debug -hideShellScriptEnvironment && User defaults from command line:
        HideShellScriptEnvironment = YES
    
    Prepare build
    note: Using legacy build system
    === BUILD TARGET cmTC_82cfa OF PROJECT CMAKE_TRY_COMPILE WITH CONFIGURATION Debug ===
    
    Check dependencies
    
    Write auxiliary files
    /bin/mkdir -p /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_82cfa.build/Objects-normal/x86_64
    write-file /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_82cfa.build/Objects-normal/x86_64/cmTC_82cfa.LinkFileList
    
    CompileC CMAKE_TRY_COMPILE.build/Debug/cmTC_82cfa.build/Objects-normal/x86_64/testCXXCompiler.o testCXXCompiler.cxx normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
        cd /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp
        /usr/local/bin/gcc -x c++ -target x86_64-apple-macos10.14 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -stdlib=libc++ -Wno-trigraphs -fpascal-strings -O2 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR=\"Debug\" -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -I/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/Debug/include -I/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_82cfa.build/DerivedSources-normal/x86_64 -I/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_82cfa.build/DerivedSources/x86_64 -I/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_82cfa.build/DerivedSources -F/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/Debug -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -pipe -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0 -MMD -MT dependencies -MF /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_82cfa.build/Objects-normal/x86_64/testCXXCompiler.d --serialize-diagnostics /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_82cfa.build/Objects-normal/x86_64/testCXXCompiler.dia -c /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx -o /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_82cfa.build/Objects-normal/x86_64/testCXXCompiler.o
    gcc: error: x86_64-apple-macos10.14: No such file or directory
    gcc: error: /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_82cfa.build/Objects-normal/x86_64/testCXXCompiler.dia: No such file or directory
    gcc: error: unrecognized command-line option '-target'
    gcc: error: unrecognized command-line option '-fdiagnostics-show-note-include-stack'; did you mean '-fdiagnostics-show-template-tree'?
    gcc: error: unrecognized command-line option '-fmacro-backtrace-limit=0'; did you mean '-ftemplate-backtrace-limit='?
    gcc: error: unrecognized command-line option '-stdlib=libc++'
    gcc: error: unrecognized command-line option '-fpascal-strings'
    gcc: error: unrecognized command-line option '-fasm-blocks'
    gcc: error: unrecognized command-line option '--serialize-diagnostics'
    Command /usr/local/bin/gcc failed with exit code 1
    
    ** BUILD FAILED **
    
    
    The following build commands failed:
        CompileC CMAKE_TRY_COMPILE.build/Debug/cmTC_82cfa.build/Objects-normal/x86_64/testCXXCompiler.o testCXXCompiler.cxx normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
    (1 failure)
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:8 (project)


-- Configuring incomplete, errors occurred!
See also "/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeOutput.log".
See also "/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeError.log".

Any help would be much appreciated!

I suspect your Xcode and/or Homebrew compiler is not installed properly somehow, though I’m not sure exactly. There should be some error longs under CMakeFiles that would contain more information.

Cc: @brad.king

Thanks @ben.boeckel For completeness, here’s CMakeOutput.log:

The system is: Darwin - 18.7.0 - x86_64
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: /usr/local/bin/g++ 
Build flags: 
Id flags:  

The output was:
0


Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"

The CXX compiler identification is GNU, found in "/Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/3.19.2/CompilerIdCXX/a.out"

and here’s CMakeError.log:

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /usr/local/bin/g++ 
Build flags: -march=core2;-mtune=haswell;-mssse3;-ftree-vectorize;-fPIC;-fPIE;-fstack-protector-strong;-O2;-pipe;-stdlib=libc++;-fvisibility-inlines-hidden;-std=c++14;-fmessage-length=0
Id flags:  

The output was:
1
g++: error: unrecognized command-line option '-stdlib=libc++'


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /usr/local/bin/g++ 
Build flags: -march=core2;-mtune=haswell;-mssse3;-ftree-vectorize;-fPIC;-fPIE;-fstack-protector-strong;-O2;-pipe;-stdlib=libc++;-fvisibility-inlines-hidden;-std=c++14;-fmessage-length=0
Id flags: -c 

The output was:
1
g++: error: unrecognized command-line option '-stdlib=libc++'


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /usr/local/bin/g++ 
Build flags: -march=core2;-mtune=haswell;-mssse3;-ftree-vectorize;-fPIC;-fPIE;-fstack-protector-strong;-O2;-pipe;-stdlib=libc++;-fvisibility-inlines-hidden;-std=c++14;-fmessage-length=0
Id flags: --c++ 

The output was:
1
g++: error: unrecognized command-line option '-stdlib=libc++'
g++: error: unrecognized command-line option '--c++'


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /usr/local/bin/g++ 
Build flags: -march=core2;-mtune=haswell;-mssse3;-ftree-vectorize;-fPIC;-fPIE;-fstack-protector-strong;-O2;-pipe;-stdlib=libc++;-fvisibility-inlines-hidden;-std=c++14;-fmessage-length=0
Id flags: --ec++ 

The output was:
1
g++: error: unrecognized command-line option '-stdlib=libc++'
g++: error: unrecognized command-line option '--ec++'; did you mean '-Weffc++'?


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /usr/local/bin/g++ 
Build flags: -march=core2;-mtune=haswell;-mssse3;-ftree-vectorize;-fPIC;-fPIE;-fstack-protector-strong;-O2;-pipe;-stdlib=libc++;-fvisibility-inlines-hidden;-std=c++14;-fmessage-length=0
Id flags: --target=arm-arm-none-eabi;-mcpu=cortex-m3 

The output was:
1
g++: warning: '-mcpu=' is deprecated; use '-mtune=' or '-march=' instead
g++: error: unrecognized command-line option '-stdlib=libc++'
g++: error: unrecognized command-line option '--target=arm-arm-none-eabi'


Detecting CXX compiler ABI info failed to compile with the following output:
Change Dir: /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_23228/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make  -f CMakeFiles/cmTC_23228.dir/build.make CMakeFiles/cmTC_23228.dir/build
Building CXX object CMakeFiles/cmTC_23228.dir/CMakeCXXCompilerABI.cpp.o
/usr/local/bin/g++   -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++ -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0    -v -Wl,-v -o CMakeFiles/cmTC_23228.dir/CMakeCXXCompilerABI.cpp.o -c /usr/local/Cellar/cmake/3.19.2/share/cmake/Modules/CMakeCXXCompilerABI.cpp
Using built-in specs.
COLLECT_GCC=/usr/local/bin/g++
g++: error: unrecognized command-line option '-stdlib=libc++'
Target: x86_64-apple-darwin18
Configured with: ../configure --build=x86_64-apple-darwin18 --prefix=/usr/local/Cellar/gcc/10.2.0 --libdir=/usr/local/Cellar/gcc/10.2.0/lib/gcc/10 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-10 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 10.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk SED=/usr/bin/sed
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (Homebrew GCC 10.2.0) 
make[1]: *** [CMakeFiles/cmTC_23228.dir/CMakeCXXCompilerABI.cpp.o] Error 1
make: *** [cmTC_23228/fast] Error 2




Determining if the CXX compiler works failed with the following output:
Change Dir: /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_b924e/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make  -f CMakeFiles/cmTC_b924e.dir/build.make CMakeFiles/cmTC_b924e.dir/build
Building CXX object CMakeFiles/cmTC_b924e.dir/testCXXCompiler.cxx.o
/usr/local/bin/g++   -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++ -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0  -o CMakeFiles/cmTC_b924e.dir/testCXXCompiler.cxx.o -c /Users/adamhaber/Exercism/cpp/leap/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
g++: error: unrecognized command-line option '-stdlib=libc++'
make[1]: *** [CMakeFiles/cmTC_b924e.dir/testCXXCompiler.cxx.o] Error 1
make: *** [cmTC_b924e/fast] Error 2

Some more info that might be relevant:

(base) adamhaber-s-macbookpro1:build adamhaber$ which gcc
/usr/local/bin/gcc
(base) adamhaber-s-macbookpro1:build adamhaber$ which g++
/usr/local/bin/g++
(base) adamhaber-s-macbookpro1:build adamhaber$ which clang
/Users/adamhaber/miniconda3/bin/clang
(base) adamhaber-s-macbookpro1:build adamhaber$ which clang++
/Users/adamhaber/miniconda3/bin/clang++
(base) adamhaber-s-macbookpro1:build adamhaber$ echo $CC
/usr/local/bin/gcc
(base) adamhaber-s-macbookpro1:build adamhaber$ echo $CXX
/usr/local/bin/g++
(base) adamhaber-s-macbookpro1:build adamhaber$ 

Hmm. Not sure what is adding the -stdlib=libc++, but that seems to be the issue.

Solved it. According to https://stackoverflow.com/questions/34654682/unrecognized-command-line-option-stdlib-libc-gcc-homebrew-gcc-5-3-0-5-3-0, -stdlib=libc++ is a flag that’s specific to the clang compiler.

I ran brew install llvm, did some symlinks to make sure the right Clang is called, and now CMake runs smoothly. Thanks!