Tôi không muốn thêm boost.cxx nếu cmake find_package không tìm thấy cài đặt tăng cường nào. Có find_package trả lại một cái gì đó mà tôi có thể bọc trong điều kiện để biên dịch boost.cxx hay không. Đây là tệp cmake hiện tại của tôi:Cách kiểm tra xem find_package có tìm thấy gói (tăng)
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)
Tuyệt vời! Bạn đã làm tất cả công việc này cho tôi, cảm ơn bạn! – Cynede
Hãy cẩn thận - biến Libname_FOUND phân biệt chữ hoa chữ thường và tất cả các mũ cho một số thư viện. Ví dụ. GTest_FOUND sẽ không được đặt mặc dù find_package (GTest) thành công. Thay vào đó, GTEST_FOUND được thiết lập (sử dụng cmake 3.0.2). –