From the course: Advanced C++: Building Projects with CMake
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Conditionally including libraries based on platform - C++ Tutorial
From the course: Advanced C++: Building Projects with CMake
Conditionally including libraries based on platform
- [Instructor] We can conditionally include libraries that might only be available on specific platforms. Here we will first check if we can find GDI+ on Windows. Then we'll check for the Image I/O framework on macOS and finally, we'll check for libpng on Linux. This approach allows our code to take advantage of platform-specific libraries when they are available, but still function correctly when they are not. The target compile definitions let our C++ code know which libraries are available and use them to load platform-specific formats. Sometimes we want to give users the option of whether to use certain dependencies. We can use CMiC options for this. Here, IL-enabled enhanced formats is set to on. If no initial value is provided, the default value is Boolean off. We can use this variable to control finding and enabling enhanced image support libraries. Users can enable or disable this feature when running CMiC. Here we are invoking CMiC with the -D flag, followed by the variable…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.