The goals of building CMake are conditionally based on the existence of a library

I have a large cross-platform project that needs to be built in different places; various user interface tools, sound APIs, etc. may be available in some places, and I'm trying to figure out how best to configure, which targets are configured based on which libraries are present.

The code I'm trying for this, for example:

find_library(PC_EGL EGL) find_library(PC_GLESv2 GLESv2) find_library(PC_Xxf86vm Xxf86vm) if (DEFINED PC_EGL AND DEFINED PC_GLESv2 AND DEFINED PC_Xxf86vm) add_executable(foo foo.cpp) target_link_libraries(foo ${PC_EGL} ${PC_GLESv2} ${PC_Xxf86vm}) endif() 

However, if I build it on a system that does not have libGLESv2, I get an error:

 CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: PC_GLESv2 linked by target "foo" in directory /path/to/platform 

The find_library documentation suggests that the PC_EGL_NOTFOUND variable should be set, but it is not (CMake 2.8.5). So what is the appropriate way to use find_library to determine if a target should exist at all? Seems to be using

 if (NOT PC_EGL MATCH "-NOTFOUND") 

is a bit fragile and inconvenient, so is there a better mechanism for determining the path of the CMake command based on the fact that the library was found at all?

+6
source share
1 answer

It's simple

 if(PC_EGL AND PC_GLESv2 AND PC_GLESv2) 

CMake considers 0 , FALSE , OFF , ANYTHING-NOTFOUND as false.

+9
source

Source: https://habr.com/ru/post/912350/


All Articles