Commit Graph

132 Commits

Author SHA1 Message Date
Nirbheek Chauhan 50b863032e find_library: Check arch of libraries on Darwin
macOS provides the tool `lipo` to check the archs supported by an
object (executable, static library, dylib, etc). This is especially
useful for fat archives, but it also helps with thin archives.

Without this, the linker will fail to link to the library we mistakenly
'found' like so:

ld: warning: ignoring file /path/to/libfoo.a, missing required architecture armv7 in file /path/to/libfoo.a
2019-01-31 20:36:49 +00:00
Nirbheek Chauhan c0166355ce Rewrite appleframework and extraframework dependency classes
Instead of only doing a naive filesystem search, also run the linker
so that it can tell us whether the -F path specified actually contains
the framework we're looking for.

Unfortunately, `extraframework` searching is still not 100% correct in
the case when since we want to search in either /Library/Frameworks or
in /System/Library/Frameworks but not in both. The -Z flag disables
searching in those prefixes and would in theory allow this, but then
you cannot force the linker to look in those by manually adding -F
args, so that doesn't work.
2019-02-01 00:14:09 +05:30
Michael Hirsch, Ph.D 8636f31d9c BUGFIX: broken/missing Fortran code/unit tests 2019-01-27 20:57:21 +02:00
Michael Hirsch, Ph.D 72486afd08 Add PGI C and C++ compilers (#4803) 2019-01-21 20:09:36 +02:00
Phillip Cao 13fe2e40eb Add get_werror_args for CCRX C compiler 2019-01-10 22:56:47 +02:00
Daniel Mensinger 9742927903
Absolute path generation refactoring 2019-01-06 12:19:32 +01:00
John Ericson 2b22576fb6 Remove cross_info; cross file is parsed up front and discarded 2019-01-02 16:22:47 -05:00
Jon Turney a872b925ea
Store the target architecture for CL-like compilers
Store the MSVC compiler target architecture ('x86', 'x64' or 'ARM' (this
is ARM64, I believe)), rather than just if it's x64 or not.

The regex used for target architecture should be ok, based on this list
of [1] version outputs, but we assume x86 if no match, for safety's
sake.

[1] https://stackoverflow.com/a/1233332/1951600

Also detect arch even if cl outputs version to stdout.

Ditto for clang-cl

Future work: is_64 is now only used in get_instruction_set_args()
2018-12-06 13:25:16 +00:00
Jussi Pakkanen 2c91ca3d6a Remove linkerlike args from compile checks. Closes #4542. 2018-11-27 22:17:38 +02:00
Jon Turney a33acd31da Fix flake8 'imported but unused' reports
$ flake8 | grep F401
./run_unittests.py:43:1: F401 'mesonbuild.mesonlib.is_linux' imported but unused
./mesonbuild/compilers/c.py:32:1: F401 '.compilers.CompilerType' imported but unused
./mesonbuild/compilers/cpp.py:23:1: F401 '.compilers.CompilerType' imported but unused
2018-11-19 21:07:37 +02:00
Dylan Baker 0092a7d3f9
Merge pull request #4359 from dcbaker/icc-fixes
ICC fixes for Linux and MacOS
2018-11-17 06:57:07 -08:00
Jussi Pakkanen aa20c91e6e Guard against broken lib paths returned by gcc. 2018-11-17 16:26:02 +02:00
Dylan Baker 842d8556ec compilers: quiet ICC messages about pch
These are useful for debugging, but not interesting for end users, where
it just adds lines between ninja jobs without adding value.
2018-11-15 19:07:28 -08:00
Dylan Baker 9f9cfd2139 compilers: Move get_allow_undefined_link_args to Compiler
This allows each implementation (gnu-like) and msvc to be implemented in
their respective classes rather than through an if tree in the CCompiler
class. This is cleaner abstraction and allows us to clean up the Fortran
compiler, which was calling CCompiler bound methods without an instance.
2018-11-15 18:42:25 -08:00
Dylan Baker 315d07d306 compilers: Set the correct values for undefined modules on apple with icc 2018-11-15 18:42:25 -08:00
Dylan Baker 3ab9620180 compilers: Add ICC setting for get_allow_undefined_link_args 2018-11-15 18:42:25 -08:00
Dylan Baker 28fd725d61 compilers: fix compiler.compile for Intel Compilers
has_arguments is the wrong thing to fix, since all checks that require
compiler options are based on compiles, it's the right thing to modify.
2018-11-15 18:42:25 -08:00
Jussi Pakkanen 6a2dc7576e Store unexpanded library directory paths. Closes #4392. 2018-11-15 21:10:16 +02:00
Dylan Baker de175aac00 compilers: Use keyword only arguments for compiler interfaces
Because we need to inherit them in some cases, and python's
keyword-or-positional arguments make this really painful, especially
with inheritance. They do this in two ways:

1) If you want to intercept the arguments you need to check for both a
   keyword and a positional argument, because you could get either. Then
   you need to make sure that you only pass one of those down to the
   next layer.

2) After you do that, if the layer below you decides to do the same
   thing, but uses the other form (you used keyword by the lower level
   uses positional or vice versa), then you'll get a TypeError since two
   layers down got the argument as both a positional and a keyword.

All of this is bad. Fortunately python 3.x provides a mechanism to solve
this, keyword only arguments. These arguments cannot be based
positionally, the interpreter will give us an error in that case.

I have made a best effort to do this correctly, and I've verified it
with GCC, Clang, ICC, and MSVC, but there are other compilers like Arm
and Elbrus that I don't have access to.
2018-11-13 00:40:13 +02:00
Phillip Cao 68c83cb213 Add support for Renesas CC-RX toolchain 2018-11-08 00:02:22 +13:00
Jon Turney c789efb8c8
Use lld-link with clang-cl
Use lld-link dynamic linker with clang-cl
Don't hardcode dynamic linker name in tests
2018-11-04 15:42:06 +00:00
Jon Turney a025c98d30
Qualify checks of self.version by self.id in VisualStudioC/CPPCompiler 2018-11-04 15:42:06 +00:00
Jon Turney e820c66a4c
Teach VisualStudioCCompiler.get_pch_use_args() to handle clang-cl
It seems that clang-cl isn't quite compatible with cl in the way it handles
pch, and when the precompiled header is used, the pathname of the header is
needed, not just its filename.

This fixes test\common\13 pch with clang-cl
2018-11-04 15:42:06 +00:00
Jon Turney b5b7e5b94a
Teach VisualStudioCCompiler.has_arguments() about clang-cl
When invoked as clang-cl to compile, it doesn't emit cl-compatible D9002
warnings about unknown options, but fortunately also supports
-Werror-unknown-argument instead.

When invoked to link, and using LINK, it does emit cl-compatible LNK4044
warnings about unknown options.
2018-11-04 15:42:06 +00:00
Jon Turney bb31a8c1c7
Only add link arguments when needed in Compiler object methods
Currently, ComplierHolder.determine_args() unconditionally adds the link
arguments to the commmand, even if we aren't linking, because it doesn't
have access to the mode (preprocess, compile, link) that
_get_compiler_check_args() will use.

This leads to command lines like:

'cl testfile.c /nologo /showIncludes /c /Fooutput.obj /Od kernel32.lib
user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib
uuid.lib comdlg32.lib advapi32.lib'

which clang-cl considers invalid; MSVS cl accepts this, ignoring the
unneeded libraries

Change from passing extra_args down to _get_compiler_check_args(), to
passing down a callback to CompilerHolder.determine_args() (with a bound
kwargs argument), so it can consult mode and kwargs to determine the args to
use.
2018-11-04 15:42:06 +00:00
Jon Turney 64edfd5069
Detect clang-cl as msvc-like, not clang-like
Handle clang's cl or clang-cl being in PATH, or set in CC/CXX

Future work: checking the name of the executable here seems like a bad idea.
These compilers will fail to be detected if they are renamed.

v2:
Update compiler.get_argument_type() test
Fix comparisons of id inside CCompiler, backends and elsewhere

v3:
ClangClCPPCompiler should be a subclass of ClangClCCompier, as well

Future work: mocking in test_find_library_patterns() is effected, as we
now test for a subclass, rather than self.id in CCompiler.get_library_naming()
2018-11-04 15:42:00 +00:00
Dylan Baker 63f4f9481e Add new compiler.get_argument_syntax method
Some compilers try very had to pretend they're another compiler (ICC
pretends to be GCC and Linux and MacOS, and MSVC on windows), Clang
behaves much like GCC, but now also has clang-cl, which behaves like MSVC.

This method provides an easy way to determine whether testing for MSVC
like arguments `/w1234` or gcc like arguments `-Wfoo` are likely to
succeed, without having to check for dozens of compilers and the host
operating system, (as you would otherwise have to do with ICC).
2018-11-03 18:10:36 +02:00
Josh Gao edda80cc75 Generalize gnulike-targeting-windows checks.
Replace several checks against GCC_MINGW or (GCC_MINGW, GCC_CYGWIN) with
is_windows_compiler instead, so that clang and other gcc-like compilers
using MinGW work appropriately with vs_module_defs, c_winlibs, and
cpp_winlibs.

Fixes #4434.
2018-10-30 20:25:32 +02:00
Marvin Scholz 2256e6314b compilers/c: Fix allow undefined link arg for PE/COFF
For PE/COFF it is not possible to allow undefined symbols, so do not
try to use the option to do so.

While gcc ld silently ignores it, this is not the case for the llvm
linker.

Fix #4415
2018-10-25 19:30:42 +03:00
David Seifert a28eddb822 Use relative build-tree RPATHs on macOS
* This helps with reproducibility on macOS in the same way
  `$ORIGIN` improves reproducibility on Linux-like systems.
* This makes the build-tree more resilient to users injecting
  rpaths via `LDFLAGS`. Currently Meson on macOS crashes when
  a build-tree rpath and a user-provided `-Wl,-rpath` in
  LDFLAGS collide, leading to `install_name_tool` failures.
  While this still does not solve the root cause, it makes
  the occurrence much less likely, as users will generally
  pass absolute `-Wl,-rpath` arguments into Meson.
2018-10-14 23:56:59 +03:00
gsobala 0ea626b89d Added .so to list possible darwin dynamic library suffixes (#4364)
Occasionally Darwin libraries can be .so rather than .dylib e.g. tensorflow_cc.so
tensorflow_cc is a c++ API for Tensorflow (https://github.com/FloopCZ/tensorflow_cc)
which was primarily written for Linux but is also compilable on Darwin. Possibly
through laziness, possibly just to have consistent filenames, the developers did not
opt to change the suffix from the Linux default when this is compiled on Darwin.

Also, the Darwin linker will find libraries with a .so suffix if they are
in its path. find_library() needs to match the linker behaviour.
2018-10-13 07:00:06 -07:00
Mohammed Amer Khalidi 18204b8ed6 Adding "compiler_type" flag to ARM compilers. 2018-10-07 19:21:26 +03:00
Bruce Richardson 386e5b876f Verify library directories as either 32-bit or 64-bit
In get_library_dirs() we are trusting the compiler to return a correct
list of directories to search for libraries, based on whether or not
we are compiling 64-bit or 32-bit. Unfortunately, this is often not the
case, as 64-bit libraries often are returned when compiling with -m32 on
a 64-bit OS.

Since system directories do not contain a mix of libraries, the solution
here is to check each directory, by picking a .so file in the directory
and checking whether its 64-bit or 32-bit. If we can't determine if we
want 32-bit or 64-bit, just skip the checks and assume the directory is
good.
2018-10-03 01:01:10 +03:00
Dylan Baker 6cf7d2492b compilers/c: don't return -pthread for MacOS with any compiler
With GCC, Clang, or ICC, and for C++

Fixes #2628
2018-10-01 12:34:46 -07:00
Marvin Scholz 843b0b1d50 compilers: Do not use -pthread with clang for darwin
Using the -pthread argument is not needed with clang when compiling for
darwin, and it results in the warning:

  warning: argument unused during compilation: '-pthread'
2018-09-28 12:54:10 -07:00
Martin Storsjö 48b6520764 Don't add rpath linker flags when building for MinGW
GNU binutils ld silently ignores -rpath flags when targeting windows
(and it is already commented within ninjabackend.py that rpath as
concept doesn't exist on windows), and build_rpath_args in
VisualStudioCCompiler also returns an empty array. Therefore skip
this flag altogether.

This fixes linking with lld in MinGW mode, which doesn't support the
rpath flag.
2018-09-25 02:43:19 +03:00
David Seifert 115962e466 Abstract shared GCC/Clang/ICC methods in GnuLikeCompiler 2018-09-17 23:31:55 +03:00
David Seifert 8f16d0f3c9 Fix ICC on macOS 2018-09-16 18:27:19 +03:00
David Seifert 0e89b03be6 Do not use relative RPATHs on macOS with ICC/GCC
* Currently, absolute rpaths on macOS are only used
  with Clang, which breaks Meson builds when using
  ICC or GCC from Homebrew or MacPorts.
2018-09-16 00:47:32 +03:00
David Seifert 69ec001b06 Use enum instead of `int` for compiler variants
* Enums are strongly typed and make the whole
  `gcc_type`/`clang_type`/`icc_type` distinction
  redundant.
* Enums also allow extending via member functions,
  which makes the code more generalisable.
2018-09-16 00:47:32 +03:00
Nirbheek Chauhan 1af704a509 Sprinkle functools.lru_cache() in a few more places
This improves the backend generation time for gst-build from 7.4s to
6.6s. This is probably all the low-hanging fruit we can get, further
improvements will probably require refactoring, moving to pathlib.Path
or reimplementing CompilerArgs:

   222045    0.551    0.000    1.324    0.000 compilers.py:666(__iadd__)
     3691    0.230    0.000    0.885    0.000 ninjabackend.py:99(write)
   233560    0.441    0.000    0.701    0.000 posixpath.py:75(join)
      882    0.141    0.000    0.636    0.001 backends.py:509(generate_basic_compiler_args)
   256301    0.248    0.000    0.576    0.000 compilers.py:562(_can_dedup)
    37369    0.035    0.000    0.466    0.000 compilers.py:652(extend_direct)
    74650    0.067    0.000    0.431    0.000 compilers.py:641(append_direct)
   158153    0.089    0.000    0.405    0.000 ninjabackend.py:129(<lambda>)
      845    0.064    0.000    0.391    0.000 ninjabackend.py:279(get_target_generated_sources)
    58161    0.070    0.000    0.317    0.000 backends.py:217(get_target_generated_dir)
   216825    0.175    0.000    0.275    0.000 ninjabackend.py:48(ninja_quote)
      845    0.058    0.000    0.255    0.000 ninjabackend.py:2289(guess_external_link_dependencies)
      845    0.068    0.000    0.239    0.000 backends.py:793(get_custom_target_provided_libraries)
    52101    0.030    0.000    0.237    0.000 compilers.py:716(append)
  1319326    0.231    0.000    0.231    0.000 {built-in method builtins.isinstance}
  1189117    0.229    0.000    0.229    0.000 {method 'startswith' of 'str' objects}
     3235    0.102    0.000    0.228    0.000 compilers.py:614(to_native)

Note: there are 845 build targets.
2018-09-11 10:19:42 -07:00
Dylan Baker 51e9db370a Add method to check for C/C++ function attributes
It's fairly common on Linux and *BSD platforms to check for these
attributes existence, so it makes sense to me to have this checking
build into meson itself. Autotools also has a builtin for handling
these, and by building them in we can short circuit cases that we know
that these don't exist (MSVC).

Additionally this adds support for two common MSVC __declspec
attributes, dllimport and dllexport. This implements the declspec
version (even though GCC has an __attribute__ version that both it and
clang support), since GCC and Clang support the MSVC version as well.
Thus it seems reasonable to assume that most projects will use the
__declspec version over teh __attribute__ version.
2018-09-07 11:52:15 -07:00
Ole André Vadla Ravnås 6cd71a8033 compilers: Reduce sizes of MSVC linked binaries
- For optimization=s add /O1: Use Maximum Optimization (Favor Size),
  and remove /Os as it's implied by /O1.
- Because we add /O1, this implies /Gy, i.e. Function-Level Linking, so
  unused code can be omitted.
- Add /Gw: Optimize Global Data, so unused data can be omitted.

With buildtype=minsize on x86 this reduces the size of a statically
linked Vala compiler binary from 5 MB down to just 1.87 MB.
2018-08-22 22:58:13 +03:00
Nirbheek Chauhan bb5f2ca3da find_library: Allow undefined symbols while linking
Shared libraries may not always be linkable without the use of other
libraries, so don't make it a linker error.
2018-08-22 12:24:43 -07:00
Bruce Richardson 8c9296e8e6 find_library: Use _build_wrapper to get library dirs
This means that we will take into account all the flags set in the
cross file when fetching the list of library dirs, which means we
won't incorrectly look for 64-bit libraries when building for 32-bit.

Signed-off-by: Nirbheek Chauhan <nirbheek@centricular.com>

Closes https://github.com/mesonbuild/meson/issues/3881
2018-08-22 12:24:43 -07:00
Jussi Pakkanen d83f77109a
Convert buildtype to optimization and debug options (#3489) 2018-08-18 20:39:47 +03:00
Jon Turney 94f09a8454 Explicitly set the Windows subsystem for ninja/VisualC 2018-08-15 06:17:58 -07:00
Nirbheek Chauhan ae5ebd258f PkgConfigDependency: Don't try to resolve internal compiler libs
-lc -lm -ldl -lrt -lpthread are special linker arguments that should
never be resolved to on-disk libraries.

Closes https://github.com/mesonbuild/meson/issues/3879
2018-08-11 04:16:18 -07:00
Nirbheek Chauhan 475efb9354 msvc: Don't add dynamic link args, they're ignored
And they print a linker warning about unknown args.
2018-08-09 18:39:19 +03:00
Nirbheek Chauhan 6c8f81333a PkgConfigDependency: Fix library path search order
We were searching the library paths in the reverse order, which meant
that we'd pick libraries from the wrong prefix.

Closes https://github.com/mesonbuild/meson/issues/3951
2018-08-08 05:45:45 -07:00