Do (Cross-compile) platform files require an include guard?

后端 未结 2 793
忘掉有多难
忘掉有多难 2021-01-16 22:17

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

2条回答
  •  逝去的感伤
    2021-01-16 22:50

    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)
    

提交回复
热议问题