Can't find CMake created executable file - cmake

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.

Related

Build gtest as shared library (dll) in CMake

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.

How to run c++ Files using g++ and Cmake?

I am using Header Only Libraries. The libraries are included through Cmake. I am using the g++ Compiler.
Now what I am looking for is to compile the c++ source files via windows cmd. In this moment i am using clion to compile.
Does anyone know how to compile the source files?
If i am compiling the files without cmake , I am getting errors because the program cannot find the libraries.
You do not run a source file, you run an executable produced by a compiler from source file(s)
If you are under a Linux for instance enter the path(s) where the libraries are through the environment variable LD_LIBRARY_PATH
[edit after your remark]
I mean compile
To indicate to g++ where the library are to link use the option -L followed by the path of a directory where the libraries are. If your libraries are on different directories use several time the option, one per directory

How to completely exclude a folder from compiling in CLion

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.

CMake for Code::Blocks -- how to NOT get a Makefile

Here is my setup:
Windows 7 x64, MingW, Msys, CMake, Freescale Kinetis SDK, Code::Blocks
I'm trying to get the project settings established by CMake into a proper Code::Blocks project. When I modify the provided build_debug.bat file with -G "CodeBlocks - Unix Makefiles", it indeed produces a .cbp file, as well as the normal Makefile (and it builds the project). However when I open this .cbp file in Code::Blocks, it basically just points to the Makefile, and building the project just runs make on the Makefile.
If I deselect "This is a custom Makefile" from Project Options, and add a source file to the project tree like a normal IDE, it doesn't get built correctly, ie the include files, libraries, linker stuff, compile options, etc., are not imported into the project itself. It seems the project is basically just a holder for the Makefile, so there is not much benefit to this as an IDE.
Of course if I add the source file to the original CMakeLists.txt which is part of the distribution, and rerun cmake (via the build_debug.bat file), then it works fine.
So is there any way to get a "real" IDE configuration out of CMake? I'm guessing the answer is No, since a "real" IDE configuration is a static thing, and a Makefile is a general (Turing complete) program, so there is no way in general to create this automatically, although I suspect for 99% of cases you're just specifying include directories, lib files, and compiler options, so no general programmability is truly needed.
I can probably try to figure out where the deeply obscured gcc calls are getting their include files from, what libs are being linked in, and what compile options are being used, and add all that stuff manually into a native Code::Blocks project, but this seems to defeat the purpose of having this already done for me by the package providers, and gets very tedious when building for a different CPU or development board.
Thanks
"Real configuration" is a CMakeLists.txt, and you need to modify CMakeLists when you editing project configuration. Both makefiles and IDE settings generated by CMake are temporary and you should not edit them.
Some IDEs are able to manage project configuration directly in the CMakeLists.txt

Specifying build directory within CMakeLists file

Is it possible to specify build directory within CMakeLists file? If yes, how.
My aim is to be able to call "cmake" within top level source directory and have cmake figure out the build directory.
Afaik, with CMake the build directory is always the directory from where you invoke the cmake or ccmake command. So if you want to change the build directory, you have to change directories before running CMake.
To control the location where executables, static and shared libraries are placed once finished, you can modifiy CMAKE_RUNTIME_OUTPUT_DIRECTORY, CMAKE_ARCHIVE_OUTPUT_DIRECTORY, and CMAKE_LIBRARY_OUTPUT_DIRECTORY respectively.
By design, there is not a way to specify that in CMakeLists.txt. It is designed for the user to be able to build the project in whatever directory they want. The typical workflow is:
Check out the project source code.
Go to desired build directory, or the source dir if you plan to do an in-source build.
Run cmake or ccmake to configure the project in that build directory.
Build your project.
All of the directories specified within your CMakeLists.txt should be relative to the ${PROJECT_BINARY_DIR} and ${PROJECT_SOURCE_DIR} variables. In this way, your code becomes buildable across different platforms, which is the goal of CMake.