Cmake "set" does not work with the same variable after calling "find_path"

Inside the Cmake module, I am trying to find different paths. In some cases, I would like to "set" a variable after I originally named "find_path" the same variable:

# general search for this include dir
find_path(LIBRARY_INCLUDE_DIR
  NAMES LibraryName/LibraryHeader.h
)

# specific option enabled by user
if(USE_OTHER_LIB)
find_path(OTHER_LIB_ROOT_DIR
  NAMES OtherLib/OtherLib.h
)
set(LIBRARY_INCLUDE_DIR ${OTHER_LIB_ROOT_DIR}/database/include)
endif(USE_OTHER_LIB)

This approach worked fine under Windows XP (CMake 2.8.1). However, it did not work on Mac OS 10.6 (CMake 2.8.3). Does anyone know if there is a difference between the mac / windows version and how to resolve it?

Thank you so much!

+3
source share
1 answer

This is a common misconception regarding the set and CMake variables.

Line:

set(LIBRARY_INCLUDE_DIR ${OTHER_LIB_ROOT_DIR}/database/include)

LIBRARY_INCLUDE_DIR, CMakeLists, . cmake-gui ccmake .

, , , :

set(LIBRARY_INCLUDE_DIR ${OTHER_LIB_ROOT_DIR}/database/include)
set(LIBRARY_INCLUDE_DIR ${LIBRARY_INCLUDE_DIR} CACHE FILEPATH "" FORCE)

, , , , cmake-gui, FORCE-d. ... , : FORCE.

, , CMakeLists.txt:

message(STATUS "LIBRARY_INCLUDE_DIR='${LIBRARY_INCLUDE_DIR}'")

... , , - , , - . , ... , .

+5

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


All Articles