Can you please tip me if this project/cmake structure is best practice or not?
There are none, or endless, best practices, and every day someone invents a new one. Especially as to how to structure your project, which is unrelated to CMake. Structure it in a way that you want, and you judge is the best. Your structure seems completely fine.
Look a look at endless google results. What’s a good directory structure for larger C++ projects using Makefile? and http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1204r0.html project.
As for CMake you can take a look at the ultimate https://github.com/friendlyanon/cmake-init , https://github.com/cmake-lint/cmake-lint , https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1 .
where i should use link_directories() and target_include_directories().
Generally you should prefer target
stuff, i.e. target_link_directories
over non-target.
Use target_include_directories
to add a path to #include <thishere>
search path.
Use target_link_directories
to add a library path to the search path target_link_libraries(... this_library_here)
. Usually you want to use add_library(... IMPORTED)
, then find_library
, instead of target_link_directories
. See man ld
.
In your project there are no external shared .so
nor static .a
libraries. I see no reason to use link_directories
at all.
how can I keep my codebase tidy and compile my project?
Well, you can work hard and cleanup your project often. Remember about regular exercise, sleep and to eat healthy.
Instead of set(CMAKE_CXX_STANDARD 11)
prefer target_set_properties(. .. CXX_STANDARD 11)
.
CLICK HERE to find out more related problems solutions.