I’m new to CMake. Trying to read up on best practices and common concepts.
One thing which eludes me is how to be able to provide CMake with paths for external libraries such that find_library finds them. The documentation refer to a number of variables used by CMake, but I’m struggling to work out which ones to use when.
Example, I have a project where I need external libraries. These libs cannot be bundled with my project so it must be supplied by the system/user somehow. (I’m targeting Windows and Mac)
To avoid hard coding paths that relate to my own machine I’m trying to figure out how to pass the appropriate directories to the project and using find_library and find_path.
One thing I tried, (using VSCode along with the CMake Tools extension) was to set the user config to:
Never mind, the below quote gave me insight into what you’re asking:
Indeed, using find_*() is the best approach to make your project cross-platform. And as I said above, machine-specific settings should be passed on the command line rather than hard-coded in your project.
That said, you can use the -C argument to pass a script file that automatically sets your system-specific variables, or write a shell script that passes them to CMake automatically, to avoid having to repeat them every time you configure your project.