How to create a simple CLion C++ CMake project with different locations for Project itself, build products and source files - c++

I'm new with CLion and CMakeList. I'd like to have different locations for:
CLion project files
Build Files
Source and Header Files
When opening default projects all are located under the same directory tree
What are the steps to create such project ('Hello world')?

CLion project files
AFAIK, you can only set one global path for each jetbrains' IDE, by writing IDE_HOME\bin\idea.properties file.
Details can be found here.
Build Files
Settings -> Build, Execution, Deployment -> CMake -> Generation path
You can also set several paths for different build profiles there.
Source and Header Files
Add sources and include directories in CMakeLists.txt .

Related

Eclipse "Makefile Project with Existing Code" can't view nor open source files

I'm using Eclipse 2020-12 release under Linux. I installed C/C++ support.
I have a project that is configured by CMake, using Unix Makefiles generator.
Note that the source files are not in a sub-folder of the folder containing CMakeLists.txt and Makefile:
sde/
code/
cpp and header files
build/
CMakeLists.txt and generated Makefile
From Eclipse, I do File New -> Makefile Project with Existing Code, and then I pickup the folder where my Makefile was generated by CMake (sde/build).
Eclipse opens the project and I can build it from here. But the problem is that the "Project Explorer" tab of Eclipse does not list my source and header files. I see here the CMakeLists.txt and MakeFile, and if I open Makefile I see it has valid absolute paths to my source code files (.cpp and .h), however they are not present in the "Project Explorer". Is there any trick to have them be displayed?
Note: I see the same issue with every Eclipse release I could test (see comments)

Visual Studio C++ how to add header files in a prefix folder

I cloned a github C++ repository. The repository is not a VS project. So I manually created a VS C++ blank project and added the files from the repo to the project. The files are not copied. This is not the problem.
The repo directory looks like this:
include\NTL\*.h
src\*.cpp
*.h means a bunch of header files and *.cpp means a bunch of .cpp source files.
The problem is that the .cpp files have #include <NTL/*.h> and when I build, VS fails to locate the header files (No such file or directory). Adding the path to the include to the Include Directories in project properties didn't help.
EDIT: After some experimenting, I've found that the error has nothing to do with the prefix NTL in #include <NTL/*.h> but with whether the files are copied into project directory. Even though the files appear in VS project view, they must be copied into the project directory.
EDIT: The only way I've managed to get the project to compile is to put the whole NTL directory containing header files in project directory. Include Directories and Additional Include Directories in project properties don't seem to have any effect.
All previous No such file or directory errors were the result of some combination of:
Mismatching project properties Configuration and Platform
Some .h files were actually missing from NTL github repo, e.g. mach_desc.h.
The solution to the problem consists of the following:
Under project Properties > C/C++, add the path to the include to Additional Include Directories.
VS project has a separate set of properties for each combination of Configuration and Platform. Make sure that step 1 applies to the active Configuration and Platform. E.g. If the project's currently configured to build for Debug x64 (active Configuration:Debug and Platform:x64), make sure that step 1 applies to Debug x64, and not something like Release Win32 or Release x64, etc.
Use the Windows/Linux-specific zip package from the Downloads page of the official website https://libntl.org/download.html

How to add Include directories in Visual Studio while cross-compiling to a Raspberry Pi?

I'm working on a c++ project on my Raspberry Pi. I'm using Visual Studio 2017 to cross-compile the project to my Raspberry.
But when I try to compile the project, I get the error"cannot open source file" in lots of header files.
I already managed to compile simple projects, but now I need to Include Directories and I don't know the proper syntax to set, on Visual Studio's project properties page, the Include Directories to tell the compile where the header files are stored.
For the PCL library, e.g., I was able to include directories using '$(INCLUDE_PCL)'.
But when I try to include pi's directory '/usr/Include/ni' I can't correctly set the absolute path. Here's an screenshot of my properties page (https://ibb.co/G2dszrx). I haven't set the Linker directories yet, since I'm currently getting errors on the compiling phase.
Does anyone knows how to set absolute path to include directories correctly?
EDITED:
Trying to figure this out, I created a new project (Proj) in which I include the file 'try.cpp' stored in the raspberry's "home/pi/projects" folder. This project is in the "/home/pi/projects/Proj" folder.
In the project property page, I have:
Configuration Properties>General>Remote Build Root Directory --> ~/projects
Configuration Properties>General>Remote Build Project Directory --> $(RemoteRootDir)/$(ProjectName)
C/C++>General>Additional Include Directories --> $(RemoteRootDir)
When I compile the project this path gets created correctly, and the project is saved at the correct place, even if go further into more folders in the remote build project directory, but it can't find the include file "try.h".
How can Visual Studio know where to save the project using '$(RemoteRootDir)', but is not able to add that path include directory?
After some searching I managed to correctly add the Additional Include Directories, and Additional Libraries.
Firstly I was also using OpenNI, to work with the PCL. After many tries, I discovered that OpenNI was not correctly installed. So I managed to install it with apt-get.
Secondly, If you want to include the "/home/pi/someDIR" directory at the Raspberry device, just add "/home/pi/someDIR" to Visual Studio's additional include directories.
For you still trying to achieve this, Merlyn Oppenheim, from visual studio, set up a sample project using VS 2019 and Raspberry PI template -> https://github.com/merlynoppenheim/sample-rasp-inc-headers
For this sample project the Visual Studio properties page should have:
C/C++ -> General -> Additional Include Directories = '/home/pi/projects/vcpkg/packages/sqlite3_x64-linux/include;%(AdditionalIncludeDirectories)'
C/C++ -> Linker -> General -> Additional Library Directories = '/home/pi/projects/vcpkg/packages/sqlite3_x64-linux/debug/lib;%(AdditionalLibraryDirectories)'
C/C++ -> Linker -> Input -> Library Dependencies = 'wiringPi;sqlite3;pthread;dl'

CMake Xcode using wrong files in Issue Navigator

I generate an Xcode project from CMake that builds a static library and test executable.
After the library is built, there is a file copy operation that moves the headers to a central directory (an include folder next to the built library).
This directory is not listed in the header search paths for either project (I have verified this inside the Xcode project and CMakeLists files).
When I am working in the generated Xcode project, the Issue Navigator will open the files in the central directory instead of the files used to build the project.
Can anyone tell me why this happens and how I can fix it?
Thanks for your help.
Use a separate build directory. Create a new directory. Navigate to that in terminal and say :
cmake -G Xcode <path_to_source>

How to add specific header folders to Eclipse?

I have a c++ project in a unix environment, that has a CMakeLists.txt. I used Cmake to convert it into an Eclipse project and import it in Eclipse CDT. Now, it says it can't find files in #include "file.h" statements.
This project has more than 20 folders and some of these folders contain the headers. I went to Project Properties -> Include Path and Symbols and added them there, but they don't appear in the Includes folder in my project, after rebuild. I don't understand why is it such a heavy task to do something so simple..
You can specify include directories in the original CMakeLists.txt using the include_directories command and re-generate the Eclipse project. This has the advantage over specifying the include directories in Eclipse because it will work for other CMake targets as well.