This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Set cmake policy CMP0068 to suppress warnings on OSX
AbandonedPublic

Authored by hintonda on Jan 24 2018, 8:59 AM.

Details

Summary

Set cmake policy CMP0068=NEW, if available -- depends on D42463 which
also adds target property "BUILD_WITH_INSTALL_NAME_DIR On" to maintain
current behavior.

This is needed to suppress warnings on OSX starting with cmake version
3.9.6.

Diff Detail

Event Timeline

hintonda created this revision.Jan 24 2018, 8:59 AM

It turns out that policies don't survive a call to cmake_minimum_required(), so we need to rethink how llvm, et al, handles policies, e.g.:

  • move cmake_minimum_required() inside the if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) branch.
  • move all cmake_policy() commands from llvm/CMakeLists.txt into a separate file in llvm/cmake/modules and include that file in subordinate projects. below the cmake_minimum_required() command.
beanz accepted this revision.Jan 31 2018, 3:54 PM

Historically we've duplicated cmake_policy calls on a per-project basis which we needed to support standalone builds. That said, it would be nice if we had LLVM vend some CMake modules that encapsulated this stuff better. In general I think that cleanup would be ideal to do after we move LLVM to the GitHub mono-repo because then we can create a cmake/modules folder at the root of the mono-repo that has common modules useable by all sub-projects.

As-is, this patch is the right way to go.

This revision is now accepted and ready to land.Jan 31 2018, 3:54 PM

Historically we've duplicated cmake_policy calls on a per-project basis which we needed to support standalone builds. That said, it would be nice if we had LLVM vend some CMake modules that encapsulated this stuff better. In general I think that cleanup would be ideal to do after we move LLVM to the GitHub mono-repo because then we can create a cmake/modules folder at the root of the mono-repo that has common modules useable by all sub-projects.

As-is, this patch is the right way to go.

This patch isn't completely OBE, but in order maintain backward compatibility, it should also set CMAKE_BUILD_WITH_INSTALL_NAME_DIR=ON, e.g., when doing out-of-tree builds that don't get CMAKE_BUILD_WITH_INSTALL_NAME_DIR=ON from llvm.

I ultimately updated D42463 to set both CMP0068 and CMAKE_BUILD_WITH_INSTALL_NAME_DIR=ON in llvm/CMakeLists.txt. This was needed for in-tree builds since cache variables survive calls to cmake_minimum_required(), and policies don't.

Perhaps a better option for this policy would be to move the fix from D42463 to llvm/cmake/AddLLVM.cmake so llvm_setup_rpath() always does the right thing, even when called by sub-projects for both in and out-of-tree builds. Thus obviating the need for this patch.

hintonda abandoned this revision.Mar 24 2018, 9:01 AM

Not needed for llvm+clang builds.