aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2019-03-17 21:31:02 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2019-03-18 22:01:06 +0200
commit93df9530c820402d553d3db2b1b3a93ba13161fb (patch)
treedfeb742286707aa18df4d8cdd204aba7beba3e8c
parent4b95dd3a6d1a08e22a144f3336f44e0d2c92bd75 (diff)
downloadmeson-93df9530c820402d553d3db2b1b3a93ba13161fb.zip
meson-93df9530c820402d553d3db2b1b3a93ba13161fb.tar.gz
meson-93df9530c820402d553d3db2b1b3a93ba13161fb.tar.bz2
Make custom lib script work with MSVC.
-rwxr-xr-xtest cases/common/216 link custom/custom_stlib.py48
-rw-r--r--test cases/common/216 link custom/meson.build4
2 files changed, 40 insertions, 12 deletions
diff --git a/test cases/common/216 link custom/custom_stlib.py b/test cases/common/216 link custom/custom_stlib.py
index 776dfbf..925d997 100755
--- a/test cases/common/216 link custom/custom_stlib.py
+++ b/test cases/common/216 link custom/custom_stlib.py
@@ -8,8 +8,6 @@ parser.add_argument('--private-dir', required=True)
parser.add_argument('-o', required=True)
parser.add_argument('cmparr', nargs='+')
-static_linker = 'ar'
-
contents = '''#include<stdio.h>
void flob() {
@@ -17,12 +15,8 @@ void flob() {
}
'''
-def generate_lib(outfile, private_dir, compiler_array):
- outdir = pathlib.Path(private_dir)
- if not outdir.exists():
- outdir.mkdir()
- c_file = outdir / 'flob.c'
- c_file.write_text(contents)
+def generate_lib_gnulike(outfile, c_file, private_dir, compiler_array):
+ static_linker = 'ar'
o_file = c_file.with_suffix('.o')
compile_cmd = compiler_array + ['-c', '-g', '-O2', '-o', o_file, c_file]
subprocess.check_call(compile_cmd)
@@ -31,8 +25,42 @@ def generate_lib(outfile, private_dir, compiler_array):
out_file.unlink()
link_cmd = [static_linker, 'csrD', outfile, o_file]
subprocess.check_call(link_cmd)
+ return 0
+
+
+def generate_lib_msvc(outfile, c_file, private_dir, compiler_array):
+ static_linker = 'lib'
+ o_file = c_file.with_suffix('.obj')
+ compile_cmd = compiler_array + ['/MDd',
+ '/nologo',
+ '/ZI',
+ '/Ob0',
+ '/Od',
+ '/c',
+ '/Fo' + str(o_file),
+ str(c_file)]
+ subprocess.check_call(compile_cmd)
+ out_file = pathlib.Path(outfile)
+ if out_file.exists():
+ out_file.unlink()
+ link_cmd = [static_linker,
+ '/nologo',
+ '/OUT:' + str(outfile),
+ str(o_file)]
+ subprocess.check_call(link_cmd)
+ return 0
+
+def generate_lib(outfile, private_dir, compiler_array):
+ private_dir = pathlib.Path(private_dir)
+ if not private_dir.exists():
+ private_dir.mkdir()
+ c_file = private_dir / 'flob.c'
+ c_file.write_text(contents)
+ for i in compiler_array:
+ if i.endswith('cl') or i.endswith('cl.exe'):
+ return generate_lib_msvc(outfile, c_file, private_dir, compiler_array)
+ return generate_lib_gnulike(outfile, c_file, private_dir, compiler_array)
if __name__ == '__main__':
options = parser.parse_args()
- generate_lib(options.o, options.private_dir, options.cmparr)
- sys.exit(1)
+ sys.exit(generate_lib(options.o, options.private_dir, options.cmparr))
diff --git a/test cases/common/216 link custom/meson.build b/test cases/common/216 link custom/meson.build
index 3dc11ec..dc01354 100644
--- a/test cases/common/216 link custom/meson.build
+++ b/test cases/common/216 link custom/meson.build
@@ -4,7 +4,8 @@ project('linkcustom', 'c')
# it detect it by itself. I'm too lazy to implement it now and it is not
# really needed for testing that custom targets work. It is the responsibility
# of the custom target to produce things in the correct format.
-assert(not meson.is_cross(), 'MESON_SKIP_TEST cross checking not implemented.')
+assert(not meson.is_cross_build(),
+ 'MESON_SKIP_TEST cross checking not implemented.')
cc = meson.get_compiler('c')
genprog = find_program('custom_stlib.py')
@@ -17,4 +18,3 @@ clib = custom_target('linkcustom',
#exe = executable('prog', 'prog.c', link_with: clib)
#test('linkcustom', exe)
- \ No newline at end of file