google/cctz

Build on macOS with LLVM 9.0.1 Clang Compiler

dFohlen opened this issue ยท 9 comments

Hi guys,

building cctz v2.3 on macOS with LLVM 9.0.1 Clang complier fails, because the target_compile_features command was introduced in CMake 3.1, so if you're calling it then it is expected that your cmake_mimimum_required is at least 3.1:

cmake -DBUILD_TESTING="False" ..
-- The C compiler identification is Clang 9.0.1
-- The CXX compiler identification is Clang 9.0.1
-- Check for working C compiler: /usr/local/Cellar/llvm/9.0.1/bin/clang
-- Check for working C compiler: /usr/local/Cellar/llvm/9.0.1/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/local/Cellar/llvm/9.0.1/bin/clang++
-- Check for working CXX compiler: /usr/local/Cellar/llvm/9.0.1/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:57 (target_compile_features):
  target_compile_features no known features for CXX compiler

  "Clang"

  version 9.0.1.
Call Stack (most recent call first):
  CMakeLists.txt:91 (cctz_target_set_cxx_standard)


CMake Error at CMakeLists.txt:57 (target_compile_features):
  target_compile_features no known features for CXX compiler

  "Clang"

  version 9.0.1.
Call Stack (most recent call first):
  CMakeLists.txt:104 (cctz_target_set_cxx_standard)


CMake Error at CMakeLists.txt:57 (target_compile_features):
  target_compile_features no known features for CXX compiler

  "Clang"

  version 9.0.1.
Call Stack (most recent call first):
  examples/CMakeLists.txt:2 (cctz_target_set_cxx_standard)


CMake Error at CMakeLists.txt:57 (target_compile_features):
  target_compile_features no known features for CXX compiler

  "Clang"

  version 9.0.1.
Call Stack (most recent call first):
  examples/CMakeLists.txt:6 (cctz_target_set_cxx_standard)


CMake Error at CMakeLists.txt:57 (target_compile_features):
  target_compile_features no known features for CXX compiler

  "Clang"

  version 9.0.1.
Call Stack (most recent call first):
  examples/CMakeLists.txt:10 (cctz_target_set_cxx_standard)


CMake Error at CMakeLists.txt:57 (target_compile_features):
  target_compile_features no known features for CXX compiler

  "Clang"

  version 9.0.1.
Call Stack (most recent call first):
  examples/CMakeLists.txt:14 (cctz_target_set_cxx_standard)


CMake Error at CMakeLists.txt:57 (target_compile_features):
  target_compile_features no known features for CXX compiler

  "Clang"

  version 9.0.1.
Call Stack (most recent call first):
  examples/CMakeLists.txt:18 (cctz_target_set_cxx_standard)


CMake Error at CMakeLists.txt:57 (target_compile_features):
  target_compile_features no known features for CXX compiler

  "Clang"

  version 9.0.1.
Call Stack (most recent call first):
  examples/CMakeLists.txt:22 (cctz_target_set_cxx_standard)


CMake Error at CMakeLists.txt:57 (target_compile_features):
  target_compile_features no known features for CXX compiler

  "Clang"

  version 9.0.1.
Call Stack (most recent call first):
  examples/CMakeLists.txt:26 (cctz_target_set_cxx_standard)


--
-- Configuring incomplete, errors occurred!

Therefore the cmake_mimimum_required version should be raised from 2.8.12 to 3.1, or it should be handled explicitly.

The code is supposed to handle that:

cctz/CMakeLists.txt

Lines 45 to 59 in 913f842

# Starting from CMake >= 3.1, if a specific standard is required,
# it can be set from the command line with:
# cmake -DCMAKE_CXX_STANDARD=[11|14|17]
function(cctz_target_set_cxx_standard target)
set(cxx_standard 11)
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(${target} PRIVATE -std=c++${cxx_standard})
endif()
elseif (CMAKE_VERSION VERSION_LESS "3.8")
set_property(TARGET ${target} PROPERTY CXX_STANDARD ${cxx_standard})
else()
target_compile_features(${target} PUBLIC cxx_std_${cxx_standard})
endif()
endfunction()

Maybe you can add some debugs to understand what is happening.

I do not have the issue on Linux:

$ cmake --version
cmake version 3.16.4

CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ clang --version
clang version 9.0.1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ env CC=clang CXX=clang++ cmake -G Ninja -DBUILD_TESTING=OFF ..
-- The C compiler identification is Clang 9.0.1
-- The CXX compiler identification is Clang 9.0.1
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/cctz/build
$ ninja
[27/27] Finished
$

Thanks @Sarcasm.

@FohlenAFK: Were you able to figure out what was happening? Do you still think something needs to change? Thanks.

Sorry @Sarcasm and @devbww I was a little stressed out.

$ cmake --version
cmake version 3.16.4

I've added some debugs and the function you mentioned is called in the correct case (CMAKE_VERSION > 3.8), e.g. with: target_compile_features(cctz PUBLIC cxx_std_11). This call throws this error:

CMake Error at CMakeLists.txt: 58 (target_compile_features):
   target_compile_features no known features for CXX compiler

   "Clang"

   version 9.0.1.
Call stack (most recent call first):
   CMakeLists.txt: 93 (cctz_target_set_cxx_standard)

I found a similar issue here.

I found a similar issue here.

So does adding ...

if(POLICY CMP0025)
  cmake_policy(SET CMP0025 NEW)
endif()

after the cmake_minimum_required() make a difference for you?

No, not in my case. I've tested also this:

if(POLICY CMP0003)
  #NEW: always link libraries by full path
  cmake_policy(SET CMP0003 NEW)
endif()

if(POLICY CMP0018)
  #NEW: enable PROPERTY POSITION_INDEPENDENT_CODE
  cmake_policy(SET CMP0018 NEW)
endif()

if(POLICY CMP0025)
  #NEW: report OS X version of Clang as "AppleClang"
  cmake_policy(SET CMP0025 NEW)
endif()

if(POLICY CMP0026)
  #NEW: disable deprecated LOCATION property. 
  cmake_policy(SET CMP0026 NEW)
endif()

if(POLICY CMP0042)
  #NEW: set TARGET PROPERTY MACOSX_RPATH to on by default
  cmake_policy(SET CMP0042 NEW)
endif()

if(POLICY CMP0053)
  #NEW: use stricter and safer variable name rules
  cmake_policy(SET CMP0053 NEW)
endif()

if(POLICY CMP0056)
  #pass linker flags to compile tests
  cmake_policy(SET CMP0056 NEW)
endif()

if(POLICY CMP0058)
  #OLD: Spoof Ninja dependencies that don't exist in case they are custom command byproducts
  # We would actually like to set this to the new behavior, but it doesn't exist in CMake 3.1 and we want consistency
  cmake_policy(SET CMP0058 OLD)
endif()

if(POLICY CMP0060)
  #NEW: Link all libraries by full path regardless of implicit dirs
  cmake_policy(SET CMP0060 NEW)
endif()


if(POLICY CMP0065)
  #NEW: do not export executable symbols by default
  cmake_policy(SET CMP0065 NEW)
endif()

if(POLICY CMP0066)
  #NEW: pass CMAKE_<lang>_FLAGS_<config> to try_compile() statements
  cmake_policy(SET CMP0066 NEW)
endif()

if(POLICY CMP0073)
  #NEW: don't generate xxx_LIB_DEPENDS cache entries (which screw up the build when switching between bundled and external libraries)
  cmake_policy(SET CMP0073 NEW)
endif()

if(POLICY CMP0075)
  #NEW: when compliling header check executables, link them to the contents of CMAKE_REQUIRED_LIBRARIES
  cmake_policy(SET CMP0073 NEW)
endif()

which leads to this:

CMake Deprecation Warning at CMakeLists.txt:44 (cmake_policy):
  The OLD behavior for policy CMP0058 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.

Just to be sure, you put the policy in-between the cmake_minimum_required() and project() calls, as they describe in the bug report?

Do you also have an issue with the sample project from the bugticket ?

I've forgot to clear the build directory ๐Ÿ™ˆ
So ...

if(POLICY CMP0025)
  cmake_policy(SET CMP0025 NEW)
endif()

solves the problem:

$ cmake -DBUILD_TESTING="False" ..
-- The C compiler identification is Clang 9.0.1
-- The CXX compiler identification is Clang 9.0.1
-- Check for working C compiler: /usr/local/Cellar/llvm/9.0.1/bin/clang
-- Check for working C compiler: /usr/local/Cellar/llvm/9.0.1/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/local/Cellar/llvm/9.0.1/bin/clang++
-- Check for working CXX compiler: /usr/local/Cellar/llvm/9.0.1/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/git/cctz-2.3/build

Thanks a lot @Sarcasm, @devbww ๐Ÿ‘

Excellent. Thanks @FohlenAFK.

@Sarcasm ... if you agree with all this and you have a moment, I'll happily approve a PR.

Fixed by #135.

@FohlenAFK ... please reopen if any problem remains. And thanks for raising the issue.