cmake DEFINED does not seems to recognize variable

后端 未结 1 330
暗喜
暗喜 2020-12-10 12:11

I have this code in cmake:

#mandatory
SET(BOOST_DIR \"$ENV{BOOST_HOME}\")
if (DEFINED ${BOOST_DIR})
    #global include directories
    include_directories($         


        
相关标签:
1条回答
  • 2020-12-10 12:30

    You need to avoid dereferencing the variable BOOST_DIR in the if statement:

    set(BOOST_DIR "$ENV{BOOST_HOME}")
    if(BOOST_DIR)               # <--- Use 'BOOST_DIR', not 'DEFINED ${BOOST_DIR}'
        #global include directories
        include_directories(${BOOST_DIR})
    else()
        message(STATUS "BOOST_HOME at ${BOOST_DIR}")
        message(FATAL_ERROR "Undefined BOOST_HOME env var.")
    endif()
    

    By dereferencing BOOST_DIR, you're effectively querying if CMake has a variable called /home/ferran/boost defined.

    0 讨论(0)
提交回复
热议问题