cmake building external library from github submodule - c++11

I am trying to build a sample c++ project with cmake which depends on the external Pisatche library hosted in github. Installation guide list the following steps:
git clone https://github.com/oktal/pistache.git
git submodule update --init
cd pistache
mkdir -p {build,prefix}
cd build
cmake -G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
-DPISTACHE_BUILD_EXAMPLES=true \
-DPISTACHE_BUILD_TESTS=true \
-DPISTACHE_BUILD_DOCS=false \
-DPISTACHE_USE_SSL=true \
-DCMAKE_INSTALL_PREFIX=$PWD/../prefix \
../
make -j
make install
I would like to install this library from inside cmake and then link it to my executable. Any ideas how to do it?

Related

arm-none-eabi toolchain compile from source

For my current project we are having an issue which we can solve if we are able to recompile the arm toolchain (gcc, c++stdlib, nanolibc, etc) from source.
From the arm website I can download a snapshot of the source. I found a blog but it's outdated. The pdf he refers to no longer exists in this snapshot anyway.
Browsing through the extracted archive I can't seem to find any instructions how to compile.
Where can I find documentation how to compile arm-none-eabi from source?
The release notes available at the download site include build-from-source instructions.
I've made a quick transcription here, but future readers should be warned it may have become out-of-date.
How to build the toolchain from sources
You can build Arm GNU Toolchain from sources using Linaro ABE (Advanced Build Environment) and provided ABE manifest files.
Below example shows how to build gcc-arm-aarch64-none-elf toolchain from sources using Linaro ABE build system.
Instructions
ABE has a dependency on git-new-workdir and needs this tool to be installed in /usr/local/bin directory:
$ wget https://raw.githubusercontent.com/git/git/master/contrib/workdir/git-new-workdir
$ sudo mv git-new-workdir /usr/local/bin
$ sudo chmod +x /usr/local/bin/git-new-workdir
Clone ABE from the URL below and checkout the stablebranch (see Getting ABE):
$ git clone https://git.linaro.org/toolchain/abe.git
Create the build directory and change to it. Any name for the directory will work:
$ mkdir build && cd build
Configure ABE (from the build directory):
$ ../abe/configure
Download the toolchain manifest file, from https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/downloads, into the build folder, for the required toolchain, for example, gcc-arm-aarch64-none-elf-abe-manifest.txt:
$ wget https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/manifest/gcc-arm-aarch64-none-elf-abe-manifest.txt
Build toolchain (from the build directory):
$ ../abe/abe.sh --manifest gcc-arm-aarch64-none-elf-abe-manifest.txt --build all
The built toolchain will be installed and available for use in the builds/destdir/x86_64-unknown-linux-gnu/bin/ directory.
# Usage
# sudo ./build_arm
# Setup vars
export TARGET=arm-none-eabi
export PREFIX=/opt/gnuarm
export PATH=$PATH:$PREFIX/bin
export JN='-j 8'
export GCCVER=11.2.0
export BINUVER=2.37
rm -rf build-*
rm -rf gcc-*
rm -rf binutils-*
# Get archives
wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUVER.tar.gz
wget https://ftp.gnu.org/gnu/gcc/gcc-$GCCVER/gcc-$GCCVER.tar.gz
# Extract archives
tar xf binutils-$BINUVER.tar.gz
tar xf gcc-$GCCVER.tar.gz
# Build binutils
mkdir build-binutils
cd build-binutils
../binutils-$BINUVER/configure --target=$TARGET --prefix=$PREFIX
echo "MAKEINFO = :" >> Makefile
make $JN all
sudo make install
# Build GCC
mkdir ../build-gcc
cd ../build-gcc
../gcc-$GCCVER/configure --target=$TARGET --prefix=$PREFIX --without-headers --with-newlib --with-gnu-as --with-gnu-ld --enable-languages='c' --enable-frame-pointer=no
make $JN all-gcc
sudo make install-gcc
# Build libgcc.a
make $JN all-target-libgcc CFLAGS_FOR_TARGET="-g -O2"
sudo make install-target-libgcc

How to fix ./configure in MSYS2?

I'm trying to build libxc-4.3.4 in an MSYS2 shell on Windows 10. I've installed the latest version of MSYS2 (msys2-x86_64-20220319.exe) and followed the installation instructions. I've installed build tools using
pacman -S --needed base-devel mingw-w64-x86_64-toolchain autoconf
I've installed libxc dozens of time on Linux machines. The first step is
./configure --prefix /somewhere
But in MSYS2 I get
$ ./configure --prefix $PWD/../libxc
bash: ./configure: No such file or directory
How can I make this work?
MSYS2 prerequisites
First of all make sure MSYS2 has all programs that are needed.
In the MSYS2 shell first update the package manager information:
pacman -Syu --noconfirm
Then install the packages you need. I would recommend at least these:
pacman -S --noconfirm autoconf autoconf-archive automake make libtool pkg-config
Project sources
Next you should make sure the folder you are in actually has a configure script:
ls -l configure
A lot of projects these days are switching to more efficient build systems like CMake or Meson.
I usually use the following command in the projects source folder to check for several build systems:
ls -ld configure* m4 CMakeLists.txt cmake Makefile GNUmakefile setup.py scons SConscript SConstruct meson.build meson_options.txt *.pro *.proj *.sln BUILD.gn .gn 2> /dev/null
building libxc
For the libxc project I see there is a CMakeLists.txt file and also a configure.ac file.
So either you should look into using CMake or generate the configure file with:
touch README ChangeLog
autoreconf -f -i -I m4
I have just tried to build libxc in MSYS2 with CMake and Ninja and this worked:
# set the line below to the desired install location
INSTALLPREFIX=D:\Prog\changeme
# build static library
cmake -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF -DENABLE_PYTHON:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_static &&
ninja -Cbuild_static install/strip &&
echo SUCCESS
# build shared library
cmake -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -DENABLE_PYTHON:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_shared &&
ninja -Cbuild_shared install/strip &&
echo SUCCESS

LLVM opt doesn't work on macOS Big Sur: -bash: opt: command not found

I downloaded LLVM from the repository with git clone https://github.com/llvm/llvm-project.git and installed it on macOS Big Sur using the following commands:
$ cmake ../llvm -G "Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX=~/llvm-project/build \
-DBUILD_SHARED_LIBS=on \
-DLLVM_ENABLE_PROJECTS=clang
The installation went well and I can compile my foo.c program using clang -c -emit-llvm foo.c -o foo.bc obtaining foo.bc.
However, when I use opt -dot-cfg foo.bc to obtain the CFG, I have this error: -bash: opt: command not found.
Has anyone had this error? The solutions for previous versions of O.S. did not work!
when you clone a git project, you do not need to include the file. You just need to type
git clone https://github.com/llvm
You use two dots when calling the command.
../llvm
this tells bash "move up one directory level" and llvm is not one directory level up. this will work:
cmake ./llvm -G "Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX=~/llvm-project/build \
-DBUILD_SHARED_LIBS=on \
-DLLVM_ENABLE_PROJECTS=clang
The tool opt is installed in $HOME/llvm-project/build/bin.
You need to add $HOME/llvm-project/build/bin in your $PATH
"I can compile my foo.c program using clang" - Are you sure you are using your newly built clang and not the one shipped with XCode? opt should be inside ~/llvm-project/build/bin alongside clang. – Solved by #mcilloni in May 2 at 17:38

OpenCV error file INSTALL cannot find /bin/opencv_annotation

I have a problem on compiling OpenCV 3.X.X on Debian but It is OK on Ubuntu. I compile OpenCV with these commands:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/opt/opencv-3.3.0/build \
-D OPENCV_EXTRA_MODULES_PATH=/opt/opencv_contrib-3.3.0/modules \
-D BUILD_SHARED_LIBS=ON \
-D WITH_FFMPEG=ON \
-D PYTHON_EXECUTABLE=/opt/virtualenvs/cv/bin/python \
-D BUILD_EXAMPLES=ON \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D WITH_TBB=OFF \
-D WITH_OPENMP=ON \
-D BUILD_opencv_apps=ON \
-D BUILD_DOCS=ON ..
make -j12
sudo make install - j12
After "make install" I get this error and all shared library in build/lib that were built successfully before error, are deleted!
CMake Error at apps/annotation/cmake_install.cmake:42 (file):
file INSTALL cannot find "/opt/opencv-3.3.0/build/bin/opencv_annotation".
Call Stack (most recent call first):
apps/cmake_install.cmake:39 (include)
cmake_install.cmake:88 (include)
Makefile:66: recipe for target 'install' failed
make: *** [install] Error 1
If I set -D BUILD_opencv_apps=OFF, there is no error in compiling but again at the end all *.so files in build/lib are deleted.
Once in another computer I manage to compile OpenCV successfully but I don't know what exactly I had done.
My system has:
OpenCV 3.3.0
Debian GNU/Linux 8.9 (jessie) 3.16.43-2+deb8u5 (2017-09-19) x86_64 GNU/Linux
cmake version 3.0.2
gcc (Debian 4.9.2-10) 4.9.2
What's the problem?
I found the solution. This error happens when build directory is the same with install directory, At least on some Linux distributions!
I should change install directory.

'make install' failed after 'make' KiCad on OS X 10.10

i'm trying to install kicad on osx 10.10. After successfully build make, failed
make install at
-- fixup_bundle
-- app='/Users/bolor/Downloads/KiCad/bin/eeschema.app/Contents/MacOS/eeschema'
-- libs=''
-- dirs=''
-- fixup_bundle: preparing...
-- warning: embedded item does not exist '/Users/bolor/Downloads/KiCad/bin/eeschema.app/Contents/MacOS/libboost_chrono-mt.dylib'
--
warning: cannot resolve item '#loader_path/libboost_chrono-mt.dylib'
possible problems:
need more directories?
need to use InstallRequiredSystemLibraries?
run in install tree instead of build tree?
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool: can't open file: #loader_path/libboost_chrono-mt.dylib (No such file or directory)
CMake was configured like below:
cmake ../kicad \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.10 \
-DwxWidgets_CONFIG_EXECUTABLE=../wx-bin/bin/wx-config \
-DKICAD_SCRIPTING=OFF \
-DKICAD_SCRIPTING_MODULES=OFF \
-DKICAD_SCRIPTING_WXPYTHON=OFF \
-DCMAKE_INSTALL_PREFIX=../bin \
-DCMAKE_BUILD_TYPE=Release \
-DKICAD_SKIP_BOOST=ON \
-DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
does anyone know how to solve this?
thanks!
i have saved all the build log in a txt file and put on dropbox readable
here
I am pretty sure that's a bug in kicad's CMake script.
Other have the same problem, see https://gist.github.com/rhaamo/497d3c94929b69874411
In
http://www.mikrocontroller.net/topic/380428
they say it either works with -DKICAD_SKIP_BOOST=ON or with letting kicad build its own Boost library.

Resources