summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/cmake/package.py
diff options
context:
space:
mode:
Diffstat (limited to 'var/spack/repos/builtin/packages/cmake/package.py')
-rw-r--r--var/spack/repos/builtin/packages/cmake/package.py127
1 files changed, 94 insertions, 33 deletions
diff --git a/var/spack/repos/builtin/packages/cmake/package.py b/var/spack/repos/builtin/packages/cmake/package.py
index e91b6eacdc..e431dc62e5 100644
--- a/var/spack/repos/builtin/packages/cmake/package.py
+++ b/var/spack/repos/builtin/packages/cmake/package.py
@@ -3,9 +3,13 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import os
import re
+import shutil
+import sys
import spack.build_environment
+from spack import *
class Cmake(Package):
@@ -141,6 +145,12 @@ class Cmake(Package):
# https://gitlab.kitware.com/cmake/cmake/merge_requests/4075
patch('fix-xlf-ninja-mr-4075.patch', sha256="42d8b2163a2f37a745800ec13a96c08a3a20d5e67af51031e51f63313d0dedd1", when="@3.15.5")
+ generator = "Unix Makefiles"
+
+ if sys.platform == 'win32':
+ generator = "Ninja"
+ depends_on('ninja')
+
# We default ownlibs to true because it greatly speeds up the CMake
# build, and CMake is built frequently. Also, CMake is almost always
# a build dependency, and its libs will not interfere with others in
@@ -149,7 +159,7 @@ class Cmake(Package):
variant('qt', default=False, description='Enables the build of cmake-gui')
variant('doc', default=False, description='Enables the generation of html and man page documentation')
variant('openssl', default=True, description="Enable openssl for curl bootstrapped by CMake when using +ownlibs")
- variant('ncurses', default=True, description='Enables the build of the ncurses gui')
+ variant('ncurses', default=os.name != 'nt', description='Enables the build of the ncurses gui')
# See https://gitlab.kitware.com/cmake/cmake/-/issues/21135
conflicts('%gcc platform=darwin', when='@:3.17',
@@ -241,36 +251,47 @@ class Cmake(Package):
flags.append(self.compiler.cxx11_flag)
return (flags, None, None)
- def bootstrap_args(self):
+ def setup_build_environment(self, env):
spec = self.spec
- args = [
- '--prefix={0}'.format(self.prefix),
- '--parallel={0}'.format(make_jobs)
- ]
+ if '+openssl' in spec:
+ env.set('OPENSSL_ROOT_DIR', spec['openssl'].prefix)
- if '+ownlibs' in spec:
- # Build and link to the CMake-provided third-party libraries
- args.append('--no-system-libs')
- else:
- # Build and link to the Spack-installed third-party libraries
- args.append('--system-libs')
-
- if spec.satisfies('@3.2:'):
- # jsoncpp requires CMake to build
- # use CMake-provided library to avoid circular dependency
- args.append('--no-system-jsoncpp')
-
- if '+qt' in spec:
- args.append('--qt-gui')
+ def bootstrap_args(self):
+ spec = self.spec
+ args = []
+ if not os.name == 'nt':
+ args.extend(
+ ['--prefix={0}'.format(self.prefix),
+ '--parallel={0}'.format(make_jobs)]
+ )
+
+ if '+ownlibs' in spec:
+ # Build and link to the CMake-provided third-party libraries
+ args.append('--no-system-libs')
+ else:
+ # Build and link to the Spack-installed third-party libraries
+ args.append('--system-libs')
+
+ if spec.satisfies('@3.2:'):
+ # jsoncpp requires CMake to build
+ # use CMake-provided library to avoid circular dependency
+ args.append('--no-system-jsoncpp')
+
+ if '+qt' in spec:
+ args.append('--qt-gui')
+ else:
+ args.append('--no-qt-gui')
+
+ if '+doc' in spec:
+ args.append('--sphinx-html')
+ args.append('--sphinx-man')
+
+ # Now for CMake arguments to pass after the initial bootstrap
+ args.append('--')
else:
- args.append('--no-qt-gui')
-
- if '+doc' in spec:
- args.append('--sphinx-html')
- args.append('--sphinx-man')
-
- # Now for CMake arguments to pass after the initial bootstrap
- args.append('--')
+ args.append('-DCMAKE_INSTALL_PREFIX=%s' % self.prefix)
+ if self.spec.satisfies('generator=Ninja'):
+ args.append('-GNinja')
args.append('-DCMAKE_BUILD_TYPE={0}'.format(
self.spec.variants['build_type'].value))
@@ -297,21 +318,61 @@ class Cmake(Package):
return args
+ def winbootcmake(self, spec):
+ from spack import fetch_strategy, stage
+ urls = {
+ '3': ('https://cmake.org/files/v3.21/cmake-3.21.2-windows-x86_64.zip', "f21e72ede9d15070602b60b2c14dc779"),
+ '2': ('https://cmake.org/files/v2.8/cmake-2.8.4-win32-x86.zip', "a2525342e495518101381203bf4484c4")
+ }
+ if spec.satisfies('@3.0.2:'):
+ bootstrap_url = urls['3']
+ else:
+ bootstrap_url = urls['2']
+ remote = fetch_strategy.URLFetchStrategy(url=bootstrap_url[0],
+ checksum=bootstrap_url[1])
+ bootstrap_stage_path = os.path.join(self.stage.path, "cmake-bootstraper")
+ with stage.Stage(remote, path=bootstrap_stage_path) as bootstrap_stage:
+ remote.stage = bootstrap_stage
+ remote.fetch()
+ remote.check()
+ remote.expand()
+ shutil.move(bootstrap_stage.source_path, self.stage.source_path)
+
+ def cmake_bootstrap(self):
+ exe_prefix = self.stage.source_path
+ relative_cmake_exe = os.path.join('spack-src', 'bin', 'cmake.exe')
+ return Executable(os.path.join(exe_prefix, relative_cmake_exe))
+
def bootstrap(self, spec, prefix):
- bootstrap = Executable('./bootstrap')
- bootstrap(*self.bootstrap_args())
+ bootstrap_args = self.bootstrap_args()
+ if os.name == 'nt':
+ self.winbootcmake(spec)
+ bootstrap = self.cmake_bootstrap()
+ bootstrap_args.extend(['.'])
+ else:
+ bootstrap = Executable('./bootstrap')
+ bootstrap(*bootstrap_args)
def build(self, spec, prefix):
- make()
+ if self.generator == "Ninja":
+ ninja()
+ else:
+ make()
@run_after('build')
@on_package_attributes(run_tests=True)
def build_test(self):
# Some tests fail, takes forever
- make('test')
+ if self.generator == "Ninja":
+ ninja('test')
+ else:
+ make('test')
def install(self, spec, prefix):
- make('install')
+ if self.generator == "Ninja":
+ ninja('install')
+ else:
+ make('install')
if spec.satisfies('%fj'):
for f in find(self.prefix, 'FindMPI.cmake', recursive=True):