Reputation: 2021
I have been trying to build my project with CMakeLists for a couple of days now with some success but I'm not sure on what it is exactly that I am doing.
I am currently using 5 external libraries. (Assimp, glew, glfw, glm, DevIL) And my main platform is windows but platform independence is a big plus.
So the question I have is how to proceed when I want to include an external library to my project?
This is what I think I know so far.
(1) If you are "lucky" you can just use find_library and link it with target_link_libraries you are good to go.
(2) Since glm is a header only library, all I need is an include_directories.
(3) If the external library has its own CMakeLists, you do add_subdirectory and set include_directories to where the header files are.
This is what I know I don't understand.
(4) If the external library has .h files and .cpp files but no CMakeLists. How do I include (and build?) this library?
(5) (This is the most important question for me!) If the external library has .h files and either .lib or .dll files, how do I include this library? In both cases! (lib/dll)
Thanks in advance for any and all replies!
Best regards Edvin
Upvotes: 4
Views: 5262
Reputation: 7809
If you want to do the quick-and-dirty way you can just
CMakeLists.txt
of you main project (well, relative to super-repo root)If a dependency has no CMakeLists.txt
or any other build script suitable for your system, you need to find or write one.
find_package
commands and you list your dependencies with the target_link_libraries
command and all other details will be taken care by the config modules.Generally you don't need to include third-party projects directly into your main project's CMakeLists
(add_subdirectory
or ExternalProject_add
) since you will not be working on them so they will not change. There's no need to clutter your IDE workspace with them. It's best to download/clone/build/install them with a separate script before you configure your main project.
Upvotes: 2