MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / test_cmake

Method test_cmake

test/test_other.py:872–927  ·  view source on GitHub ↗
(self, test_dir, output_file, cmake_args)

Source from the content-addressed store, hash-verified

870 'cxx20': ('cxx20', 'cxx20test.js', []),
871 })
872 def test_cmake(self, test_dir, output_file, cmake_args):
873 if test_dir == 'whole_archive' and 'EMTEST_SKIP_NEW_CMAKE' in os.environ:
874 self.skipTest('EMTEST_SKIP_NEW_CMAKE set')
875
876 # Test all supported generators.
877 if WINDOWS:
878 generators = ['MinGW Makefiles', 'NMake Makefiles']
879 else:
880 generators = ['Unix Makefiles', 'Ninja', 'Eclipse CDT4 - Ninja']
881
882 configurations = {
883 'MinGW Makefiles' : {'build' : ['mingw32-make'] }, # noqa
884 'NMake Makefiles' : {'build' : ['nmake', '/NOLOGO']}, # noqa
885 'Unix Makefiles' : {'build' : ['make']}, # noqa
886 'Ninja' : {'build' : ['ninja']}, # noqa
887 'Eclipse CDT4 - Ninja': {'build' : ['ninja']}, # noqa
888 }
889 for generator in generators:
890 conf = configurations[generator]
891
892 if not shutil.which(conf['build'][0]):
893 # Use simple test if applicable
894 print('Skipping %s test for CMake support; build tool not found: %s.' % (generator, conf['build'][0]))
895 continue
896
897 cmakelistsdir = test_file('cmake', test_dir)
898 builddir = 'out_' + generator.replace(' ', '_').lower()
899 os.mkdir(builddir)
900 with common.chdir(builddir):
901 # Run Cmake
902
903 # Some tests have very old cmake_minimum_version settings which is not supported by cmake 4+.
904 # Forcing a slighly more recent cmake_minimum_version works around this issue.
905 cmd = [EMCMAKE, 'cmake'] + cmake_args + ['-G', generator, cmakelistsdir, '-DCMAKE_POLICY_VERSION_MINIMUM=3.5']
906
907 env = os.environ.copy()
908 # https://github.com/emscripten-core/emscripten/pull/5145: Check that CMake works even if EMCC_SKIP_SANITY_CHECK=1 is passed.
909 if test_dir == 'target_html':
910 env['EMCC_SKIP_SANITY_CHECK'] = '1'
911 print(str(cmd))
912 self.run_process(cmd, env=env)
913
914 # Build
915 cmd = conf['build']
916 if common.EMTEST_VERBOSE and 'Ninja' not in generator:
917 cmd += ['VERBOSE=1']
918 self.run_process(cmd)
919 self.assertExists(output_file, 'building a cmake-generated Makefile failed to produce an output file %s!' % output_file)
920
921 # Run through node, if CMake produced a .js file.
922 if output_file.endswith('.js'):
923 ret = self.run_js(output_file)
924 self.assertFileContents(os.path.join(cmakelistsdir, 'out.txt'), ret)
925
926 if test_dir == 'post_build':
927 ret = self.run_process(['ctest'], env=env)
928
929 @crossplatform

Callers

nothing calls this directly

Calls 9

test_fileFunction · 0.90
lowerMethod · 0.80
run_processMethod · 0.80
assertExistsMethod · 0.80
run_jsMethod · 0.80
assertFileContentsMethod · 0.80
printFunction · 0.50
copyMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected