Skip to content

Commit

Permalink
Fix compiling ObjC/ObjC++ on Windows/MinGW
Browse files Browse the repository at this point in the history
Co-Authored-By: L. E. Segovia <[email protected]>
  • Loading branch information
2 people authored and dcbaker committed Aug 8, 2024
1 parent 43b80e0 commit 81b151f
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 3 deletions.
2 changes: 2 additions & 0 deletions mesonbuild/cmake/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def make_abs(exe: str) -> str:
defaults[prefix + 'COMPILER'] = exe_list
if comp_obj.get_id() == 'clang-cl':
defaults['CMAKE_LINKER'] = comp_obj.get_linker_exelist()
if lang.startswith('objc') and comp_obj.get_id().startswith('clang'):
defaults[f'{prefix}FLAGS'] = ['-D__STDC__=1']

return defaults

Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
defaults['cpp'] = ['icl', 'cl', 'c++', 'g++', 'clang++', 'clang-cl']
# the binary flang-new will be renamed to flang in the foreseeable future
defaults['fortran'] = ['ifort', 'gfortran', 'flang-new', 'flang', 'pgfortran', 'g95']
defaults['objc'] = ['clang-cl', 'gcc']
defaults['objcpp'] = ['clang-cl', 'g++']
defaults['objc'] = ['clang', 'clang-cl', 'gcc']
defaults['objcpp'] = ['clang++', 'clang-cl', 'g++']
defaults['cs'] = ['csc', 'mcs']
else:
if platform.machine().lower() == 'e2k':
Expand Down
2 changes: 2 additions & 0 deletions mesonbuild/compilers/mixins/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def __init__(self, defines: T.Optional[T.Dict[str, str]]):
# linkers don't have base_options.
if isinstance(self.linker, AppleDynamicLinker):
self.base_options.add(OptionKey('b_bitcode'))
elif isinstance(self.linker, MSVCDynamicLinker):
self.base_options.add(OptionKey('b_vscrt'))
# All Clang backends can also do LLVM IR
self.can_compile_suffixes.add('ll')

Expand Down
2 changes: 2 additions & 0 deletions mesonbuild/compilers/mixins/visualstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ def symbols_have_underscore_prefix(self, env: 'Environment') -> bool:
# As a last resort, try search in a compiled binary
return self._symbols_have_underscore_prefix_searchbin(env)

def get_pie_args(self) -> T.List[str]:
return []

class MSVCCompiler(VisualStudioLikeCompiler):

Expand Down
3 changes: 3 additions & 0 deletions mesonbuild/linkers/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,9 @@ def import_library_args(self, implibname: str) -> T.List[str]:
def rsp_file_syntax(self) -> RSPFileSyntax:
return self.rsp_syntax

def get_pie_args(self) -> T.List[str]:
return []


class MSVCDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):

Expand Down
6 changes: 6 additions & 0 deletions test cases/cmake/24 mixing languages/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ if not add_languages('objc', required : false)
error('MESON_SKIP_TEST: No ObjC compiler')
endif

objc = meson.get_compiler('objc')
c = meson.get_compiler('c')
if c.get_argument_syntax() != objc.get_argument_syntax()
error('MESON_SKIP_TEST: cmake cannot mix compiler types on Windows')
endif

cm = import('cmake')

sub_pro = cm.subproject('cmTest')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project(cmTest)
project(cmTest LANGUAGES C OBJC)

include_directories(${CMAKE_CURRENT_BINARY_DIR})

Expand Down
3 changes: 3 additions & 0 deletions test cases/failing build/11 objc werror/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ project('test', default_options: ['werror=true'])
if not add_languages('objc', required: false)
error('MESON_SKIP_TEST: Objective C not found')
endif
if get_option('backend').startswith('vs')
error('MESON_SKIP_TEST: objcpp is not supported by vs backend')
endif
executable('prog', 'test.m')
3 changes: 3 additions & 0 deletions test cases/failing build/12 objcpp werror/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ project('test', default_options: ['werror=true'])
if not add_languages('objcpp', required: false)
error('MESON_SKIP_TEST: Objective C++ not found')
endif
if get_option('backend').startswith('vs')
error('MESON_SKIP_TEST: objcpp is not supported by vs backend')
endif
executable('prog', 'test.mm')
4 changes: 4 additions & 0 deletions test cases/objc/1 simple/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
project('objective c', 'objc', default_options: ['c_std=c99'])

if get_option('backend').startswith('vs')
error('MESON_SKIP_TEST: objc is not supported by vs backend')
endif

exe = executable('prog', 'prog.m')
test('objctest', exe)
4 changes: 4 additions & 0 deletions test cases/objc/2 nsstring/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
project('nsstring', 'objc')

if get_option('backend').startswith('vs')
error('MESON_SKIP_TEST: objc is not supported by vs backend')
endif

if host_machine.system() == 'darwin'
dep = dependency('appleframeworks', modules : 'Foundation')
elif host_machine.system() == 'cygwin'
Expand Down
4 changes: 4 additions & 0 deletions test cases/objc/3 objc args/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
project('objective c args', 'objc')

if get_option('backend').startswith('vs')
error('MESON_SKIP_TEST: objc is not supported by vs backend')
endif

exe = executable('prog', 'prog.m', objc_args : ['-DMESON_TEST'])
test('objective c args', exe)
4 changes: 4 additions & 0 deletions test cases/objc/4 c++ project objc subproject/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
project('master', ['cpp'])

if get_option('backend').startswith('vs')
error('MESON_SKIP_TEST: objc is not supported by vs backend')
endif

foo = subproject('foo')
dep = foo.get_variable('foo_dep')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
project('foo', ['objc'])

if get_option('backend').startswith('vs')
error('MESON_SKIP_TEST: objc is not supported by vs backend')
endif

l = static_library('foo', 'foo.m')

foo_dep = declare_dependency(link_with : l)
4 changes: 4 additions & 0 deletions test cases/objc/5 objfw/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
project('objfw build tests', 'objc')

if get_option('backend').startswith('vs')
error('MESON_SKIP_TEST: objc is not supported by vs backend')
endif

objfw_dep = dependency('objfw', required: false)
objfwtest_dep = dependency('objfw', modules: ['ObjFWTest'], required: false)

Expand Down
4 changes: 4 additions & 0 deletions test cases/objcpp/1 simple/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
project('Objective C++', 'objcpp', default_options: 'cpp_std=c++14')

if get_option('backend').startswith('vs')
error('MESON_SKIP_TEST: objcpp is not supported by vs backend')
endif

exe = executable('objcppprog', 'prog.mm')
test('objcpp', exe)
4 changes: 4 additions & 0 deletions test cases/objcpp/2 objc++ args/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
project('objective c++ args', 'objcpp')

if get_option('backend').startswith('vs')
error('MESON_SKIP_TEST: objcpp is not supported by vs backend')
endif

exe = executable('prog', 'prog.mm', objcpp_args : ['-DMESON_OBJCPP_TEST'])
test('objective c++ args', exe)
4 changes: 4 additions & 0 deletions test cases/objcpp/3 objfw/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
project('objfw build tests', 'objcpp')

if get_option('backend').startswith('vs')
error('MESON_SKIP_TEST: objcpp is not supported by vs backend')
endif

objfw_dep = dependency('objfw', required: false)
objfwtest_dep = dependency('objfw', modules: ['ObjFWTest'], required: false)

Expand Down

0 comments on commit 81b151f

Please sign in to comment.