Zs.Gabor
Zs.Gabor

Reputation: 3

How to create proper Find***.cmake file

I wrote a simple Find***.cmake file for my project which works fine on Windows,

if(WIN32)
    find_path(Shaderc_INCLUDE_DIR
            NAMES shaderc/shaderc.hpp
            PATH "$ENV{VULKAN_SDK}/Include")
    find_library(Shaderc_LIBRARY
            NAMES shaderc_combined
            PATH "$ENV{VULKAN_SDK}/Lib")
elseif(UNIX)
    find_path(Shaderc_INCLUDE_DIR
            NAMES shaderc/shaderc.hpp
            PATH "$ENV{SHADERC_DIR}/include")
    find_library(Shaderc_LIBRARY
            NAMES libshaderc_combined
            PATH "$ENV{SHADERC_DIR}/lib")
endif()
set(Shaderc_INCLUDE_DIRS ${Shaderc_INCLUDE_DIR})
set(Shaderc_LIBRARIES ${Shaderc_LIBRARY})

, but throws an error on Linux. The error message is:

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: Shaderc_LIBRARY

If I copy this code to my main CMakeLists file it compiles fine on Linux as well. What I'm doing wrong? Is it a bad practice to use environment variables on Linux for this purpose?

Thanks for your help!

Upvotes: 0

Views: 967

Answers (1)

arrowd
arrowd

Reputation: 34411

Well, judging from the code, your module looks in directories specified by environmental variables.

Instead, you should make it search in well-known places, like /usr/lib or /usr/local/lib.

Upvotes: 1

Related Questions