我正在使用此CMakeLists.txt建立自己的库:
PROJECT (AstroLib)
cmake_minimum_required(VERSION 3.0)
set(AALib_VERSION_MAJOR 1 CACHE STRING "major version" FORCE)
set(AALib_VERSION_MINOR 95 CACHE STRING "minor version" FORCE)
set(AALib_VERSION ${AALib_VERSION_MAJOR}.${AALib_VERSION_MINOR} CACHE STRING "version" FORCE)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
include(GenerateExportHeader)
file(GLOB AALib_SRCS "AALIb/source/*.cpp")
file(GLOB AALib_Headers "AALIb/include/*.h" "AALIb/include/*.hpp")
message ("AALib_VERSION ${AALib_VERSION}")
message ("CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}")
message ("CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}")
add_library (AALib STATIC ${AALib_SRCS})
target_include_directories(AALib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/AALib/include>
$<INSTALL_INTERFACE:include>
PRIVATE AALib/source)
generate_export_header( AALib )
set_property(TARGET AALib PROPERTY VERSION ${AALib_VERSION})
install(TARGETS AALib EXPORT AALibConfig
LIBRARY DESTINATION "lib/${CMAKE_BUILD_TYPE}"
ARCHIVE DESTINATION "lib/${CMAKE_BUILD_TYPE}"
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/AALib_export.h" DESTINATION include COMPONENT Devel)
install(FILES ${AALib_Headers} DESTINATION include)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/AALib/AALibConfigVersion.cmake"
VERSION ${AALib_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(TARGETS AALib
FILE "${CMAKE_CURRENT_BINARY_DIR}/AALib/AALibConfig.cmake"
NAMESPACE Upstream::
)
install(EXPORT AALibConfig DESTINATION AALib/cmake)
set(FOO "rtatzera")
#configure_file(AALibTargets.cmake "${CMAKE_CURRENT_BINARY_DIR}/AALib/AALibConfig.cmake" COPYONLY)
set(ConfigPackageLocation lib/cmake/AALib)
message ("ConfigPackageLocation ${ConfigPackageLocation}")
install(EXPORT AALibConfig
FILE
AALibConfig.cmake
NAMESPACE
Upstream::
DESTINATION
${ConfigPackageLocation}
)
我用这个cmakelists.txt运行cmake-gui,我可以在我的计算机上构建和安装我的库。
现在我想在另一个项目中使用这个lib使用这个cmakelists.txt:
cmake_minimum_required(VERSION 3.0)
PROJECT (DataMeteo)
find_package(OpenCV REQUIRED)
find_package(AALib REQUIRED)
file(GLOB DataMeteo_SRCS
"*.h"
"*.cpp")
ADD_EXECUTABLE (DataMeteo ${DataMeteo_SRCS})
message ( "AALib = ${AAlib}")
if (OpenCV_FOUND AND AALib_FOUND)
target_link_libraries( DataMeteo PUBLIC ${AALIb_} ${OpenCV_LIBS})
else (OpenCV_FOUND AND AALib_FOUND)
message("OPENC not found or AALib NOT FOUND ")
endif (OpenCV_FOUND AND AALib_FOUND)
在VS项目中,我可以找到所有opencv库和包含但我找不到我自己库的include和lib。运行cmake-gui时没有错误。
我的代码(cmakelists.txt)中的错误在哪里?
配置Windows 10 64位VS2017 CMake 3.11.0