Ich möchte boost.cxx nicht hinzufügen, wenn cmake find_package keine Boost installiert gefunden hat. Gibt find_package etwas zurück, das ich in Bedingung umwandeln kann, um boost.cxx zu kompilieren oder nicht. Hier ist meine aktuelle cmake-Datei:Wie überprüft man, ob find_package das Paket gefunden hat (boost)
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)
Super! Du hast all diese Arbeit für mich gemacht, danke! – Cynede
Seien Sie vorsichtig - die Libname_FOUND-Variable unterscheidet zwischen Groß- und Kleinschreibung und Großbuchstaben für einige Bibliotheken. Z.B. GTest_FOUND wird nicht gesetzt, obwohl find_package (GTest) erfolgreich ist. Stattdessen wird GTEST_FOUND festgelegt (mit cmake 3.0.2). –