CMakePackage: added 'ipo' variant (#18374)

+ipo sets CMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
The option is not supported for CMake < 3.9
This commit is contained in:
Omri Mor 2020-10-21 02:09:45 -07:00 committed by GitHub
parent bed929e7a9
commit 1147220b9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@
import spack.build_environment
from llnl.util.filesystem import working_dir
from spack.util.environment import filter_system_paths
from spack.directives import depends_on, variant
from spack.directives import depends_on, variant, conflicts
from spack.package import PackageBase, InstallError, run_after
# Regex to extract the primary generator from the CMake generator
@ -94,6 +94,13 @@ class CMakePackage(PackageBase):
description='CMake build type',
values=('Debug', 'Release', 'RelWithDebInfo', 'MinSizeRel'))
# https://cmake.org/cmake/help/latest/variable/CMAKE_INTERPROCEDURAL_OPTIMIZATION.html
variant('ipo', default=False,
description='CMake interprocedural optimization')
# CMAKE_INTERPROCEDURAL_OPTIMIZATION only exists for CMake >= 3.9
conflicts('+ipo', when='^cmake@:3.8',
msg='+ipo is not supported by CMake < 3.9')
depends_on('cmake', type='build')
@property
@ -147,6 +154,11 @@ def _std_args(pkg):
except KeyError:
build_type = 'RelWithDebInfo'
try:
ipo = pkg.spec.variants['ipo'].value
except KeyError:
ipo = False
define = CMakePackage.define
args = [
'-G', generator,
@ -154,6 +166,10 @@ def _std_args(pkg):
define('CMAKE_BUILD_TYPE', build_type),
]
# CMAKE_INTERPROCEDURAL_OPTIMIZATION only exists for CMake >= 3.9
if pkg.spec.satisfies('^cmake@3.9:'):
args.append(define('CMAKE_INTERPROCEDURAL_OPTIMIZATION', ipo))
if primary_generator == 'Unix Makefiles':
args.append(define('CMAKE_VERBOSE_MAKEFILE', True))