Compile & Run CLion Project from Terminal - makefile

I am trying to create generally-accessible compile & run instructions for my CLion project, but can't find the exact terminal command it uses to execute the program (it's makefile, I would assume). From the project directory in the terminal, how would I do this?
The directory looks like this:

I will add a little bit to #Stanley F.'s excellent answer.
FROM the root of the CLion project, this is what works for me. I generally run with a debug profile. The same can be reproduced for release.
When cmake loads its project, it runs
cmake -Bcmake-debug-build -H. ${CMakeOptions}
where CMakeOptions is stored in CLion at
CLion->settings->Build,Execution, Deployment->CMake->[profile]->CMake Options
My general cmake build option is
-DCMAKE_BUILD_TYPE=debug -DSYTEM_ARCH=Linux-gcc5.3.0-x86_645 -CMAKE_CXX_STANDARD=14
[Note the lower-case d for 'debug'. If I do not use this, my system will not work. I wish that CLion did not default to 'Debug']
So, to reproduce what CLion creates upon project reload, I run
rm -rf cmake-debug-build
cmake -Bcmake-debug-build -H. -DCMAKE_BUILD_TYPE=debug -DSYTEM_ARCH=Linux-gcc5.3.0-x86_645 -CMAKE_CXX_STANDARD=14
Then, to build the project, I run
cmake --build cmake-build-debug --target all
Please note that when I run the first cmake command (from CLion or the command line), cmake pulls in lots of libraries from other "precedent" projects as part of the processing of my CMakeLists.txt file. If anything in one of those precedent projects changes, I will not pull them in anew, unless I physically delete the entire cmake-build-debug/ directory. None of CLion's reset tool menu items from my experience will delete that file.
If I am running these commands from the CLion menus, then I have to physically delete the cmake-build-debug/ directory as well (if I have a change in one of the external libraries that I want to pull in).

CLion currently only supports CMake projects. So you have to invoke the CMake executable with the appropriate parameters for your project.
At first, you can delete the cmake-build-debug folder, since this is auto-generated by CLion, which itself invokes CMake. It only contains temporary files.
So your build environment basically contains the 3DTable.c, 3DTable.h and CMakeLists.txt files. At least this is what I get from the screenshot.
To build the project from command line, first navigate to the source directory. Then invoke CMake:
cd <source path of Project_1>
cmake -Bbuild -H.
cmake --build build --target all
Notes:
build is the directory, where CMake will generate temporary files and the build artifacts.
The -H. option tells CMake, where the CMakeLists.txt file is located, which in this case is the current working directory.
The library / executable for your project will be located within the build directory

CLion can tell you, you don't need to hunt.
CMake command line
Select tools\cmake\reload cmake project.
The command line is shown in the CMake window.
Build command line
Select build\build project.
The command line is shown in the messages window.
Example
Mine look like this:
"C:\Program Files\JetBrains\CLion 2021.2.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2021.2.2/bin/ninja/win/ninja.exe" -G Ninja -S C:\some_application -B C:\some_application\cmake-build-debug
...
"C:\Program Files\JetBrains\CLion 2021.2.2\bin\cmake\win\bin\cmake.exe" --build C:\some_application\cmake-build-debug --target all -j 9
Reminder
If using Visual Studio you still to specify which environment you are using. Typically this involves using the VS command prompt or executing one of the premade scripts to set up the environment variables. See here.

Related

openJPEG installation: $ make make: *** No targets specified and no makefile found. Stop

So.
Coming from
OpenJPEG installation
The build method maintained by OpenJPEG is CMake.
UNIX/LINUX - MacOS (terminal) - WINDOWS (cygwin, MinGW)
To build the library, type from source tree directory:`
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
https://github.com/uclouvain/openjpeg/blob/master/INSTALL.md
After properly getting Cmake to build, mingw-get to get msys-make (and also msys 1.0) to even have a proper response from MingW64, no matter what I do, I am stuck in the same error.
Downloaded first from the openjpeg-v2.3.1-windowsx64 link which the above proceeding seems to do nothing, as there is no CMakeList file there, then from the 'Source Code' openjpeg-2.3.1 which I can build from but that's it.
Can't make, can't install, can't use.
Considered 'source tree folder' the downloaded folder itself, the src folder inside of it and even a src folder of a IntelliJ project.
What am I missing?
PATH VARIABLE: %USERPROFILE%\AppData\Local\Microsoft\WindowsApps;
%IntelliJ IDEA Community Edition%;
C:\Users\Ajna\Desktop\jar2app\jar2app\jar2app_basefiles;
C:\Program Files\CMake\bin;
C:\Program Files\Git\mingw64\bin;
C:\MinGW\bin;
C:\Program Files\ffmpeg-4.2.1-win64-static\bin;
C:\msys\1.0\bin;
I've spent quite a while with this myself today. Here's what worked for me.
Download the whole code folder (green download code button) from
https://github.com/uclouvain/openjpeg
The downloaded folder is called "openjpeg-master". Save it in your downloads folder.
Install MinGW from https://www.ics.uci.edu/~pattis/common/handouts/mingweclipse/mingw.html
Install msys from
https://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.11/MSYS-1.0.11.exe/download?use_mirror=altushost-swe
Open windows command line.
Navigate to the location of the "openjpeg-master" folder
e.g.
cd C:\#insert_location_of_your_downloads_folder#\Downloads\openjpeg-master
To specify the use of MinGW makefiles on windows use the following command
mkdir build
cd build
cmake -G "MinGW Makefiles" .. -DCMAKE_BUILD_TYPE=Release
make
The default for cmake on Windows is to use a Visual Studio generator: it generates project files for use with Visual Studio, not makefiles.
If you want it to generate makefiles you have to tell it specifically:
cmake -G 'Unix Makefiles' .. -DCMAKE_BUILD_TYPE=Release
You probably want to file an issue with the project and ask them to update their INSTALL file to have proper instructions.

CodeLite with CMake does not execute make when building

I just switched to CodeLite for C++ development.
I followed the QuickStart guide and created a simple console executable (g++), and when setting up a new project, you can choose the Build System, which offers the options
Default
CMake
GNU makefile onestep build
NMakefile for MSVC toolset
If I choose "CMake", and leave everything else the way it is, I get my usual hello world code in main.cpp.
Now I want to build it. I execute CMake, which produces a makefile, and then execute "Build" (by pressing F7 or via the menu). That does not work:
C:\Windows\system32\cmd.exe /C cd "\\"C\Users\Username\Documents\CodeLite\WorkspaceName\cmake-build-Debug"\ProjectName" && C:/mingw/mingw64/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e
"\\C\Users\Username\Documents\CodeLite\WorkspaceName\cmake-build-Debug\ProjectName"
CMD unterst_tzt keine UNC-Pfade als aktuelles Verzeichnis.
====0 errors, 0 warnings====
The last line says it does not support UNC paths. Not sure whether that's the problem, but anyway, nothing actually gets built.
However, if I simply open a command line in the cmake-build-Debug\ProjectName\ directory, I can execute "make" and my executable is built properly.
Now my question is: Why does CodeLite not build my project? This does not seem to work as intended. I did not change any settings and my project is a clean default, but yet, I have to build it manually.
If I simply choose "Default" instead of "CMake", it gets build, by the way.
A path in UNC (universal naming convention) has \\ before the host name and then the drive, directory, ... letters.
The path "\\C\Users\Username\Documents\CodeLite\WorkspaceName\cmake-build-Debug\ProjectName" does not look like a proper (UNC or other) path. Was it written this way by the CodeLite build system or did you need to do this manuully?
The form "C:\Users\Username\Documents\CodeLite\WorkspaceName\cmake-build-Debug\ProjectName" (or "C:\Windows\Users\ ...") should work on your system.

How to create a Code::Blocks project from the cmake file?

I would like to use the Code::Blocks IDE to build a C++ project based on a CMakeLists.txt file. Previously, I was using Qt Creator, where I could open a CMakeLists.txt file directly, which would create a project. I could then define the build commands, eg. cmake ../src followed by make -j8. This would run cmake on the CMakeLists.txt file, and then run make on the makefile.
How can I do something similar in Code::Blocks? If I try to create a new project, it gives me the option of creating an empty project, but then I am stuck as to where to go next...
It's similar but you have to specify the compiler, supposing that you have a folder project/build and project/src and your CMakeLists.txt is under /project. Then your commands should be something as the following :
$ cd build/
$ cmake .. -G"CodeBlocks - Unix Makefiles"
you will have your CodeBlocks project created on the /build.
Code::Blocks, has its own .cbp files which do the same things as Makefile automatically.
Therefore Code::blocks canot generate a Makefile, but you can build your project from an alredy existing Makefile, i've found a very good explaination of it on the code::blocks wiki. I do hope this will help you :)

Create XCode workspace and pin a project from command line

I found that it is possible to create XCode project from command line with a help of CMake (are there any other options?). Is there any tool to create XCode workspace and pin projects into it?
If not, can I create it manually? My current version of XCode (7.3 beta) makes a workspace that consists of below file structure:
WORKSPACE_NAME.xcworkspace/
contents.xcworkspacedata
xcuserdata/
USER_NAME.xcuserdatad/
UserInterfaceState.xcuserstate
Content of contents.xcworkspacedata looks straightforward and I guess this is the file that pins projects into workspace.
UserInterfaceState.xcuserstate is a binary file that can be generated when workspace is opened in XCode.
Summing up, if there is no command line tool for creating workspace and pinning projects into it, can I just generate proper contents.xcworkspacedata file or should I do something more?
If your project has a CMakeLists.txt file, CMake can generate an XCode project file from it (on the command line), and you can then build it as well (from the command line).
Assuming you are currently in your project's source directory and it contains a CMakeLists.txt:
$ mkdir build && cd build
$ cmake -G "Xcode" ../
$ cmake --build .
Alternatively you can remove the -G option, it'll then generate a Makefile, and then you can do make and it will build on the command-line too, using the Xcode build tools.

cmake generate Xcode project from existing sources

This is what I have, when I started generation:
iMac:IXCSoftswitch alex$ /usr/bin/cmake -G Xcode .
-- CMAKE_SOURCE_DIR = /Users/alex/Desktop/ixc-v/IXCSoftswitch, CMAKE_BINARY_DIR = /Users/alex/Desktop/ixc-v/IXCSoftswitch
CMake Error at CMakeLists.txt:25 (MESSAGE):
Binary and source directory cannot be the same
-- Configuring incomplete, errors occurred!
How can I fix it? I'm new to CMake, samples appreciated.
CMake is used to produce out-of-source builds.
The idea here is that you don't mix the files created during compilation with the original source files. In practice, you usually run CMake from a new, empty build directory and give the path to the source directory as an argument.
cd IXCSoftswitch
mkdir build
cd build
cmake -G Xcode ..
All of the files generated by CMake (which could be a lot) will now go into the build subdirectory, while your source directory stays clean of build artifacts.
The concept of out-of-source builds may seem strange at first, but it is actually a very convenient way of working once you get used to it.
From the root of your project directory.
cmake -G Xcode -H. -B_build
This is similar to the answer above. However, you are manually managing the out of source build. -B sets your target build directory (I happen to prefer _build). I tried looking up -H to double check, but couldn't find it. If memory serves, it specifies where your CMakeLists.txt lives.
I keep this command in a .sh/.bat file (depending). This way, I can keep my scripts that build my project in the root where a new person can easily find them.

Resources