# 防止重复引入 if(CART_ALREADY_INCLUDED) return() endif() set(CART_ALREADY_INCLUDED 1) # find_path 搜索包含某个文件的路径 # 如果在某个路径下发现了该文件,该结果会被存储到该变量中;如果没有找到,存储的结果将会是-NOTFOUND find_path(CART_DIRS NAMES CARTDll.dll CARTDll.lib PATHS ${CMAKE_SOURCE_DIR}/extlib/CART NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH ) set(CART_VERSION_MAJOR 1) set(CART_VERSION_MINOR 0) set(CART_VERSION_PATCH 0) set(CART_VERSION "${CART_VERSION_MAJOR}.${CART_VERSION_MINOR}.${CART_VERSION_PATCH}") find_path(CART_LIBRARY_DIRS NAMES CARTDll.lib HINTS ${CART_DIRS} ) find_path(CART_BINARY_DIRS NAMES CARTDll.dll HINTS ${CART_DIRS} ) set(CART_LIBRARIES GJDM::CART) add_library(GJDM::CART SHARED IMPORTED) set_property(TARGET GJDM::CART PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CART_INCLUDE_DIRS}) set_property(TARGET GJDM::CART APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_property(TARGET GJDM::CART APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(GJDM::CART PROPERTIES IMPORTED_IMPLIB_DEBUG "${CART_DIRS}/CARTDll.lib" IMPORTED_LOCATION_DEBUG "${CART_DIRS}/CARTDll.dll" IMPORTED_IMPLIB_RELEASE "${CART_DIRS}/CARTDll.lib" IMPORTED_LOCATION_RELEASE "${CART_DIRS}/CARTDll.dll " ) include(FindPackageHandleStandardArgs) # 如果找到所有需要的变量,并且版本匹配,则将CART_FOUND变量设置为TRUE find_package_handle_standard_args(CART FOUND_VAR CART_FOUND REQUIRED_VARS CART_DIRS CART_BINARY_DIRS CART_LIBRARY_DIRS CART_LIBRARIES VERSION_VAR CART_VERSION )