Commit Graph

145 Commits

Author SHA1 Message Date
Nirbheek Chauhan b438455ec1 Hotfix for cross-compilation from Windows to Linux
We currently pass cross-compiler options to the native compiler too and
when cross-compiling from Windows to Linux, `options` will contain
Linux-specific options which doesn't include `c_winlibs`.

The proper fix is to allow cross-info files to specify compiler options
and to maintain both cross and native compiler options in coredata, but
that will have to be done after the 0.36.0 release.

Also fixes a typo in MinGW cpp_winlibs option setting.

Closes #1029
2016-11-14 11:44:51 -05:00
Nirbheek Chauhan 085650a1e3 vala: Implement valac.find_library
Move CCompiler.compile to Compiler.compile so that ValaCompiler can use
it. Also rewrite ValaCompiler.sanity_check to use it since it does
a simple compile check.

At the same time, it enhances ExternalLibrary to support arguments for
languages other than C-like.

Includes a test for this that links against zlib through Vala.

Closes #983
2016-11-12 13:56:17 -05:00
Jussi Pakkanen 1d9c40c9c3 Merge pull request #1027 from centricular/has-header-prefix
cc.has_header: Allow specifying a prefix for headers
2016-11-12 12:16:16 -05:00
Scott D Phillips 3db969336f compilers: add werror flag for msvc 2016-11-12 11:51:59 -05:00
Nirbheek Chauhan aa5afba00b cc.has_header: Allow specifying a prefix for headers
Fixes #1026
2016-11-11 10:25:34 +05:30
Nirbheek Chauhan 88f1d400c0 Fix debug PCH builds with MSVC 2012 and later
With MSVC 2013 and newer, using pre-compiled headers with .pdb debugging
fails with the following error message:

fatal error C1041: cannot open program database '[...]\prog.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS

So we use /FS when PCH is enabled. When PCH is enabled and debugging is
disabled, this will have no effect since .pdb files will not be written.
2016-11-10 00:40:16 +05:30
Jussi Pakkanen cf7b50364f Merge pull request #1006 from centricular/cpp-has-header-symbol
A bunch of fixes for compiler checks with C++
2016-11-09 10:27:28 -05:00
Nirbheek Chauhan e90f21ae59 javac: Fail gracefully if there's no JVM
Without this, we error out with an exception if `javac` is found but
`java` isn't:

[...]
File "mesonbuild/interpreter.py", line 1759, in detect_compilers
  comp.sanity_check(self.environment.get_scratch_dir(), self.environment)
File "mesonbuild/compilers.py", line 1279, in sanity_check
  pe = subprocess.Popen(cmdlist, cwd=work_dir)
File "/usr/lib64/python3.5/subprocess.py", line 947, in __init__
  restore_signals, start_new_session)
File "/usr/lib64/python3.5/subprocess.py", line 1551, in _execute_child
  raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'java'
2016-11-09 02:37:56 +05:30
Nirbheek Chauhan 30392a3a8a Inherit VisualStudioCPPCompiler from CPPCompiler
Without this our custom C++ has_header_symbol implementation is not used
with the Visual Studio C++ compiler.
2016-11-08 23:52:01 +05:30
Nirbheek Chauhan f144e50f5c has_function: Cast to void* instead of int
Clang++ doesn't allow that, but void* will always be allowed because
lots of projects depend on that.

error: cast from pointer to smaller type 'int' loses information
2016-11-08 16:22:40 +05:30
Nirbheek Chauhan 7400284e32 has_function: Fix trivial typo
This was breaking has_function on C++
2016-11-08 16:05:32 +05:30
Nirbheek Chauhan 4d84241ccf has_header_symbol: Also detect C++ classes and templates
With the `using` keyword we can try to use the specified class or
template which will tell us if it exists.
2016-11-08 16:05:32 +05:30
Nirbheek Chauhan f6dfd36239 has_header_symbol: Make it work with C++ compilers
Need to pass -fpermissive to force C++ compilers to only warn about our
non-conformant code that tests for a symbol being defined.

Also do a simple #ifdef check first in has_header_symbol to allow
arbitrary macros to be detected which would not have been detected
earlier. This follows what AC_CHECK_DECL does.

Closes #958
2016-11-08 15:42:15 +05:30
Jussi Pakkanen 97c2321740 Merge pull request #949 from centricular/has-function-xcode8-fixes
Fix has_function with XCode 8 and related changes
2016-11-02 11:41:32 -07:00
Nirbheek Chauhan b8ef693a2a Clang also supports gnu89/99/11, gnu++03/11/14/1z
The list of supported standards is identical for GCC and Clang.

We don't list duplicate standard names however, such as c++03 and c++09

https://github.com/llvm-mirror/clang/blob/master/include/clang/Frontend/LangStandards.def
2016-10-30 06:43:49 -07:00
Nirbheek Chauhan b05d37db67 compilers: Ignore pthread flags when using MSVC
They don't make sense and just cause a build failure.
2016-10-27 10:51:26 -07:00
Nirbheek Chauhan 5ffb0bcd0d Use *FLAGS from the env in compiler checks
Every other build system does this, and at least OS X, iOS, and Android
depend on this to select the OS versions that your application is
targetting.

At the same time, just use a wrapper for self.run and self.links to
share the common (identical) code.
2016-10-26 23:16:06 +05:30
Nirbheek Chauhan 4be8e71fb3 has_function: Try to use the function being checked
Simply placing a reference to it isn't enough for the linker to try and
think it's being used and do a symbol availability check with
-Wl,-no_weak_imports on OS X ld.
2016-10-26 23:16:04 +05:30
Nirbheek Chauhan a06178f58f Add -Wl,-no_weak_imports to has_function with XCode 8
This is needed to ensure that symbol availability checks actually fail
at link time (instead of at runtime) which is necessary for has_function
to work correctly.
2016-10-25 09:44:15 +05:30
Nirbheek Chauhan ac58c13bbf has_function: Only ignore prototype when no includes are specified
The Autoconf-style check we were doing gives false positives when the
linker uses the prototype defined in the SDK header to decide whether
a function is available or not.

For example, with macOS 10.12, clock_gettime is now implemented
(alongwith other functions). These functions are always defined in the
XCode 8 SDK as weak imports and you're supposed to do a runtime check to
see if the symbols are available and use fallback code if they aren't.

The linker will always successfully link if you use one of those symbols
(without a runtime fallback) even if you target an older OS X version
with -mmacosx-version-min. This is the intended behaviour by Apple.

But this makes has_function useless because to test if the symbol is
available, we must know at link-time whether it is available.

To force the linker to do the check at link-time you must use
'-Wl,-no_weak_imports` *and* use the prototype in time.h which has an
availability macro which tells the linker whether the symbol is
available or not based on the -mmacosx-version-min flag.

An autoconf-style check would override this prototype and use its own
which would result in the linker thinking that the function is always
available (a false positive). Worse, this would manifest at runtime and
might not be picked up immediately.

We now use the function prototype in the user-provided includes if the
'prefix' kwarg contains a `#include` and use the old Autoconf-style
check if not. I've tested that the configure checks done by GStreamer
and GLib are completely unaffected by this; at least on Linux.

The next commit will also add `-Wl,-no_weak_imports` to extra_args by
default so that Meson avoids this mess completely. We always want this
because the user would not do a has_function check if they have
a runtime fallback for the function in their code.
2016-10-25 09:44:15 +05:30
Nirbheek Chauhan 02a2d69270 compilers: Derive ClangObj*Compiler from ClangCompiler too
The Clang ObjC/++ compiler is the same as the C/++ compiler.
2016-10-25 09:44:15 +05:30
Nirbheek Chauhan 9c9c5ab2a8 Implement get_default_suffix in the base Compiler class
This way every compiler has it implemented
2016-10-21 08:00:39 +05:30
Nirbheek Chauhan 4332df01b8 Add no-warning args while building Vala C code
This is done by adding a new compiler method called 'no_warn_args' which
returns the argument(s) required for the compiler to emit no warnings
for that compilation.

This take care of not disabling warnings for C code compiled into the
BuildTarget. Also includes tests for ensuring all this.

https://github.com/mesonbuild/meson/issues/864
2016-10-14 19:13:21 +05:30
Jussi Pakkanen 95a99682b0 Merge branch 'QuLogic-compiler-file-checks' 2016-10-12 23:26:30 +03:00
Jussi Pakkanen 28df8b800e Add an option to select if static libraries are built with -fPIC. 2016-10-10 21:28:28 +03:00
Jussi Pakkanen f0fee2e542 Fix soname to work on OSX. 2016-10-08 14:34:24 +02:00
Jussi Pakkanen 4dc798dc7e Check that soname matches the filename. Closes #785. 2016-10-08 07:34:39 -04:00
Nirbheek Chauhan 67c9e520de compilers: Don't pollute c_args with -fPIC on OS X
It's always enabled and the compiler just ignores all PIC-related
arguments. Relatedly, do the same thing for Clang as GCC.
2016-10-08 01:02:16 +05:30
Jussi Pakkanen 62ec92c8b0 Set soname with clang properly. 2016-10-02 12:52:16 -04:00
Jussi Pakkanen 295b67df51 Merge pull request #814 from centricular/heavy-cleanup-compilers-buildtargets
Heavy cleanup in compilers and BuildTarget
2016-09-30 15:30:57 -04:00
Elliott Sales de Andrade f2fed5052d Allow passing files to compile/link/run queries. 2016-09-29 04:44:01 -04:00
Elliott Sales de Andrade 51341ce177 Reduce redundancy in compile/link/run queries. 2016-09-29 04:43:59 -04:00
Nirbheek Chauhan a001fa0fb6 compilers: Make GCC detection more robust on all platforms
Fixes https://github.com/mesonbuild/meson/issues/650

Also adds new has_define and get_define internal API for querying
pre-processor defines provided by GNU compilers.
2016-09-27 00:27:38 +05:30
Matthew Waters 13e91ab499 Add dependency support to the checks using the compiler
It is extremely common to need to know within a given dependency if
a given header, symbol, member, function, etc exists that cannot be
determined from the version number alone.

Without passing dependency objects to the various compiler/linker
checks and with many libraries headers/libraries being located in
their own subdirs of the standard prefix, the check for the library
would not find the header/function/symbol/etc.

This commit allows passing dependency objects to the compiler checks so
that the test program can be compiled/linked/run with the necessary
compilation and/or linking flags for that library.
2016-09-26 20:25:17 +03:00
Nirbheek Chauhan 4ceaa395b5 compilers: Populate Rust and Vala compiler ids
These two have only one implementation, so just name them as they are
2016-09-26 19:48:46 +05:30
Nirbheek Chauhan b89c52e844 compilers: Remove duplicate class methods
These can just be implemented by the base Compiler class
2016-09-26 19:48:46 +05:30
Nirbheek Chauhan ece29e32a8 compilers: Consolidate language suffix mapping
Instead of spreading it across the entire file and re-implementing
can_compile for each compiler, consolidate it in one dictionary which
the base compiler class can refer to based on self.language set by the
child class.

This has fixed a number of hidden and unreported bugs due to bitrotten
can_compiler implementations.
2016-09-26 19:48:46 +05:30
Nirbheek Chauhan e8dc13248e compilers: Fix typo in visual studio warning argument 2016-09-25 09:41:07 +05:30
Nirbheek Chauhan e459fd2f53 compilers: Fall back to -pedantic with older GCC
Fixes https://github.com/mesonbuild/meson/issues/242
2016-09-25 07:53:49 +05:30
Jussi Pakkanen f1b6c89d9c Option for ndebug. 2016-09-16 21:51:29 +03:00
Jussi Pakkanen 7d24f96d2d Merge pull request #774 from mesonbuild/compilerreorg
Move compiler common functionality to own class
2016-09-14 19:12:09 +03:00
Jussi Pakkanen c334eeda76 Merge pull request #684 from mesonbuild/pdb
Create pdb files with MSVC
2016-09-11 13:04:55 +03:00
Nirbheek Chauhan 4228a6dab6 vs: Never serialize debug file generation with /FS
/FS forces .pdb file writing to be serialized through MSPDBSRV.EXE,
which is supposed to solve concurrency issues (esp. with anti-viruses),
but it doesn't actually always work. It also isn't needed anymore since
we don't use a shared vcXXX.pdb temporary file for pdb writing and use
/Fd to explicitly set a per-target pdb filename instead.

Not serializing the PDB writing will make a large difference on fast
disks when linking multiple libraries and executables simultaneously.
2016-09-11 10:10:46 +05:30
Jussi Pakkanen 873558b2b4 Reorganisation. 2016-09-10 17:41:01 +03:00
Jussi Pakkanen e57c626337 Clang C++ compiler uses common class. 2016-09-10 17:39:03 +03:00
Jussi Pakkanen 20083c0694 Factored Clang common stuff in its own class. 2016-09-10 17:19:51 +03:00
Jussi Pakkanen 26f9adf6a6 Moved base options to base class, because they are always the same. 2016-09-10 17:07:18 +03:00
Jussi Pakkanen 5833d23e76 Made objc compilers use Gnu class. 2016-09-10 17:05:20 +03:00
Jussi Pakkanen 85c2f67079 Made C++ compiler use GNU class. 2016-09-10 17:00:00 +03:00
Jussi Pakkanen 2336624f4a Refactored GNU common functionality into its own class. 2016-09-10 16:56:22 +03:00