Good day, i searched answer, but not found yet. How to exclude properties from CMakeLists.txt to a separate file? Like it in gradle we have file gradle.properties where we can set paths etc. What is the best practices or official way?
Related
When cloning a repo on github I have made with lots of subfolders (like src,include and then several sub-directories in those) on a new PC I get a heap of errors that it can't find the paths for the include files. How do I quickly let Visual Studios know to look for include files in those sub-directories and not just the main folder where I cloned the repo?
Going into properties and choosing "include directories" I can manually select paths to look for include files, but I obviously don't want to manually add the dozens of sub-folders where include files can be found. Preferably I would like whoever is cloning the repo to not have to worry about this at all of course if there is something to do about this when creating the repo. Thank you!
The github repo for reference: https://github.com/OscarUngsgard/Cpp-Monte-Carlo-Value-at-Risk-Engine
And a picture of the "include directories" options I'm refering to in visual studios:
As far as I know there's no way to search for include files in subfolders. And it's obvious if this was possible it would not be relevant to do that as this will take more time to search them.
But you can do one thing, when including files just add their relative path
Such as
#include "../src/header_file.h"
After downloading JSON-CPP 0.5.0 and extracting it, I've no idea how to add it to my project on XCode. I couldn't find any steps online as well. Help please..
I've also tried the steps in ReadMe file. But stuck after installing SCons.
SOLVED:
Step1: Just add all the files inside the include directory and src/lib_json directory anywhere in the project. (.h, .cpp etc.,)
Step2: You have to change the include file paths from #include "json/writer.h" to # include "writer.h" everywhere. If you don't like the name "writer.h", you can very well rename it to "json_writer.h" or whatever.
Step3: In the project settings, under Build phases, add the cpp files(that you added in step1) in the "Compile Sources".
This question is more or less a warmup of this question:
how to get cmake to add files to msvcs solution tree
It never got a valid answer so I want to repose it slightly different:
Is it possible to use the cmake solution folders that where introduced with cmake 2.8.3 to add files directly to the vs solution? I want to do the cmake equivalent of VS->Solution->Add->Existing Item. So my file will appear in a folder that belongs to the solution and not to a project.
I found examples how the solution folders can be used to group targets into folders with code like this:
set_property( GLOBAL PROPERTY USE_FOLDERS ON)
set_property(TARGET ${TARGET_NAME} PROPERTY FOLDER "Test")
So can I add a file instead of a target to the folder?
This is probably not possible.
CMake organizes its assets into projects and targets. The project is what corresponds to Visual Studio's solution file while each target will generate a Visual Studio project inside the respective solution.
The problem is now that CMake does not allow to add files to CMake projects. In fact, a CMake project is little more than a collection of targets and offers almost no customization options. Hence the USE_FOLDERS option you mentioned can only be used to group VS projects inside a solution, but not single files.
The closest to what you ask would probably be to add a custom target that holds your files. However, this will still generate a VS project (which also contains a bunch of other stuff besides your files) inside the solution and not a plain folder.
If I understand the question correctly, I think I know how to do it:
set(FILES_TO_ADD
file1
file2
file3)
source_group("Group Name" FILES ${FILES_TO_ADD})
The source_group command creates the folder inside the Visual Studio project.
This answer just adds an example for the "custom target" solution that was proposed by ComicSansMS in the accepted answer. This is what I currently use to add my global files.
set( SOLUTION_FILES
${CMAKE_SOURCE_DIR}/CMakeLists.txt # root CMakeLists file
${CMAKE_SOURCE_DIR}/cmake/macros.cmake # cmake functions
${CMAKE_SOURCE_DIR}/CMakeInCodeDefinitions.h.in # imported cmake variables
# etc...
)
add_custom_target( GlobalFiles SOURCES ${SOLUTION_FILES})
I have multiple solutions for different project I have worked on but the project I am currently working on rely on a class from a previous solution. I was wondering if there was an easy way to link these solutions together so I have access to all the previous classes.
The most maintainable way to do this is to add the source project's header file directory to your target project's include list.
In the project's configuration properties page, go to:
C/C++ -> General -> Additional Include Directories.
If the source project is compiled into a library, dynamic or otherwise, you will need to link with the corresponding .lib file.
To do this, go to "VC++ Directories" and add to the "Library Directories" field the path containing the .lib file.
Note that you can also add your source project's header directory in this page as well.
After that, go to Linker->Input and add your library's .lib file name.
You will now be able to #include<your_header_file.h>.
Note that you will need to be careful about the choice of directory, as files with the same names as standard or platform-specific headers will cause problems.
EDIT:
I do not know of a way to avoid editing the VC++ Directories page in the project's property page to add a library directory. Why is this a problem? Things like Intel's C++ composer like to step all over these fields (you have to let it make a mess, then you can clean it up).
for example I need to include a header
#include <OpenGL/glext.h>
while it is actually a header file glext.h under OpenGL.framework/Headers/.
Therefore it is no way to give eclipse a physical path about "OpenGL/glext.h", and I always get unresolved inclusion warning.
I can still build and run them (with managed makefile project) but it is impossible to browse the functions or definitions from those "resolved" header files.
is there any solution?
While not ideal, my solution to this has been to create a folder "/Developer/Framework Headers" (though the name isn't important), and link from e.g. "/System/Library/Frameworks/Foo.framework/Headers" to "Foo" under said folder. Then in Eclipse I add "/Developer/Framework Headers" to a project's includes.
I say not ideal because apart from having to create links for the frameworks you need and add an include to each project, Eclipse seems to have trouble in certain cases such as nested frameworks (e.g. CoreGraphics beneath ApplicationServices), but YMMV.
Yes there is one. Right click on the project in "Project Explore" window and click on the "property". In there Open "C/C++ General" column and choose "Path and symbols". Now you see all of the include library path for this project. If your using C then add the OpenGL library into GNU C, or if you use C++ then add it into GNU C++. Unfortunately you have to do this for every new project. I have been searching for a while how to do this by default but nothing really useful. Hope this help you get rid of those annoying yellow wave lines.
Since current Eclipse CDT releases don't perform sub-framework header inclusion correctly, you can avoid sub-framework problems (like those generated by the CoreServices header files) by creating symbolic links to the include directories of each sub-framework. I elaborated on this subject, which stems from danhan answer on this question, in this blog post.
In order to automate this process, I've created a Z shell script which automates this process and creates the symlink to the specified frameworks' header directory, together with the links to the include directory of each one of their sub-frameworks. The script can be found in this GitHub repository.
Hope this helps.