Building LLVM with cmake. Does -D_GLIBCXX_USE_CXX11_ABI=0 get overridden? - cmake

I try to build LLVM.
This is the way I try …
mkdir -p src/llvm-$(LLVM_VERSION).src/build
cd src/llvm-$(LLVM_VERSION).src/build && \
$(CMAKE) -GNinja \
-DCMAKE_INSTALL_PREFIX=$(BUNDLE) \
-DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 -static-libgcc -static-libstdc++ -l:libstdc++.a" \
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX" \
-DLLVM_PARALLEL_COMPILE_JOBS=$(BUILD_JOBS) \
-DLLVM_PARALLEL_LINK_JOBS=2 \
-DLLVM_USE_CRT_RELEASE=MD \
-DLLVM_USE_CRT_DEBUG=MDd \
-DLLVM_STATIC=ON \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_BUILD_LLVM_C_DYLIB=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_UNWIND_TABLES=OFF \
-DLLVM_ENABLE_RTTI=ON \
.. && \
$(CMAKE) --build . && \
$(CMAKE) --build . --target install
You can see -D_GLIBCXX_USE_CXX11_ABI=0 in -DCMAKE_CXX_FLAGS. After LLVM finished compiling, libLLVM*.a still contain abi:cxx11 symbols.
llvm-config reveals, llvm build process completely ignored "-D_GLIBCXX_USE_CXX11_ABI=0" flag.
> ./bundle/bin/llvm-config --cxxflags
-I/home/leonard/Documents/Develop/build_as_deps/bundle/include -std=c++11 -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
Do you have an idea how to build llvm in a way that disables abi:cxx11 symbols and prevents "-D_GLIBCXX_USE_CXX11_ABI=0" to be overridden?

It looks like you're confusing the cmake options (which are specified with via -D) with C/C++ compiler macro (which are also specified via -D, but to compiler). cmake happily ignored your -D_GLIBCXX_USE_CXX11_ABI, because it's not a cmake option (and you should see a warning about this, that the value is unused by the build system).
Since you need to add extra macro definition, you'd need to change CMAKE_CXX_FLAGS cmake variable.

Related

CPPFLAGS set from configure.ac are ignored in Makefile.am

I am trying to build TerraGear with self-made AutoTools files (configure script). TerraGear is split into several subprojects. For each, I create a different set of configure.ac and Makefile.am files, but they are all almost the same.
Consider the following two files:
configure.ac
AC_PREREQ([2.69])
AC_INIT([TerraGear libterragear], [2.1.0], [])
AC_CONFIG_SRCDIR([airport.cxx])
AC_CONFIG_FILES([Makefile])
AM_INIT_AUTOMAKE([foreign])
AC_PROG_CXX
PKG_CHECK_MODULES([ZLIB], [zlib])
PKG_CHECK_MODULES([GDAL], [gdal])
AC_ARG_WITH([simgear-dir], [AS_HELP_STRING(
[--with-simgear-dir=prefix],
[installation prefix of SimGear])],
[
SIMGEAR_CPPFLAGS="-I${withval}/include"
SIMGEAR_LIBRARY="-L${withval}/lib"
]
)
AC_MSG_NOTICE([simgear cppflags : ${SIMGEAR_CPPFLAGS}])
AC_OUTPUT
Makefile.am
bin_PROGRAMS = genapts850
genapts850_SOURCES = airport.cxx \
apt_math.cxx \
closedpoly.cxx \
debug.cxx \
elevations.cxx \
helipad.cxx \
lights.cxx \
linearfeature.cxx \
linked_objects.cxx \
main.cxx \
object.cxx \
output.cxx \
parser.cxx \
runway.cxx \
rwy_simple.cxx \
rwy_gen.cxx \
scheduler.cxx \
taxiway.cxx
genapts850_LDADD = -L$(top_srcdir)/../../Lib/terragear \
$(SIMGEAR_LIBRARY) \
-lSimGearCore \
-lSimGearScene \
-lterragear \
$(ZLIB_LIBRARY) \
$(GDAL_LIBRARY)
genapts850_CXXFLAGS = -I$(top_srcdir)/../../Lib \
-I$(top_srcdir)/../../Lib/terragear \
$(SIMGEAR_CPPFLAGS) \
$(ZLIB_CFLAGS) \
$(GDAL_CFLAGS)/gdal
I run autoreconf:
autoreconf -vfi
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
autoreconf: configure.ac: not using Autoheader
autoreconf: running: automake --add-missing --copy --force-missing
autoreconf: Leaving directory `.'
then run the configure script:
./configure --with-simgear-dir=/path/to/simgear/installation/prefix
[...]
configure: simgear cppflags : -I/path/to/simgear/installation/prefix/include
[...]
then I run make:
make
g++ -DPACKAGE_NAME=\"TerraGear\ libterragear\" -DPACKAGE_TARNAME=\"terragear-libterragear\" -DPACKAGE_VERSION=\"2.1.0\" -DPACKAGE_STRING=\"TerraGear\ libterragear\ 2.1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"terragear-libterragear\" -DVERSION=\"2.1.0\" -I. -I./../../Lib -I./../../Lib/terragear -Ig++ -DPACKAGE_NAME=\"TerraGear\ libterragear\" -DPACKAGE_TARNAME=\"terragear-libterragear\" -DPACKAGE_VERSION=\"2.1.0\" -DPACKAGE_STRING=\"TerraGear\ libterragear\ 2.1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"terragear-libterragear\" -DVERSION=\"2.1.0\" -I. -I./../../Lib -I./../../Lib/terragear -I/path/to/simgear/installation/prefix/include/gdal -g -O2 -MT genapts850-airport.o -MD -MP -MF .deps/genapts850-airport.Tpo -c -o genapts850-airport.o `test -f 'airport.cxx' || echo './'`airport.cxx
airport.cxx:6:10: fatal error: simgear/compiler.h: Datei oder Verzeichnis nicht gefunden
6 | #include <simgear/compiler.h>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:471: genapts850-airport.o] Fehler 1
(simgear/compiler.h resides inside /path/to/simgear/installation/prefix/include)
What am I doing wrong ? I'm banging my head into the screen for three hours now without being able to figure out the problem. Please help …
Not all shell variables defined in configure are forwarded to output files. Generally speaking, you need to use AC_SUBST() to tell Autoconf that a shell variable should be an output variable:
AC_SUBST([SIMGEAR_CPPFLAGS])
AC_SUBST([SIMGEAR_LIBRARY])

LLVM ERROR: Cannot select: intrinsic %llvm.objc.clang.arc.use

I'm getting the next error with llc when trying to to link some IR files:
LLVM ERROR: Cannot select: intrinsic %llvm.objc.clang.arc.use
I discovered that if I disabled clang optimization (O0) during compilation the error doesn't pop up, but I don't want to do that
I attach a sample of how to reproduce it, just cd the 'issue' folder and run the 'issue.sh' to reproduce the error. You must have Xcode (12.x preferred) tu run it
https://drive.google.com/file/d/1j0TvMZI2A7QxRbv_Q7aydtlNYaiTPYBm/view?usp=sharing
This is what the issue.sh contains, that is a reduced version of my real implementation:
echo "clang..."
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c \
-target arm64-apple-ios12.0 \
-fobjc-arc -fmodules \
-S -Os -flto=thin \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.1.sdk \
-fembed-bitcode \
-c ${PWD}/GTMSessionFetcher.m \
-o ${PWD}/GTMSessionFetcher.ll
echo "llc..."
${PWD}/llc \
GTMSessionFetcher.ll \
-stats -filetype=obj \
-code-model=small \
-enable-machine-outliner=never \
--mtriple=arm64-apple-ios12.0 \
-o ${PWD}/GTMSessionFetcher.o
As I mentioned before, if you change -Os for -O0, the error disappears, but I do need the size optimization.
The objective-c file that I included is a file from a pod from a Google library
https://github.com/google/gtm-session-fetcher
I found a similar question, but it doesn't have any answer yet
LLVM Error Cannot select intrinsic %llvm.coro.begin
I thought it was bug, but it wasn't
As Akira pointed me in LLVM bug report I was able to fix it by adding an intermediate optimizer OPT step with -objc-arc-contract flag:
clang
...
<path to your LLVM tools>/OPT \
<Your IR file> \
-objc-arc-contract \
-o <Output file>
llc
...

pgf77 vs pgf90 to compile software

I'm compiling a software (to convert ASCII to BIN) in LINUX, using PGI 2019 community version.
The Makefile use pgf77 which not included in the PGI compiler I have in my system, so I have to change to pgf90. However, I faced to an error:
pgf90 -vms -c -O -Mbyteswapio simcon.f
pgf90-Error-Unknown switch: -vms
make: *** [simcon.o] Error 1
I think the -vms is not recognized by pgf90. So what flag should I use here instead?
The MAKEFILE like this:
FCFLGS = -O -Mbyteswapio
OBJCTS = \
aircon.o \
airconv.o \
avgcon.o \
avgcns.o \
bndcon.o \
checon.o \
dfbcon.o \
emicon.o \
metcon.o \
ptscon.o \
regcon.o \
simcon.o \
tercon.o \
tmpcon.o \
tmpcn3.o \
tpccon.o \
wndcon.o
airconv: $(OBJCTS)
pgf77 -o airconv $(FCFLGS) $(OBJCTS)
.f.o:
pgf77 -c $(FCFLGS) $<
simcon.o: simcon.f
pgf77 -vms -c $(FCFLGS) simcon.f
Thank you very much.
Ha Chi
pgf77 was in the process of being deprecated with the PGI 2019 compilers. It's still there, but only included under the older non-LLVM versions of compilers (i.e. "$PGI/linux86-64-nollvm/19.xx/bin" directory). Though it would be best to move to the newer pgfortran driver (pgf90 works as well).
The "-vms" flag enabled very old VAX/VMS extensions that have been superseded by Fortran standard routines or other extensions. As you note, the code compiles without the flag, so either the code doesn't actually use these extensions or it can use the 3F version of the extensions.

Is there a cmake option to specify an out of source binary directory? [duplicate]

This question already has an answer here:
How to tell CMake where to put build files?
(1 answer)
Closed 4 years ago.
I'm trying to build MySQL from source but I hit a configuration error:
CMake Error at CMakeLists.txt:283 (MESSAGE):
Please do not build in-source. Out-of source builds are highly
recommended: you can have multiple builds for the same source, and there is
an easy way to do cleanup, simply remove the build directory (note that
'make clean' or 'make distclean' does *not* work)
You *can* force in-source build by invoking cmake with
-DFORCE_INSOURCE_BUILD=1
-- Source directory /usr/local/mysql-source
-- Binary directory /usr/local/mysql-source
-- Configuring incomplete, errors occurred!
See also "/usr/local/mysql-source/CMakeFiles/CMakeOutput.log".
The command '/bin/sh -c cd /usr/local/mysql-source/ && cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/install -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITHOUT_TOKUDB=1 -DMYSQL_DATADIR=/usr/local/mysql/install/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/mysql/install/boost -DMYSQL_UNIX_ADDR=/usr/local/mysql/install/tmp/mysql.sock' returned a non-zero code: 1
I thought the CMAKE_INSTALL_PREFIX option was supposed to do exactly that, that is, specify the binary installation directory.
Here are my build commands:
RUN apt-get install -y libncurses-dev
COPY mysql-8.0.15.tar.gz /usr/local/
WORKDIR /usr/local
RUN gzip -d mysql-8.0.15.tar.gz \
&& tar -xvf mysql-8.0.15.tar \
&& mv mysql-8.0.15 mysql-source
RUN mkdir mysql
WORKDIR /usr/local/mysql/
RUN mkdir install \
&& mkdir install/data \
&& mkdir install/var \
&& mkdir install/etc \
&& mkdir install/tmp
RUN cd /usr/local/mysql-source/ \
&& cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/install \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITHOUT_TOKUDB=1 \
-DMYSQL_DATADIR=/usr/local/mysql/install/data \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/mysql/install/boost \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/install/tmp/mysql.sock \
&& make \
&& make install \
&& make clean
I read other similar questions but none explained why this CMAKE_INSTALL_PREFIX option was not doing it, nor if there was any other option.
I'm hoping not to have to edit the Makefile as I'm in a Docker environment.
I tried adding the -DDESTDIR=/usr/local/mysql/install \ option but the issue remained the exact same.
The cmake documentation didn't help me.
UPDATE: Following the provided solution I could successfully build with the command:
WORKDIR /usr/local/mysql/
RUN cmake -- -j4 \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/install \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITHOUT_TOKUDB=1 \
-DMYSQL_DATADIR=/usr/local/mysql/install/data \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/mysql/install/boost \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/install/tmp/mysql.sock \
/usr/local/mysql-source/ \
&& make \
&& make install \
&& make clean
with the -- -j4 option being optional here, as it only tells cmake to use the 4 cores of the computer.
CMake is complaining about the fact you are trying to build MySQL in the source tree and therefore tainting it. A typical scenario is to use a separate builddir (that might be located under the source dir, but not necessarily need to). CMAKE_INSTALL_PREFIX is the place where after a successful build the binaries are installed to.
Create your solutions with
cmake -Hsourcedir -Bbuilddir ....<all your options>
CMake will create the builddir if it does not exist. In your case this could be called from the current source dir with
cmake -H. -Bbuilddir ....<all your options>
Newer CMake versions know about a -S option that is equivalent to -H
Later then the build tool mode of CMake comes very handy.
cmake --build builddir --target all --config Release -- -j4
It uses the default build tool of the platform (make in your case).
(give special options to the build tool after the trailing --, in this case -j4 for a parallel build)
Installing then is done by
cmake --build builddir --target install --config Release
AFAIK if you omit the --config Releaseoption CMake will use the CMAKE_BUILD_TYPE that was specified at configuration time either from CMakeLists.txt or from the command line.
Your entire RUN command then would look as follows:
RUN cd /usr/local/mysql-source/ \
&& cmake -H. -Bbuilddir \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/install \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITHOUT_TOKUDB=1 \
-DMYSQL_DATADIR=/usr/local/mysql/install/data \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/mysql/install/boost \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/install/tmp/mysql.sock \
&& cmake --build builddir --target all \
&& cmake --build builddir --target install \
&& cmake --build builddir --target clean

CMake: Force to include own boost before system

I've tried several ways and read quite some questions on SO, but still can't get my own boost get included before the one in /usr/include.
I'm using Ubuntu 14.04 btw.
BOOST_ROOT="${CMAKE_CURRENT_SOURCE_DIR}/Libraries/hdm-boost-lib" \
BOOST_INCLUDE_DIRS="${CMAKE_CURRENT_SOURCE_DIR}/Libraries/hdm-boost-lib/include" \
Boost_NO_BOOST_CMAKE=TRUE \
Boost_NO_SYSTEM_PATHS=TRUE \
Boost_LIBRARY_DIRS="${CMAKE_CURRENT_SOURCE_DIR}/Libraries/hdm-boost-lib/lib" \
cmake -D CMAKE_BUILD_TYPE=Release \
-DBoost_NO_BOOST_CMAKE=TRUE \
-DBoost_NO_SYSTEM_PATHS=TRUE \
-DBoost_LIBRARY_DIRS:FILEPATH="${CMAKE_CURRENT_SOURCE_DIR}/Libraries/hdm-boost-lib/lib" \
.
And this is my CMakeLists.txt
# set (CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-O2 -std=c++11 -Wall ${CMAKE_CXX_FLAGS}")
set (CMAKE_PREFIX_PATH "/opt/hdm")
set( serializer_SRC
main.cpp Serializer.cpp
)
add_executable(cadmiral-serializer ${serializer_SRC})
set(BOOST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../Libraries/hdm-boost-lib")
set(BOOST_INCLUDE_DIRS "${BOOST_ROOT}/include")
set(BOOST_LIBRARY_DIRS "${BOOST_ROOT}/lib")
#find_package(Boost REQUIRED regex date_time system filesystem thread graph program_options)
#find_package(geos)
#find_package(gdal)
include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/../Libraries/hdm-geo-common/hdm-geo-common/include"
"${BOOST_INCLUDE_DIRS}"
"${CMAKE_CURRENT_SOURCE_DIR}/../Libraries/hdm-geo-common/hdm-geo-common/include"
/opt/hdm/include
"${CMAKE_CURRENT_SOURCE_DIR}/../Libraries/hdm-boost-lib/include"
)
#find_library(GDAL_LIB libgdal /opt/hdm/gdal/lib)
#find_library(GEOS_LIB libgeos /opt/hdm/geos/lib)
target_link_libraries(cadmiral-serializer
"${CMAKE_CURRENT_SOURCE_DIR}/../Libraries/hdm-geo-common/hdm-geo-common/libhdm_geo_common.a"
/opt/hdm/geos/lib/libgeos.so
/opt/hdm/gdal/lib/libgdal.so
#${GEOS_LIB}
#${GDAL_LIB}
)
How can I force my own headers in Libraries/hdm-boost-lib/include?