I want to basically have a "trash" folder in one of my CLion projects which I can just use to dump all .cpp or whatever files that I do not want to compile. So the files that I do want to compile will be in a "main" folder and if I feel like adding a new file, I can just copy it from the "trash" folder.
This can be done in Eclipse by simply making a new "empty project" but CLion doesn't seem to have that option.
Maybe some CMake code to exclude a directory since CLion primarily relies on CMake for project building?
I have found a solution to this. I simply added the following code to CMakeLists.txt
file(GLOB Sourcefiles Source/*.cpp)
add_executable(project_name ${Sourcefiles})
where "Source" is a folder at root level of the project folder; it will hold all the main files and "project_name" is simply the name of the project.
This way CMake just looks through that folder for files that are meant to be compiled and ignores everything else. This works great in CLion where I can use the "Reload CMake Project" option to tell CMake about new files added.
Related
I have never worked with CMake before, so please forgive any rookie mistakes. Most of the following working frame has been given to me by my project group.
The goal is to build GoogleTest into a .dll, to be used in different, indepentent parts of our project. I'm having troubles setting up CMake the right way.
The work-flow so far has been:
Clone gtest from git --> also downloads a CMake List file
Alter variables in CMakeCache.txt to have it produce a Code::Blocks project file
Compile the project file in Code::Blocks
So far, it produces a static library (.a files) that can be used in our project. I'm having troubles genereating .dll files.
Variables I have tried changing:
BUILD_SHARED_LIBS:BOOL=ON --> the files generated by Code::Blocks now have a .dll.a double extension
CMAKE_C_FLAGS and all the corresponding C++ flags where set to -DGTEST_CREATE_SHARED_LIBRARY=1 as given here
CMAKE_EXE_LINKER_FLAGS has been set to -shared to make the linker produce .dll files
I have worked my way through the GoogleTest documentation here and here but in both, building it into a .dll is merely a 2-sentence-topic.
As #Tsyvarev pointed out, the .dll files were created in a (very) different folder.
I have a third_party directory with another cmake project in it. How can I add includes and sources of that project into my project? I tried to use include third_party/project/CMakeLists.txt but it gives me error something like 'can't find directory "X"'. I thing its because when I use include() it doesn't change working directory to third_party/project but uses my root project's one. Directory "X" exists in that project I want to add. What can I do in that case?
This seems really basic. How can i add files to a project without having to manually edit the CMakeLists.txt.
For example source files in another directory
CLion parses the CMakeLists.txt and uses it to generate a project view, but I believe the only way to add files to the project is to edit the CMakeLists.txt to include those files. I expect that eventually this will change similar to the way IntelliJ integrates with a pom.xml file in a Java project, but for now you edit the CMakeLists.txt.
There is also a way to make CLion to add any cpp and h files (I don't know why don't they do it by default) and is to add this line:
file(GLOB SOURCES
*.h
*.cpp
)
and also edit the line of:
add_executable(ClionProject ${SOURCE_FILES} ${SOURCES})
In this example: ClionProject is actually the name of the project. SOURCES_FILES and SOURCES can be whatever you want.
Another good idea is to go to File -> Settings -> Build, Execution, Deployment -> CMake and tick on "Automatic reload CMake project on editing"
Here is a good starting tutorial: https://www.jetbrains.com/help/clion/2016.3/quick-cmake-tutorial.html
No other option. You have to edit the CMakeLists.txt. CLion is completely cmake based IDE. Even if you need to link external libraries, you need to edit the above-mentioned file. It doesn't work like in GUI based code-blocks for example.
How about right clicking the CMakeLists.txt editor tab, clicking "Open in -> terminal", typing ls or find or whatnot, and copy-and-pasting from there?
In the main folder of my project, I have a CMakeLists.txt file. Inside this file, I include (using add_subdirectory) another CMakeLists.txt file located in my header file directory. The responsibility of this second file is to add all of my header files to the project:
file(GLOB gl_nbody_HEADERS "*.h")
add_executable(gl_nbody ${gl_nbody_HEADERS})
However, this files causes an error:
CMake Error: CMake can not determine linker language for target:gl_nbody
CMake Error: Cannot determine link language for target "gl_nbody".
What is strange is that when I include the two lines causing this error in my main CMakeLists.txt file (modified to work correctly for the change in directory), it works fine.
What is going wrong here?
add_executable causes the creation of an executable target, meaning the compilation of a list of source code files into an executable binary.
In order for this to work, and have CMake select a suitable compiler, the list of source files must contain at least one file with a "compilable" extension, ie. .c, or .cpp, or .cxx....
I don't see why you are trying to compile an executable here, since you only seem to try to list header files for inclusion into a project (which only makes sense for IDE-based generators, such as Visual Studio).
Also, it is not recommended to use globbing of files in CMake, because if you add more files to your project, CMake cannot detect them automatically, and will not regenerate build files. Please list all files explicitely.
The proper solution here is to list the header files in the proper add_executable command call where you list the actual source files that you want to compile.
You might also want to use the source_group() command, that allows you to group files into folders in the generated Visual Studio solution, for example:
source_group(header_files ${gl_nbody_HEADERS})
I am new to Cmake, I was trying to build an executble program from a Fortran code using Cmake-GUI. As per the program instruction I created the Cmakelists.txt. I then launched the Cmake-GUI and nominated the source directory and binaries directory and then used the configure and generate options to create my executable file. Everything seemed to have ran ok. Howover, when I checked my bin folder the .exe file that i was hoping to find is nowhere to be seen, instead I have cmake_Install.cmake and Makefile in the binaries folder. I opened these file with a text editor and they seem to be script file. Can somebody please tell me what I should do with these files to create the executale file. or if this is a sign of the cmake build process failing.
I don't know CMake for fortran, but cmake in general will create the makefiles / visual studio projects etc. We cmake into a bin directory, then go in there and run make. It doesn't build the source, it builds the make files.
Did you build the source?
CMake just create the makefiles and projects structures to compile using a make tool. I don't know how to compile it for Fortran, but in Linux for a C++ project, I just have to open a terminal, go to the build folder (your bin folder) and run make or make all and it compile the whole project.
I think that your problem is that your project is not compiled, so there is not any binary files.