I\'m writing a Cross-compiling Toolchain file for VxWorks. Since it\'s an unknown system to cmake a also have write platform files (those in ../Modules/Platform
CMake modules can include each other, so it can lead to diamond problem. If you are lucky, you've got double work for setting some variables, but if you will need some complex stuff, things may get worse.
Example:
FindB.cmake
find_package(A)
FindA.cmake
find_package(B)
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
find_package(A) # include FindA.cmake, which include FindB.cmake
# which include FindA.cmake ....
Now run cmake .
-- The C compiler identification is Clang 4.2.0
-- The CXX compiler identification is Clang 4.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
Segmentation fault: 11
Just use guards at beginning of the module (let variable describe path to prevent collision)
FindB.cmake
if(FIND_B_CMAKE)
return()
endif()
set(FIND_B_CMAKE 1)
find_package(A)