English 中文(简体)
如何检查是否发现包裹(boost)
原标题:How to check if find_package found the package (boost)
  • 时间:2012-04-19 11:25:36
  •  标签:
  • cmake

如果四分五裂发现包装没有安装动力,我不想增加升值。 是否找到了包裹式回馈,这是我有条件汇编的。 这里是我的现成 cm子:

add_executable (complex complex.cxx lexer.cxx boost.cxx ../../src/lili.cxx ../../src/lilu.cxx)

# Make sure the compiler can find all include files
include_directories (../../src) 
include_directories (.)

# Make sure the linker can find all needed libraries
# rt: clock_gettime()
target_link_libraries(complex rt)

# Install example application
install (TARGETS complex
         RUNTIME DESTINATION bin)

IF(UNIX)
    find_package(Boost COMPONENTS system filesystem REQUIRED)

    ## Compiler flags
    if(CMAKE_COMPILER_IS_GNUCXX)
        set(CMAKE_CXX_FLAGS "-O2")
        set(CMAKE_EXE_LINKER_FLAGS "-lsqlite3 -lrt -lpthread")
    endif()

    target_link_libraries(complex 
      ${Boost_FILESYSTEM_LIBRARY}
      ${Boost_SYSTEM_LIBRARY}
      #${PROTOBUF_LIBRARY}
    )
ENDIF(UNIX)
最佳回答

<代码>FindXXX scripts be set a changing <Packagename>_FOUND to TRUEif the Pack was found. 因此,如果发现升幅,它将制定<条码>Boost_FOUND。

在编辑<条码>Boost.cxx时, 我假定,你也需要布局负责人,因此,你也应调整包括名录。 * E/CN.6/2009/1。

寻求帮助,然后才能使你获得迫害。 Furhtermore, 你需要在添加可起诉的目录之前确定您的名录。

IF(UNIX)
    find_package(Boost COMPONENTS system filesystem REQUIRED)
    # IF( Boost_FOUND ) # checking this variable isnt even necessary, since you added
                        # REQUIRED to your call to FIND_PACKAGE
        SET( BOOST_SRC_FILES boost.cxx )
        INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} ) # you could move this down as well
                                                     # as ${Boost_INCLUDE_DIRS} will be
                                                     # empty if Boost was not found
    # ENDIF()
ENDIF()

add_executable (complex complex.cxx lexer.cxx ${BOOST_SRC_FILES} ../../src/lili.cxx ../../src/lilu.cxx)

# Make sure the compiler can find all include files
include_directories (../../src) 
include_directories (.)
# INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} ) # alternative location to 
                                               # add include dirs, see above

# Make sure the linker can find all needed libraries
# rt: clock_gettime()
target_link_libraries(complex rt)

# Install example application
install (TARGETS complex
         RUNTIME DESTINATION bin)

IF(UNIX)

    ## Compiler flags
    if(CMAKE_COMPILER_IS_GNUCXX)
        set(CMAKE_CXX_FLAGS "-O2")
        set(CMAKE_EXE_LINKER_FLAGS "-lsqlite3 -lrt -lpthread")
    endif()

    target_link_libraries(complex 
      ${Boost_FILESYSTEM_LIBRARY}
      ${Boost_SYSTEM_LIBRARY}
      #${PROTOBUF_LIBRARY}
    )
ENDIF(UNIX)

注: 由于你在找Boost时使用QUIRED的旗帜(因为你只需要放在Unix平台上),因此,使用optional-source-files-in-a-variable trick甚至足够了。

(*) 由于你的问题,我刚刚发现,在用<条码>确定目标之前或之后,是否打上了<条码>。 ADD_EXECUTABLE 或ADD_LIBR /code>,因为同一项目的所有目标都增加了这些目录。

问题回答

是的,如果<条码>限定的-包装(Boost CompONENTS系统文档系统REQUIRED)成功,<条码>Boost_FOUND即行。

此外,还将有具体构成部分的版本,例如Boost_date_time_FOUNDBoost_filesystem_FOUND等。

更多信息

cmake --help-module FindBoost

是的,它规定了可变的<代码>Boost_FOUND。 FindBoost.cmake的例子:

 == Using actual libraries from within Boost: ==
#
#   set(Boost_USE_STATIC_LIBS        ON)
#   set(Boost_USE_MULTITHREADED      ON)
#   set(Boost_USE_STATIC_RUNTIME    OFF)
#   find_package( Boost 1.36.0 COMPONENTS date_time filesystem system ... )
#
#   if(Boost_FOUND)
#      include_directories(${Boost_INCLUDE_DIRS})
#      add_executable(foo foo.cc)
#      target_link_libraries(foo ${Boost_LIBRARIES})
#   endif()




相关问题
Why can t CLion see header files, WSL2 toolchain?

My setup: Windows 10 Pro 22H2 (19045.2965) CLion 2020.1.3 (JetBrains) WSL2 with Ubuntu 22.04.2 LTS gcc 11.3.0 cmake 3.22.1 gdb 12.1 gmake 4.3 CMakeLists.txt cmake_minimum_required(VERSION 3.22)...

CMake linking problem

I am trying to use CMake to compile a C++ application that uses the C library GStreamer. My main.cpp file looks like this: extern "C" { #include <gst/gst.h> #include <glib.h> } int main(...

How to add an extra plist property using CMake?

I m trying to add the item <key>UIStatusBarHidden</key><true/> to my plist that s auto-generated by CMake. For certain keys, it appears there are pre-defined ways to add an item; ...

(c)make - resursive compile

Let s assume I have directories like: dir1 main.cpp dir2 abc.cpp dir3 def.cpp dir4 ghi.cpp jkl.cpp And let s assume that main.cpp ...

Reading registry values with cmake

On a Windows 7 machine I cannot read any registry values that contain a semicolon. For example if you have 7-zip, running the following SET(MYPATH [HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip;Path]) ...

Finding the correct Python framework with cmake

I am using the macports version of python on a Snow Leopard computer, and using cmake to build a cross-platform extension to it. I search for the python interpreter and libraries on the system using ...

热门标签