@@ -7451,6 +7451,54 @@ def test_emcc(self):
74517451 # TODO: test normal project linking, static and dynamic: get_library should not need to be told what to link!
74527452 # TODO: deprecate llvm optimizations, dlmalloc, etc. in emscripten.py.
74537453
7454+ def test_cmake (self ):
7455+ emscriptencmaketoolchain = path_from_root ('cmake' , 'Platform' , 'Emscripten.cmake' )
7456+
7457+ # On Windows, we want to build cmake-generated Makefiles with mingw32-make instead of e.g. cygwin make, since mingw32-make
7458+ # understands Windows paths, and cygwin make additionally produces a cryptic 'not valid bitcode file' errors on files that
7459+ # *are* valid bitcode files.
7460+ if os .name == 'nt' :
7461+ make_command = 'mingw32-make'
7462+ else :
7463+ make_command = 'make'
7464+
7465+ cmake_cases = ['target_js' , 'target_html' ]
7466+ cmake_outputs = ['hello_world.js' , 'hello_world_gles.html' ]
7467+ for i in range (0 , 2 ):
7468+ for configuration in ['Debug' , 'Release' ]:
7469+
7470+ # Create a temp workspace folder
7471+ cmakelistsdir = path_from_root ('tests' , 'cmake' , cmake_cases [i ])
7472+ tempdirname = tempfile .mkdtemp (prefix = 'emscripten_test_' + self .__class__ .__name__ + '_' , dir = TEMP_DIR )
7473+ try :
7474+ os .chdir (tempdirname )
7475+
7476+ # Run Cmake
7477+ cmd = ['cmake' , '-DCMAKE_TOOLCHAIN_FILE=' + emscriptencmaketoolchain , '-DCMAKE_BUILD_TYPE=' + configuration , '-G' 'Unix Makefiles' , cmakelistsdir ]
7478+ ret = Popen (cmd , stdout = PIPE , stderr = PIPE ).communicate ()
7479+ if 'error' in ret [1 ].lower ():
7480+ print >> sys .stderr , 'Failed command: ' + ' ' .join (cmd )
7481+ print >> sys .stderr , 'Result:\n ' + ret [1 ]
7482+ raise Exception (
'cmake call failed!' )
# cmake spams this silly message to stderr, so hide it: "Platform/Emscripten to use this system, please send your config file to [email protected] so it can be added to cmake" 7483+ assert os .path .exists (tempdirname + '/Makefile' ), 'CMake call did not produce a Makefile!'
7484+
7485+ # Build
7486+ cmd = [make_command ]
7487+ ret = Popen (cmd , stdout = PIPE ).communicate ()
7488+ if 'error' in ret [0 ].lower () and not '0 error(s)' in ret [0 ].lower ():
7489+ print >> sys .stderr , 'Failed command: ' + ' ' .join (cmd )
7490+ print >> sys .stderr , 'Result:\n ' + ret [0 ]
7491+ raise Exception ('make failed!' )
7492+ assert os .path .exists (tempdirname + '/' + cmake_outputs [i ]), 'Building a cmake-generated Makefile failed to produce an output file!'
7493+
7494+ # Run through node, if CMake produced a .js file.
7495+ if cmake_outputs [i ].endswith ('.js' ):
7496+ ret = Popen ([NODE_JS , tempdirname + '/' + cmake_outputs [i ]], stdout = PIPE ).communicate ()[0 ]
7497+ assert 'hello, world!' in ret , 'Running cmake-based .js application failed!'
7498+ finally :
7499+ os .chdir (path_from_root ('tests' )) # Move away from the directory we are about to remove.
7500+ shutil .rmtree (tempdirname )
7501+
74547502 def test_Os (self ):
74557503 for opt in ['s' , '0' ]:
74567504 output = Popen (['python' , EMCC , path_from_root ('tests' , 'hello_world.c' ), '-O' + opt ], stdout = PIPE , stderr = PIPE ).communicate ()
0 commit comments