I'm using a shell gitlab runner on my macbook. It's task is currently to run a very simple yaml file to build my project using cmake.
build:
before_script:
- git submodule update --init --recursive
- mkdir cmake-build-debug
- cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" .
script:
- cmake --build . --target all -- -j 4
It returns this though: CMake 3.17 or higher is required. You are running version 3.16.3.
When I add - which cmake to my before_script, it returns /usr/bin/cmake
When I run ls /usr/bin | grep cmake in my terminal, it doesn't return anything. When I run brew info cmake it returns the version as cmake: stable 3.19.3
How do I update cmake in my runner? Apparently It can't find brew in the before_script either.
PS: added bonus, if I set the minimum cmake version required to 3.16 it suddenly seems to be unable to link libm
I forgot to add a tag. So it wasn't running on my computer but on a different server.
Related
I have a cpp project, and I want to build everything from source, to get latest things likned in. So under my project root I've created a 3rd_party folder and assemble following script:
sudo apt-get install autoconf automake libtool curl make g++ unzip -y
git clone https://github.com/google/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
./configure
make
make check
sudo make install
sudo ldconfig
cd ..
echo installing grpc
git clone --recurse-submodules -b v1.43.0 https://github.com/grpc/grpc
export MY_INSTALL_DIR=$HOME/.local
be sure that its exists
cd grpc
mkdir -p cmake/build
pushd cmake/build
cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR ../..
make -j
make install
popd
i've encountered following flaws:
grpc v1.43.0 clones 3rd party submodule protoc v3.18, which after build has problems - protoc binary says "cpp plugin not found", when trying to generate
To overcome that I've copied sources obtained in the first part of script, to 3rd party subfolder of second part, to gurantee it to be 3.19 - then after compilation protoc working great, plugins are in place, and grpc is linked against latest version.
Very weird issue, needs understanding why it clones outdated version, and why 3.18 has no plugins under same build parameters as 3.19
in cmakelists find_package(Protobuf REQUIRED) fails at all
find_package( gRPC REQUIRED ) is not operating properly:
Found package configuration file:
[cmake]
[cmake] /home/a/.local/lib/cmake/grpc/gRPCConfig.cmake
[cmake]
[cmake] but it set gRPC_FOUND to FALSE so package "gRPC" is considered to be NOT
[cmake] FOUND. Reason given by package:
[cmake]
[cmake] The following imported targets are referenced, but are missing:
[cmake] protobuf::libprotobuf protobuf::libprotoc
Question
How can I write script, that in an empty folder will get me everything, related to grpc 3rd party libs and tools, that I need for project?
Here are the steps I took:
$ mkdir .local
$ export INSTALL_PREFIX="$PWD/.local"
$ export CMAKE_GENERATOR=Ninja # optional, but recommended
$ git clone --recurse-submodules -b v3.19.3 --depth 1 https://github.com/google/protobuf.git
$ pushd protobuf
$ ./autogen.sh
$ ./configure --prefix=$INSTALL_PREFIX
$ make -j$(nproc)
$ make install
$ popd
$ git clone --recurse-submodules -b v1.43.0 --depth 1 https://github.com/grpc/grpc.git
$ cmake -S grpc -B .build/grpc \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
-DCMAKE_PREFIX_PATH=$INSTALL_PREFIX \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DgRPC_PROTOBUF_PROVIDER=package \
-DABSL_PROPAGATE_CXX_STD=ON
$ cmake --build .build/grpc --target install
...
$ mkdir example
$ echo "int main () { return 0; }" > example/main.cpp
$ vim example/CMakeLists.txt
$ cat example/CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(example)
find_package(gRPC REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE gRPC::grpc++)
$ cmake -S example -B .build/example \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$INSTALL_PREFIX
$ cmake --build .build/example
...
I build protobuf separately because gRPC doesn't set up its dependencies in CMake correctly when using its internal protobuf build (I tried both ways). This involves passing --prefix to protobuf's ./configure script and passing -DgRPC_PROTOBUF_PROVIDER=package to gRPC's CMake build. The latter is a gRPC-specific variable that tells it not to build protobuf, but to search for it instead. I tell gRPC where to find protobuf by setting CMAKE_PREFIX_PATH, which is a standard variable.
I'm trying to use clang with CMake. Here's my Dockerfile. You can see that I did not install build-essentials, only clang, because I dont want GNU compilers to be made default.
My Dockerfile:
FROM ubuntu:bionic
WORKDIR /home/project
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update\
&& apt-get install -y clang wget
RUN wget https://github.com/Kitware/CMake/releases/download/v3.18.0-rc2/cmake-3.18.0-rc2-Linux-x86_64.sh && ls
RUN mkdir -p /usr/local/cmake \
&& chmod +x cmake-3.18.0-rc2-Linux-x86_64.sh \
&& ./cmake-3.18.0-rc2-Linux-x86_64.sh --skip-license --prefix=/usr/local/cmake
ENV PATH="/usr/local/cmake/bin:${PATH}"
CMakeLists.txt
cmake_minimum_required (VERSION 3.10)
project(libsmoltcp_cpp LANGUAGES CXX)
Here's what I get when running cmake .:
root#275dbeaae123:/home/project# cmake .
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/home/project/CMakeFiles/CMakeOutput.log".
In update-alternatives there's just clang:
root#275dbeaae123:/home/project# update-alternatives --config cc
There is only one alternative in link group cc (providing /usr/bin/cc): /usr/bin/clang
Nothing to configure.
It seems your CMake configuration is generating Makefiles that should be run with make but it isn't installed.
Install make.
The second issue could be you have configured C language:
update-alternatives --config cc
And may need to configure C++ language:
update-alternatives --set g++ /usr/bin/clang
I'm trying to build this
https://github.com/patrikhuber/eos
but I'm having troubles.
The instructions are pretty simple, as it says on gitHub
To build:
git clone --recursive https://github.com/patrikhuber/eos.git
mkdir build && cd build # creates a build directory next to the 'eos' folder
cmake -G "<your favourite generator>" ../eos -DCMAKE_INSTALL_PREFIX=../install/
make && make install # or open the project file and build in an IDE like Visual Studio
I'm using "Ninja" as generator and it looks like the cmake part goes through successfully as I get
-- Configuring done
-- Generating done
-- Build files have been written to: /home/francesco/eos/build
That's where things stop "working" for me, or where I fail to understand what's next. Following the instructions, I type
make && make install
and I get this message
make: *** No targets specified and no makefile found. Stop.
I looked around for solutions but I don't really understand what I am supposed to do: I tried
./configure
but I'm getting
bash: ./configure: No such file or directory
Anyone can please help?
Thanks
It always depends on your CMake "Generator". The 'make' is linux/mingw tool/command. For VisualStudio you can use nmake or sln/proj generated stuff.
More reliable could be utilize CMake for building i.e. for "NMake Makefiles" generator:
cmake --build <build folder> --target install
or
cmake --build <build folder> --config release --target install
for VisualStudio generator
I had the same problem, and solved by tinkering with locations for cmake and make. Here's what I used:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local
make
I believe /usr/local is the default location (see here)
I run cmake in command prompt with:
mkdir build && cd build
.. cmake
But now, I have problem constructing the command to build realease static.
I tried:
C:\Users\Kuba\Downloads\rabbitmq-c>cmake --build build --BUILD_STATIC_LIBS=ON
Which yields the error:
Unknown argument --BUILD_STATIC_LIBS=ON
How to correct this? Thanks !
You should define the variable using the -D option:
cmake --build build -DBUILD_STATIC_LIBS=ON
Please read the documentation for more information.
Configuring the build is a separate step from building it.
From the source directory create a binary directory:
mkdir build && cd build
Then configure the build (this is where you can add other build-flags):
cmake -DBUILD_STATIC_LIBS=ON ..
then build it:
cmake --build .
There is a project that was developed for linux environment. Now I am trying to build this on windows using CMake.
I keep trying to build the project and always get this error:
CMake Error at C:/Program Files(x86)/CMake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
Call Stack (most recent call first):
C:/Program Files(x86)/CMake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files(x86)/CMake/share/cmake-3.3/Modules/FindGTest.cmake:204 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
C:/Users/awy9/git/cmake_modules/modules/SigeoGTest.cmake:21 (find_package)
C:/Users/awy9/git/cmake_modules/modules/SigeoInit.cmake:29 (include)
CMakeLists.txt:12 (include)
How can I set these variables to work on this project now on Windows?
Honestly It's not the best idea to set hardcoded variables like you've done with GTEST_LIBRARY and GTEST_MAIN_LIBRARY.
I had the exact same problem. I was using gtest 1.7.0 on windows and getting the same error.
Turns out "GTest" should be "gtest" (not capitalized).
So the code in my CMakeLists.txt became:
find_package(gtest REQUIRED)
Note that I was using CMake 3.9
EDIT
I would highly recommend following this guide now:
http://crascit.com/2015/07/25/cmake-gtest/
It is by far the best method I have found to use unbuilt gtest and gmock in your cmake project.
UPDATE
#Tsyvarev helped me solving the first problem and I quote him:
This is standard CMake message, when requested package(GTest in your case) is not found. You should install GTest before configuring your project. Or, if you already have installed it into non-standard location, pass this location via GTEST_ROOT variable: cmake -DGTEST_ROOT= ...
As alternative for the passing variable to cmake, you can set environment variable: set GTEST_ROOT=
This solved the problem with the value of GTEST_INCLUDE_DIR, but I still had these errors:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.3/Modules/FindPackageH andleStandardArgs.cmake:148 (message): Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY)
SOLUTION
I figured that on Windows environment some values are different from what the manuals say.
After compiling Gtest, I got two libs: gtest.lib and gtest_main.lib
Then, I set these filepath variables:
GTEST_LIBRARY=C:\Users\awy9\Softwares\Gtest\gtest-1.7.0\Debug\gtest.lib
GTEST_MAIN_LIBRARY=C:\Users\awy9\Softwares\Gtest\gtest-1.7.0\Debug\gtest_main.lib
Now everything is working!
Thank you
I've come up with a similar issue when building my project through GitHub Actions on Windows platform.
Even if I export the CMAKE_PREFIX_PATH to enable the find_package(GTest REQUIRED) to properly find the framework library (Windows is a bit nasty BTW), it continues to fail with Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY). Note that it correctly fetches the include directory.
After digging a little bit deeper into the issue I realized that on Windows the command cmake --build . --target install without any --config options, builds the library in Debug configuration, contrary to Linux and macOS.
If you are then building your project in Release, e.g. cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build . --config Release --target install, the find_package(GTest REQUIRED) won't find any GTest library because it searches for the nonexistent Release build.
In this case a better solution is to install GTest in Release mode w.r.t. hardcoding the library paths to fetch the Debug\ directory builds.
I attach also the GitHub Action steps which may be helpful for someone:
steps:
- name: Clone GTest
shell: bash
working-directory: ${{runner.workspace}}
run: git clone https://github.com/google/googletest.git
- name: Create GTest Build Environment
shell: bash
working-directory: ${{runner.workspace}}/googletest
run: cmake -E make_directory build
- name: Configure GTest CMake
shell: bash
working-directory: ${{runner.workspace}}/googletest/build
run: cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_FLAGS=-std=c++11
- name: Install GTest
shell: bash
working-directory: ${{runner.workspace}}/googletest/build
run: cmake --build . --config $BUILD_TYPE --target install || sudo cmake --build . --config $BUILD_TYPE --target install
- name: Export CMAKE_PREFIX_PATH on Windows
shell: bash
if: runner.os == 'Windows'
run: echo '::set-env name=CMAKE_PREFIX_PATH::C:/Program Files (x86)/googletest-distribution'
- name: Checkout
uses: actions/checkout#v2
- ... your project build steps