[PATCH] LLVM 3.5 and newer use llvm-config.h instead of config.h

Signed-off-by: Niels Ole Salscheider <niels_ole@salscheider-online.de>

As far as I can tell the current llvm trunk defines both, and config.h includes llvm-config.h. Is there any particular failure you’re seeing when building libclc?

Best,

Jeroen

As far as I can tell the current llvm trunk defines both, and config.h
includes llvm-config.h. Is there any particular failure you’re seeing when
building libclc?

For me the build fails with:

./utils/prepare-builtins.cpp:13:10: fatal error: 'llvm/Config/config.h' file not
found
#include "llvm/Config/config.h"
         ^
Makefile:8: recipe for target 'utils/prepare-builtins.o' failed

The CMake-based build system does not install the config.h header anymore since
"r210766 - CMake: don't install the internal config.h header".

Kind regards,

Ole

> As far as I can tell the current llvm trunk defines both, and config.h
> includes llvm-config.h. Is there any particular failure you’re seeing when
> building libclc?

For me the build fails with:

./utils/prepare-builtins.cpp:13:10: fatal error: 'llvm/Config/config.h' file not
found
#include "llvm/Config/config.h"
         ^
Makefile:8: recipe for target 'utils/prepare-builtins.o' failed

The CMake-based build system does not install the config.h header anymore since
"r210766 - CMake: don't install the internal config.h header".

ra itno this failure too when I did a clean build.

Kind regards,

Ole

> Best,
>
> Jeroen
>
> > Signed-off-by: Niels Ole Salscheider <niels_ole@salscheider-online.de>
> > ---
> > configure.py | 3 +++
> > utils/prepare-builtins.cpp | 5 +++++
> > 2 files changed, 8 insertions(+)
> >
> > diff --git a/configure.py b/configure.py
> > index 768a6ad..f28c847 100755
> > --- a/configure.py
> > +++ b/configure.py
> > @@ -73,6 +73,9 @@ llvm_core_libs = llvm_config(['--libs', 'core',
> > 'bitreader', 'bitwriter']) + ' '>
> > llvm_config(['--ldflags'])
> >
> > llvm_cxxflags = llvm_config(['--cxxflags']) + ' -fno-exceptions -fno-rtti'
> >
> > +if (int(llvm_version[0]) == 3 and int(llvm_version[1]) >= 5) or
> > int(llvm_version[0]) > 3: + llvm_cxxflags = llvm_cxxflags + '
> > -DLLVM_NEW_CONFIG_INCLUDE'
> > +
> > llvm_clang = os.path.join(llvm_bindir, 'clang')
> > llvm_link = os.path.join(llvm_bindir, 'llvm-link')
> > llvm_opt = os.path.join(llvm_bindir, 'opt')
> > diff --git a/utils/prepare-builtins.cpp b/utils/prepare-builtins.cpp
> > index ce84148..20fcd1b 100644
> > --- a/utils/prepare-builtins.cpp
> > +++ b/utils/prepare-builtins.cpp
> > @@ -10,7 +10,12 @@
> > #include "llvm/Support/raw_ostream.h"
> > #include "llvm/Support/ErrorOr.h"
> > #include "llvm/Support/ToolOutputFile.h"
> > +
> > +#ifdef LLVM_NEW_CONFIG_INCLUDE
> > +#include "llvm/Config/llvm-config.h"
> > +#else
> > #include "llvm/Config/config.h"
> > +#endif

The conditional define for llvm 3.5+ is few lines down, and it already
handles few includes. config.h could be handled the same way and you
don't need the configure.py changes.

0001-Fix-build-since-r210766.patch (1.04 KB)

> > As far as I can tell the current llvm trunk defines both, and config.h
> > includes llvm-config.h. Is there any particular failure you’re seeing
> > when
> > building libclc?
>
> For me the build fails with:
>
> ./utils/prepare-builtins.cpp:13:10: fatal error: 'llvm/Config/config.h'
> file not found
> #include "llvm/Config/config.h"
>
> ^
>
> Makefile:8: recipe for target 'utils/prepare-builtins.o' failed
>
> The CMake-based build system does not install the config.h header anymore
> since "r210766 - CMake: don't install the internal config.h header".

ra itno this failure too when I did a clean build.

> Kind regards,
>
> Ole
>
> > Best,
> >
> > Jeroen
> >
> > > Signed-off-by: Niels Ole Salscheider <niels_ole@salscheider-online.de>
> > > ---
> > > configure.py | 3 +++
> > > utils/prepare-builtins.cpp | 5 +++++
> > > 2 files changed, 8 insertions(+)
> > >
> > > diff --git a/configure.py b/configure.py
> > > index 768a6ad..f28c847 100755
> > > --- a/configure.py
> > > +++ b/configure.py
> > > @@ -73,6 +73,9 @@ llvm_core_libs = llvm_config(['--libs', 'core',
> > > 'bitreader', 'bitwriter']) + ' '>
> > >
> > > llvm_config(['--ldflags'])
> > >
> > > llvm_cxxflags = llvm_config(['--cxxflags']) + ' -fno-exceptions
> > > -fno-rtti'
> > >
> > > +if (int(llvm_version[0]) == 3 and int(llvm_version[1]) >= 5) or
> > > int(llvm_version[0]) > 3: + llvm_cxxflags = llvm_cxxflags + '
> > > -DLLVM_NEW_CONFIG_INCLUDE'
> > > +
> > > llvm_clang = os.path.join(llvm_bindir, 'clang')
> > > llvm_link = os.path.join(llvm_bindir, 'llvm-link')
> > > llvm_opt = os.path.join(llvm_bindir, 'opt')
> > > diff --git a/utils/prepare-builtins.cpp b/utils/prepare-builtins.cpp
> > > index ce84148..20fcd1b 100644
> > > --- a/utils/prepare-builtins.cpp
> > > +++ b/utils/prepare-builtins.cpp
> > > @@ -10,7 +10,12 @@
> > > #include "llvm/Support/raw_ostream.h"
> > > #include "llvm/Support/ErrorOr.h"
> > > #include "llvm/Support/ToolOutputFile.h"
> > > +
> > > +#ifdef LLVM_NEW_CONFIG_INCLUDE
> > > +#include "llvm/Config/llvm-config.h"
> > > +#else
> > > #include "llvm/Config/config.h"
> > > +#endif

The conditional define for llvm 3.5+ is few lines down, and it already
handles few includes. config.h could be handled the same way and you
don't need the configure.py changes.

Unfortunately, this won't work because LLVM_VERSION_MAJOR and
LLVM_VERSION_MINOR are defined in config.h and llvm-config.h, respectively...

At least I understand now why I’m not seeing this error: I build against my llvm build directory, not against an installed version. The file still occurs in the build dir.

If I’m not mistaken this file is only included to get the version number, and in llvm 3.4 this already occurs in llvm-config.h. So just a simple replacement in prepare-builtins.cpp might do (unless llvm 3.3 doesn’t have it and that's still supported).

Jeroen

At least I understand now why I’m not seeing this error: I build against my
llvm build directory, not against an installed version. The file still
occurs in the build dir.

If I’m not mistaken this file is only included to get the version number,
and in llvm 3.4 this already occurs in llvm-config.h. So just a simple
replacement in prepare-builtins.cpp might do (unless llvm 3.3 doesn’t have
it and that's still supported).

LLVM 3.3 seems to have it, too. I will send a new patch.

Ole

Signed-off-by: Niels Ole Salscheider <niels_ole@salscheider-online.de>

Signed-off-by: Niels Ole Salscheider <niels_ole@salscheider-online.de>

you were right we can't use the macros defined in the header in order to
include it :slight_smile:
I checked that llvm-config.h is distributed in 3.3/4/5 and contains the
version info.
this patch looks good to me.