Get product version via terminal when building cmake project - build

Is there a way to get product version when building the project via cmake from terminal. In the CMakeLists.txt I have declared:
project(sayProject VERSION "1.0")
Appreciate any help.

If you want to read the setting of PROJECT_VERSION without actually running cmake, then this answer will get you that.
Specifically, I use this script:
cmake --system-information |
awk -F= '$1~/CMAKE_PROJECT_VERSION:STATIC/{print$2}'

Not 100% clear from the question, but this:
message("cmake version ${CMAKE_VERSION}")
should output the current version of cmake to the terminal
or this:
message("project version ${PROJECT_VERSION}")
should output the current version of the project.

Related

How to build OpenCV 4.5 from source on RaspberryPi 4?

I am trying to compile the OpenCV 4.5 library from source on a fresh install of Raspian and I'm running into a problem regarding the C++ standard. After running the cmake command from the build dir, in order to obtain the required makefiles, I get prompted with the message "OpenCV 4.X requires c++11. I tried modifying the CMakeLists.txt adding the set(CMAKE_CXX_STANDARD 11) and also adfding a building flag using the -D CMAKE_CXX_FLAGS='-std=c++11' option but without luck. All options available here: cmake build command + flags I'm not sure how I could get past this and I could use some advice if someone encountered it before, any suggestions? TIA 😃

Cannot Run Compiler 'cl' for qt5.10.1 on Windows 10 in terminal

I have never used qt before, but I got a task to build an already existing application for Windows and Mac using the newest version of qt. What I have done so far is:
Installed Visual Studio Professional 2017.
Installed the latest Qt 5 Open Source.
Note: when installing the QT 5 I installed all of the components under QT/ QT 5.10.1 which were: qt 5.10.1 components and under QT/Tools I installed QT Creator 4.6.0 CDB Debugger Support and MinGW 5.3.0 : qt 5 Tools
I cloned the branch from GitHub that I wanted to build to C:/Projects
Then in Git Bash I cd to the project and tried to run qmake. The first time I had this problem:
"bash: qmake: command not found"
After searching into the problem I found out that I haven't added "Qt/5.10.1/msvc2017_64/bin" to PATH and I added it. Now when I echo $PATH I can see the directory added.
Now after bash recognises qmake and I try to run it it says:
Project ERROR: Cannot run target compiler 'cl'. Output:
===================
Maybe you forgot to setup the environment?
I have no idea how to fix the problem due to the fact that I have never used QT to build anything before. Can you help me?
In the read me file for the application I am trying to build it says:
Step-by-step instructions
1. Clone this branch
2. cd into the project
3. Run qmake - this wil generate Makefiles for all of the project's modules
4.Run make (Use the -j4 of -j flags - this greatly speeds up the build process - see the manual page for make for more info). You can also use the -s flag to silence the output - this also wins you a few seconds.
I am a bit puzzled by the instructions, it does not say to run qmake -project anywhere, but there is a qt project file in the directory that I cd to. Does this mean that I don't have to run qmake -project?
Also I have no idea how to run make by using the -j4 and -j flags and how to run flags in general. Could someone help me?
I believe that for the Cannot Run Compiler 'cl' issue I have some kind of a problem with the set up. Did I install too many components or is it to do with the VS setup?
I highly recommend you to install Qt from the Qt installer, and to use Qt Creator.
However, if you want to use it from source, you first need to get a compiler (ex: MinGW). Then you need to execute the instructions, but you need to use a MinGW (or whatever compiler you use) command prompt, which will automatically set the environment variables needed.
Note that this is Windows specific. On mac and linux, the compiler's environment variables are already set in the default command prompt (if there is a compiler, obviously).

CMake error no CMAKE_C_COMPILER could be found using Xcode and GLFW

I'm trying to follow this tutorial to get started with OpenGL: http://www.learnopengl.com/#!Getting-started/Creating-a-window and it requires downloading glfw and CMake.
I have set the downloaded glfw folder as the source code folder and I have created inside that folder another one called "build" which I then set as the build one for the binaries, as the tutorial asks.
I click on "Configure" and I select XCode as the Generator, since I'm on a Mac.
The problem is that when I try to configure the project CMake gives me this error:
The C compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_C_COMPILER could be found.
Configuring incomplete, errors occurred!
See also "/Users/standard/Desktop/glfw-3.2.1/build/CMakeFiles/CMakeOutput.log".
See also "/Users/standard/Desktop/glfw-3.2.1/build/CMakeFiles/CMakeError.log".
I've already read this question, but as far as I can understand, it doesn't have what I need:
CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
If you have installed Xcode or Command Line Tools for Xcode, try this:
sudo xcode-select --reset
This happened to me with Xcode10 / Cmake 3.12 after installing Homebrew. Running sudo xcode-select --reset fixed it for me.
Did you install Xcode and Xcode Commandline Tools?
xcode-select --install
If you have Xcode Commandline Tools installed, you should no longer be receiving the xcrun is missing error.
How did you install Cmake? Once you have ensured that Xcode Commandline Tools is installed, please completely remove Cmake from your system and reinstall it. You have a screwed up configuration. There are ways to debug and fix it without a clean install, but since you are new to this, it will be the easiest and lest frustrating way.
Failing that if you do have Xcode Commandline Tools installed, hstdt suggested trying this:
sudo xcode-select --reset
This error means CMake cannot find your standard C/C++ Compiler, looks like you'll need to export the environment variables yourself. you can find the path of your C/C++ compiler with:
xcrun -find c++
xcrun -find cc
Then afterwards when you have the paths, create two variables inside the gui. If you are running it from the cline, it would be something like
cmake -D CMAKE_C_COMPILER="/path/to/your/c/compiler/executable" -D CMAKE_CXX_COMPILER="/path/to/your/cpp/compiler/executable" ...
On a fresh Xcode install the command line tools complain about agreeing to the EULA which build tools don't like. Which you can do with:
sudo xcodebuild -license
If you are on a Mac computer and have Homebrew, you can simply upgrade cmake, forcing the compiler to be reconfigured:
brew upgrade cmake
In my case, I needed to install CMake from CMake official site, download the .dmg, install it and then add the CMake folder the system's PATH.
Before the installation, the output of which cmake is /usr/local/bin/cmake.
After the installation it should be something like /Applications/CMake.app/Contents/bin/cmake.
This has solved the issue for me.
I get exactly this error if ccache is enabled on my machine. Disabling ccache fixed the problem for me.
To check if ccache is enabled, print the systems variables CC or CXX:
echo $CC
echo $CXX
This prints something like the following: ccache clang -Qunused-arguments -fcolor-diagnostics. (CC or CXX are typically overridden by the .bashrc or .zshrc file.)
To disable ccache, use the following:
CC=clang
CXX=clang++
Then rebuild the cmake project:
cmake -G Xcode <path/to/CMakeLists.txt>
Apparently, it is possible to use CMake's Xcode generator also in combination with ccache, as is described here. But I never tried it out myself.
I got this error when I had an invalid value set for CMAKE_OSX_SYSROOT. I was trying to give it the name of the SDK e.g. "macOS 10.13". Setting it to the full path of the SDK resolved the issue.
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
Compiler detection appears to be broken with Xcode 10 and older versions of CMake. I know that it broke for me with CMake 2.2 and upgrading to the latest (2.13) solved it for me. It was working fine with Xcode 9 and it broke with the upgrade. I tried the other solutions (all good depending on your situation) but upgrading CMake fixed the issue.
If you are on CLion and facing this issue try changing the C and C++ compiler location inside Toolchains settings to the latest one. the default GCC installation directory is /usr/local/Cellar/gcc/...
after I upgrade Xcode to new verison, I met this error, then I upgrade my cmake version, problem solved.
For anyone coming to this question nowadays from google, my problem was fixed via
xcodebuild -runFirstLaunch
I found this by inspecting CMakeFiles/CMakeError.log

How to build cmake-project with atom text editor?

I've installed packages build and build-make, and it's not obvious what to do next.
Build-tools package is bugged and impossible to install now.
I have cmake project, sucsessfully build in different IDE: QTCreator, VisualStudio, via bash. So i want to make it with atom, and there is no instruction how to use it's build-make package. Documentation to this package is empty.
in bash i call: cmake ../src from my build dir.
So in .atom-build.json i put this command and point directory as working - and nothing happens, on f9 i've god "Cannot read peoperty "exec" or undefined"
Actually, there is a cmake package for Atom.
Here you go:
https://atom.io/packages/build-cmake
Firstly, CMake and make are two different things.
What you are looking for is a CMake plugin for Atom, of which there are currently none. (Some for syntax highlighting but none for running graphically...)
If you have CMake working in other IDEs then you shouldn't have a problem running CMake from the command line:
cd /path/to/project
cmake .

configure MinGW with Eclipse CDT

I have searched a lot about this and read most of the available answers for similar problem but I still couldn't solve it. Therefore, any help will be helpful.
I am using Eclipse Mars(Latest version after Luna) on Windows 7
MinGW is installed in "C:\Program Files (x86)\CodeBlocks\MinGW\bin".
Environment variable "Path" contains "C:\Program Files (x86)\CodeBlocks\MinGW\bin;..."
Preferences -> C/C++ -> Build -> Settings -> Discovery->CDT GCC Built-in Compiler Settings : command to get compiler specs
${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"
manually doing gcc -E -P -v -dD in cmd from any directory gives
.
.
Target: mingw32
.
.
Errors:
Program g++/gcc not found in PATH
I make a C++ project, add a file with hello world program in it.
I get errors "unresolved inclusion " and 'printf' could not be resolved.
comment if any other details required
It sounds like you're doing everything correctly.
TWO SUGGESTIONS:
Take a look at this link, and see if you missed anything regarding the MinGW/GCC install:
https://www3.ntu.edu.sg/home/ehchua/programming/howto/EclipseCpp_HowTo.html
Otherwise, consider deleting (or simply renaming) your current Eclipse and installing the CDT (Eclipse for C/C++ Developers) version instead:
http://www.eclipse.org/downloads/
For whatever it's worth, here are a couple of screenshots from my property settings (I'm able to create and successfully build a new C project):
I think your problem is simply because of MinGW path include white spaces in it. just reinstalling MinGW on Root directory "c:\MinGW"will solve your problem.
install MinGW with basic setup packages select "mingw-developer-toolkit, mingw32-base, mingw32-gcc-g++, msys-base". complete installation.
restart your pc. then check your eclipse settings.
I hope your problem is already solved.
I also faced such problems,you need to set environment variable, In path add your MinGW location, if you haven't downloaded MinGW go here for downloading MinGW:
http://sourceforge.net/projects/mingw/files/latest/download?source=files
Simple solution is:
For more and detailed information to fix your problem, it worked for me!
Visit here:
http://www.multigesture.net/articles/how-to-install-mingw-msys-and-eclipse-on-windows/