How do you use cmake in a project? Suppose the project is named as “myllvm” and has only one file: log.c and you have decided to use “gcc” to compile the C file.
This is the simplest CMakeLists.txt to get started:
The directory only have two files: log.c and CMakeLists.txt
To build the binary: either clang or gcc can be used, how to configure that?
First “mkdir build” and “cd build” and then issue the following command to use gcc to compile:
Otherwise, you can use clang (ie, replace the “gcc” with “clang”).
But it is also possible to modifiy CMakeLists.txt to have “gcc” specified inside.
How to add new directories with new C files? (the subdirectory is call “core”):
add_subdirectory(core)
How to add header directory into the compilation?
include_directories(include)
How to add multiple C or CPP files in “src” subdirectory?
#set(SOURCES src/mainapp.cpp src/Student.cpp)
#or just a widcard:
file(GLOB SOURCES “src/*.cpp”)
For more complete list of commands (for CMakeLists.txt) we can dig into cmake source codes and looking into “Help/command” directory. Or the commands are listed here:
And when you do a “cmake -G <generator>“ these are the generate currently available (under Help/generator directory):
How to make use of the available cmake recipes written for each different platform:
For example here some Linux related cmake recipes:
And here are the Windows related cmake templates:
How to use the cmake recipes for different common tasks (eg, finding nvidia cuda compiler, find header files, etc) which are called Modules.
For example of a subtasks, these are all the “finding compiler” related modules (left hand side number is the number of lines for the file – a good representation of the complexity of the tasks it is handling):
Here are a complete list of all the tasks:
For more complete tutorial examples:
https://gitlab.kitware.com/cmake/community/wikis/Home
https://cmake.org/cmake/help/latest/index.html
https://stackoverflow.com/questions/44722714/including-c-file-linking-with-cmake-isnt-working-with-c-cannot-include-funct
You must be logged in to post a comment.