How to build CLion based CMake Project with custom Toolchain from Command Line - cmake

I've only worked with CMake in conjunction with the CLion IDE but I'm aware that CMake projects can be built on the command line completely without the IDE with the CMake build system only.
Now I have some more complex CLion projects for which I created a custom toolchain and various profiles through the CLion menus (File -> Settings -> Build, Execution, Deployment --> Toolchain / CMake). I want to switch to building these projects through Gitlab CI without CLion. But how do I start a CMake build on the command line in on a build VM without CLion installed that uses the toolchain and profiles that I created in the CLion GUI?
The desired settings to reproduce are:
Using a custom gcc cross compiler for all profiles
Dependent on the profile:
passing various CMake variables (like -DMY_VAR=FOO) to my CMakeLists
choosing a debug or release build as build type
In CLion I have one custom toolchain with the special gcc and four profiles with different settings, all using this toolchain.
Does CLion generate a toolchain file somewhere in the background that I could just use (didn't find any so far) or do I need to write my own toolchain file and pass it to cmake?

Related

Cmake support for tasking tri-core compiler toolchain

This is unsure if cmake support is available for the tasking tri-core compiler toolchain.
We could use a normal makefile to compile using this compiler, but I would like to configure cmake to do the same in windows
You could either use Greenhills MULTI project files, or define your own Toolchain file to enable cross-compiling for your project.

CMake version in CLion not updating

I cloned a project from my teacher, and I wanted to run it on CLion. However, I noticed an error:
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.14 or higher is required. You are running version 3.13.2
I configured a new CMake debugger in CLion, but I still keep getting the error.
I have a new version of CMake installed:
When I install a new CMake version in cygwin, CLion returns this:
Does anyone know what I am missing or doing wrong?
It sounds like you want CLion to use your newest version of CMake (instead of the bundled 3.13.2 version). To do that, you must add a new Toolchain (see here) or modify an existing one (see here):
On Windows CLion, navigate to File > Settings > Build, Execution, Deployment > Toolchains, and choose the toolchain you want to modify.
At the CMake: section, select a custom CMake installation by choosing the path to your custom CMake executable (likely a bin folder).
Click OK to save your changes.
Eventually, I solved the problem by installing a new version of CMake inside the cygwin installer. I also updated CLion, because I had the 2018 version and that version only supports CMake versions up to and including 3.13. After updating CLion to the 2019 version, it supported CMake versions up to and including 3.15. Because the CMake version 3.16 is pretty recently released. CLion automatically takes the maximum supported version, which in this case is the 3.15. The minimum version in de CMakeLists.txt was 3.14, so 3.15 worked fine.

Build configuration error using Android NDK

There is a build configuration error (Gradle sync failed) starting a new simple Android project using IntelliJ IDEA and the installed Android SDK (API 28) to include C++ support.
If I can remember, it worked when first installed, but now any attempt to compile and build the project using the IntelliJ GUI fail. LLDB, CMake and NDK are all installed correctly in the correct folders and the local.properties file references the location of the SDK and NDK.
All attempts to refresh linked C++ projects or clear caches (invalidate caches/restart) make no difference.
CMake_server_log.txt suggests:
CMAKE SERVER: CMake Error: CMake was unable to find a build program
corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You
probably need to select a different build tool.
Build output (edited to remove path):
Cause: executing external native build for cmake CMakeLists.txt
There appears to be a lack of configuration to complete the build or missing PATH or ENVIRONMENT variable. Should I manually try to change this or add some extra code to the build.gradle or CMakeLists.txt? There is the ninja application in the cmake bin directory.
Even importing other NDK sample projects fail (after downloading any required dependencies e.g. Gradle version).
Reinstalling LLDB, CMake and the NDK via SDK Tools do not solve the issue either.
I get the impression that I need to completely uninstall IntelliJ IDEA on Windows and remove any remaining folders/files associated with it, before reinstalling it. That would be a shame as IntelliJ IDEA works for other type of Android projects not requiring native C++ support.

What is the best multiplattform IDE to use with CMAKE?

I'm trying to set up a multiplattform project using CMake, so its easy to setup on any PC.
Basicly the CMAKE script sets up all settings for the projects and finds all libraries automatically.
But after trying a few IDE's like codeblocks and eclipse it seams like CMake integration in these is pretty lackluster.
Does anybody have a few recommendations for better IDE's?
They should have an included debugger and code completion and should be easy to setup on windows and linux.
Have a look at clion, that fully integrates CMake, but I dislike the editor, not really user friendly.
Starting with version 2.6.0 CMake includes a generator for Eclipse CDT 4.0 or newer. It works together with the Makefile generators (i.e. "Unix Makefiles", "MinGW Makefiles", "MSYS Makefiles", and maybe "NMake Makefiles"). This generator creates a set of .project/.cproject files that can be imported in Eclipse using File > Import > Existing Eclipse project.
https://cmake.org/Wiki/Eclipse_CDT4_Generator

pjsip using cmake

Has someone compiled pjsip using cmake?
The project does not have a way of using CMake to build the library itself (yet). But you can link to pjproject libs from your CMake project.
Here's a snippet from one of mine that uses pjproject as a dependency:
find_package(PKGCONFIG REQUIRED)
pkg_check_modules(PJSIP libpjproject>=1.14 REQUIRED)
include_directories(${PJSIP_INCLUDE_DIRS})
...
target_link_libraries(your_target ${PJSIP_LIBRARIES})
This requires pkg-config as well, and that pjproject.pc should be in it's default search path, or in directory in $PKG_CONFIG_PATH.
This should work on Linux and OS X.
I just made cmake-based compilation of PJSIP v2.3.
I use this compilation only on Windows platform for now, not tested on linux.
On Linux I recommend use PKG_CONFIG tool to discover PJSIP for your app.
Having peeked at their repository, the project is auto-tools/configure based. You would need to port the build system yourself. Depending on complexity, it is not that hard to accomplish. I have converted many projects to cmake. Maybe the pjsip comunity would welcome an upgrade to their build system, as I see they support multiple platforms like iphone, and windows through visual studio.
If you are using Clion IDE then it can automatically generate cmake file for pjproject. Just import it and it will open a wizard. You’ll need to specify the location of the sources, then select project files and include directories. Clion has the ability to make the cmake file from existing projects. for more help please see this link Clion Documentation