I'm new to CMake and I tried to do this in my root CMakeLists.txt :
set(HAVE_MY_SDK OFF)
if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}../Libs/A")
if(EXISTS "${PROJECT_SOURCE_DIR}../Libs/A/CMakeLists.txt")
set (HAVE_MY_SDK ON)
endif()
endif()
Currently, CMake is just avoiding the instruction, leaving HAVE_MY_SDK
in a OFF
status. Is it possible to check an higher level directory with CMake ? Or maybe doing it with an indirect method
if(<variable|string> STREQUAL <variable|string>) True if the given string or variable's value is lexicographically equal to the string or variable on the right.
Add a subdirectory to the build. Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.
CMake will use whatever path the running CMake executable is in. Furthermore, it may get confused if you switch paths between runs without clearing the cache. So what you have to do is simply instead of running cmake <path_to_src> from the command line, run ~/usr/cmake-path/bin/cmake <path_to_src> .
I think you're just missing a /
after ${PROJECT_SOURCE_DIR}
.
Out of completeness here is the code I use for this (note that if (EXISTS ...)
needs full paths):
get_filename_component(_fullpath "${_dir}" REALPATH)
if (EXISTS "${_fullpath}" AND EXISTS "${_fullpath}/CMakeLists.txt")
...
And here inside my extended add_subdirectory()
version (including a "add once guard"):
function(my_add_subdirectory _dir)
get_filename_component(_fullpath "${_dir}" REALPATH)
if (EXISTS "${_fullpath}" AND EXISTS "${_fullpath}/CMakeLists.txt")
get_property(_included_dirs GLOBAL PROPERTY GlobalAddSubdirectoryOnceIncluded)
list(FIND _included_dirs "${_fullpath}" _used_index)
if (${_used_index} EQUAL -1)
set_property(GLOBAL APPEND PROPERTY GlobalAddSubdirectoryOnceIncluded "${_fullpath}")
add_subdirectory(${_dir} ${ARGN})
endif()
else()
message(WARNING "my_add_subdirectory: Can't find ${_fullpath}/CMakeLists.txt")
endif()
endfunction(my_add_subdirectory)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With