I'm using the CMake Tools extension in VSCode to build and run a C++ project on Windows.
Where do I set if the build configuration should be Debug or Release?
On Build, CMake Tools executes
"C:\Program Files\CMake\bin\cmake.EXE" --build c:/work/foobar/build --config Debug --target ALL_BUILD
How do I get the extension to build with --config Release?
The CMake Tools extension sets up a lot of goodies, including a status bar panel for configuring various aspects of your build(s). In the status line various panels provided by VSCode and extensions can be enabled/disabled. And example including the CMake Tools mini panels appears below:
Note: I am not running VS Code on a Windows machine; mine is MacOS, but the premise is the same.
Anyway, if you click on the portion that says CMake: [Debug]: Ready a select-variant list should open near the top of the IDE in the location you're probably familiar seeing the general Command Palette open. It will look like this:
It is here you can change your selection from one build configuration type to another.
You can also do this via the main command palette by doing the following:
Hit ctrl-shift-P (or cmd-shift-P on MacOS)
Type CMake. The list should filter to just CMake command options.
Scroll the list and choose CMake: Select Variant
The same aforementioned build variant options should present themselves.
Related
I'm using the latest AppImage of KDevelop (version 5.6.1) on a kubuntu 20.04 to develop and build a project with CMake.
Opposed to earlier versions of KDevelop this one automatically executes a CMake configure run whenever I save a source file or a CMake file. Earlier versions only did this on manual request.
This is annoying for me, because I have the reflex to save whenever I stop typing and the CMake configure run switches the tool view to the build panel although I may have been working with another view. Additionally, when I work on my (very complex) CMake configuration I sometimes want to watch the configure run to see some changes in the output.
I went through all global and project-specific settings multiple times, but I couldn't find out how to turn off this behavior, so:
How can I turn off the automatic execution of CMake on save in KDevelop 5.6.1?
I have few json data which I need to upload on azure iot hub. I am writing code in c++ and need mqtt to publish all the data to iot hub. I am referring this github page: https://github.com/eclipse/paho.mqtt.cpp
But instruction on how to build it is a bit confusing and not seems to be working. Can anyone please explain how can I install mqtt in windows and can use it with visual studio c++. Please help. Thanks
I struggled the last few days too and I finally got it running.
I succeeded using the CMake GUI and the Developer Console from Visual Studio 2019.
The instructions I (kinda) followed, were these: https://github.com/eclipse/paho.mqtt.cpp. Scroll down to the Windows part, it's actually very straight forward. However, instead of using the terminal for the cmake -BBuild ... commands I used the CMake GUI, where I configured the variables appropriately.
Installing paho.mqtt.c
So, as mentioned on the instructions, you first need to install paho.mqtt.c. For that, just clone the repo somewhere on your machine. Inside the paho.mqtt.c folder create a "build" folder.
Open the CMake GUI, then click on "Browse Source" and set the folder where the repo was cloned ../paho.mqtt.c/.
For "Browse Build" select the build folder you just created ../paho.mqtt.c/build/
The click on "Configure" (I used the default Generator Visual Studio 16 2019). At this instance I didn't touch the configuration variables, so I just went ahead and clicked on "Generate".
CMake GUI for paho.mqtt.c
Then, open a developer console (press the windows key, type "developer" and open the Developer Command Prompt for VS 2019, or whatever version you use) and navigate to the paho.mqtt.c folder. There, according to the instructions on the github page, type the command:
cmake --build build --target install
This will install the paho.mqtt.c in C:\Program Files(x86)\Eclipse Paho C\. Note that this location can be changed by modifying the CMAKE_INSTALL_PREFIX variable on the CMake GUI to a custom location.
Installing paho.mqtt.cpp
The procedure is in nature the same: open the CMake GUI, select the folder that contains the source, then the build folder and then click on "Configure".
Now, since paho.mqtt.cpp relies on libraries from paho.mqtt.c, you must tell cmake where to find the corresponding paho.mqtt.c libraries.
In order to do this, configure the variables PAHO_MQTT_C_INCLUDE_DIRS and PAHO_MQTT_C_LIBRARIES.
PAHO_MQTT_C_INCLUDE_DIRS should point to the "include" folder inside the paho.mqtt.c installation, in my case: C:/Program Files (x86)/Eclipse Paho C/include
PAHO_MQTT_C_LIBRARIES I set up to point to the paho-mqtt3c.dll, in my case: C:/Program Files (x86)/Eclipse Paho C/bin/paho-mqtt3c.dll
The other options I left untouched.
Finally, go back to the Developer Command Prompt, navigate to the paho.mqtt.cpp folder and run cmake --build build --target install.
If everything goes well, paho.mqtt.cpp will be installed in C:/Program Files (x86)/paho-mqtt-cpp, according to the configuration variable CMAKE_INSTALL_PREFIX.
Now, you can reference both libraries in your c++ projects. Be aware that if you want to use the paho.mqtt.cpp library on your project you'll also have to include paho.mqtt.c.
I'm using QT Creator 3.5.1 on Ubuntu 16.0.4 for a C++ project.
"Run CMake" and "Run" commands work fine in the IDE.
I want to do these two things from a terminal without the IDE. How can I do this?
Qt creator will actually tell you in the 'compile out' pane what commands are run for cmake, usually along the line of cmake --build . -- target all. For running the application you just find the build folder and the executable, alternatively you can peek at the Projects > Run configuration (in case you specify some arguments, but clearly that's not the case)
Note that with a new cmake (>= 3.7) you want to make sure not to use cmake in the build directory that is seen by Qt Creator while that has the project open. Creator will be running cmake in server-mode and that does not like any of the cmake files being changed:-/
Creator should print exactly what it runs in the output pane. For a build that is cmake --build . --target all (in the build directory).
Make sure to run the command in the right directory. For builds that is the top level build directory, while for build targets that can be set in Project mode.
Sometimes you also need some environment variables to be set (to pick up libraries, etc.). Creator does show the environment it uses to build or run things in Project mode.
I am not a C/C++ developer, I tried to google but I couldn't find anything about.
Trying to write a simple java port of Assimp, I modified the Main.cpp code runs fine but it doesn't stop at the breakpoint, I guess because I am not compiling in debug mode.
My steps:
cloned assimp
from terminal in the directory cmake -G "Unix Makefiles"
opened the project in Netbeans from "existing sources"
compiled
This is my project Debug Property:
I don't have any other configuration other than the "Default" one.
How can I solve?
Cmake based projects are configured using the cmake configuration. Instead of switching to debug / release configuration within netbeans - as usual for "default" C/C++ Projects - you have to set CMAKE_BUILD_TYPE variable accordingly.
Using command line:
Debug: cmake -DCMAKE_BUILD_TYPE=Debug
Release: cmake -DCMAKE_BUILD_TYPE=Release
You do not need to repeat the other flags like, -G ….
Alternatively use the CMake GUI.
To get the selectable build configurations you can create them your own (go to Build -> Pre-Build and add calls as above).
TIP
It's recommended to do an out-of-source build.
I recently downloaded and built opencv in my 64-bit Windows machine using cmake. All the binaries are included in the install folder and it contains only the folders as shown below:
I don't know how to config cmake to produce binaries for x86. I'm asking this, because I'm using Qt Creator 32bit with MinGW and I'm getting problems while linking and compiling the code. What's the proper way to do the build? I'm using mingw compiler suite.
Note: The downloaded package contains the pre-built binaries for x86 but there are none for MinGW, but only for Visual Studio.
Steps for mingw from with cmake-gui from this guide. We could also do this easily on command prompt with cmake and -m32 option. But using cmake-gui will give you more idea about the options available for opencv configuration and bring you in better position if you want to customize opencv build tomorrow ( like enabling java wrapper or OpenCL etc ).
Start cmake-gui.
Set source path to downloaded opencv directory and build path to your choice as in image
Click Configure button and specify generator as mingw makefiles as
in image
Choose compilers ( here we choose 32 bit ) as in image and click Finish button.
An options page will be listed.
5.1. Edit CMAKE_INSTALL_PREFIX to change the install location if you want to.
5.2. Select ENABLE_CXX11 if it isn't already selected.
5.3. Change other options only if you are familiar with them. Then click Configure again and then click 'Generate` to generate make files.
Modify opencv\sources\modules\videoio\src\cap_dshow.cpp and add this define at the top of the file:
#define STRSAFE_NO_DEPRECATE
In command prompt( at build path ) type mingw32-make ( add mingw32-make folder to PATH if required )
On completion, type mingw32-make install