Skip to content

Commit 85cba40

Browse files
committed
emmakenxx.py to handle .c files in projects that are really c++
1 parent 6345f59 commit 85cba40

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

tools/emmaken.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* With CMake, do something like
2525
2626
SET(CMAKE_C_COMPILER "PATH/emmaken.py")
27-
SET(CMAKE_CXX_COMPILER "PATH/emmaken.py")
27+
SET(CMAKE_CXX_COMPILER "PATH/emmakenxx.py")
2828
SET(CMAKE_LINKER "PATH/emmaken.py")
2929
SET(CMAKE_CXX_LINKER "PATH/emmaken.py")
3030
SET(CMAKE_C_LINK_EXECUTABLE "PATH/emmaken.py")
@@ -37,6 +37,15 @@
3737
give to Emscripten. Note that this tool doesn't run Emscripten itself. Note
3838
also that you may need to do some manual fiddling later, for example to
3939
link files that weren't linked, and them llvm-dis them.
40+
41+
Note the appearance of emmakenxx.py instead of emmaken.py
42+
for the C++ compiler. This is needed for cases where we get
43+
a C++ file with a C extension, in which case CMake can be told
44+
to run g++ on it despite the .c extension, see
45+
46+
https://github.com/kripken/emscripten/issues/6
47+
48+
(If a similar situation occurs with ./configure, you can do the same there too.)
4049
'''
4150

4251
import sys
@@ -65,6 +74,11 @@ def path_from_root(*pathelems):
6574
CXX = os.environ.get('EMMAKEN_COMPILER') or LLVM_GCC
6675
CC = to_cc(CXX)
6776

77+
# If we got here from a redirection through emmakenxx.py, then force a C++ compiler here
78+
if sys.argv[-1] == '-EMMAKEN_CXX':
79+
CC = CXX
80+
sys.argv = sys.argv[:-1]
81+
6882
CC_ARG_SKIP = ['-O1', '-O2', '-O3']
6983
CC_ADDITIONAL_ARGS = ['-m32', '-U__i386__', '-U__x86_64__', '-U__SSE__', '-UX87_DOUBLE_ROUNDING', '-UHAVE_GCC_ASM_FOR_X87']
7084
ALLOWED_LINK_ARGS = ['-f', '-help', '-o', '-print-after', '-print-after-all', '-print-before',

tools/emmakenxx.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
see emmaken.py
5+
'''
6+
7+
import os, sys
8+
9+
abspath = os.path.abspath(os.path.dirname(__file__))
10+
def path_from_root(*pathelems):
11+
return os.path.join(os.path.sep, *(abspath.split(os.sep)[:-1] + list(pathelems)))
12+
exec(open(path_from_root('tools', 'shared.py'), 'r').read())
13+
14+
emmaken = path_from_root('tools', 'emmaken.py')
15+
exit(os.execvp('python', ['python', emmaken] + sys.argv[1:] + ['-EMMAKEN_CXX']))
16+

0 commit comments

Comments
 (0)