[CMake] Set Policy CMP0048 to NEW

CMake 3.0 introduced the VERSION option for the project() command. If you don't specify the VERSION in the function it will clear out variables matching ${PROJECT_NAME}_VERSION_${MAJOR|MINOR|PATCH|TWEAK}.

This makes overriding LLVM_VERSION_* not work properly with newer versions of CMake. To make this work properly we need to:

(1) Optionally set the policy to NEW
(2) Move default versions and setting PACKAGE_VERSION to before the call to project()
(3) If the policy is set, pass the VERSION and LANGUAGES options in the new format

This change should have no behavioral change for CMake versions before 3.0, and it makes the behavior of later versions match the earlier versions.

llvm-svn: 250275
This commit is contained in:
Chris Bieneman 2015-10-14 07:37:00 +00:00
parent 1b001b9f04
commit c7eb59a1ea

View File

@ -20,13 +20,33 @@ if (POLICY CMP0051)
cmake_policy(SET CMP0051 OLD)
endif()
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
set(cmake_3_0_PROJ_VERSION
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
set(cmake_3_0_LANGUAGES LANGUAGES)
endif()
if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
set(cmake_3_2_USES_TERMINAL)
else()
set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
endif()
project(LLVM C CXX ASM)
set(LLVM_VERSION_MAJOR 3)
set(LLVM_VERSION_MINOR 8)
set(LLVM_VERSION_PATCH 0)
set(LLVM_VERSION_SUFFIX svn)
if (NOT PACKAGE_VERSION)
set(PACKAGE_VERSION
"${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
endif()
project(LLVM
${cmake_3_0_PROJ_VERSION}
${cmake_3_0_LANGUAGES}
C CXX ASM)
# The following only works with the Ninja generator in CMake >= 3.0.
set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
@ -58,16 +78,6 @@ set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
)
set(LLVM_VERSION_MAJOR 3)
set(LLVM_VERSION_MINOR 8)
set(LLVM_VERSION_PATCH 0)
set(LLVM_VERSION_SUFFIX svn)
if (NOT PACKAGE_VERSION)
set(PACKAGE_VERSION
"${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
endif()
option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)