我正在一个项目中创建一些 C++ 库(VS 术语中的解决方案),需要由其他两个项目使用。为此,我创建了一个 FindDQSAnalyticsInfra.cmake 文件,如下所示:
# DQSAnalyticsInfra
# -----
# Find the path to DQSAnalyticsInfra header files and libraries
#
# DEFINES
# ------
# DQSINFRA_ROOT - Root of the DQSAnalyticsInfra project
# DQSINFRA_INCLUDE_DIR - DQSAnalyticsInfra include directory
# DQSINFRA_LIBRARIES - Libraries required to link DQSAnalyticsInfra
# DQSINFRA_FOUND - Confirmation
set(DQSINFRA_LIBRARIES_LIST Utils Actor gtest)
find_path(DQSINFRA_INCLUDE_DIR Actor/Actor.h Utils/Log.h gtest/gtest/gtest.h
${DQSINFRA_ROOT}/include
)
foreach(search_lib ${DQSINFRA_LIBRARIES_LIST})
find_library(DQSINFRA_LIB NAMES ${search_lib}
PATHS
${DQSINFRA_ROOT}/lib/Release #The problem is here
)
set(DQSINFRA_LIBRARIES ${DQSINFRA_LIBRARIES} ${DQSINFRA_LIB})
if(DQSINFRA_LIB)
unset(DQSINFRA_LIB CACHE)
set(DQSINFRA_FOUND TRUE)
else(DQSINFRA_LIB)
set(DQSINFRA_FOUND FALSE)
break()
endif(DQSINFRA_LIB)
endforeach(search_lib)
if(DQSINFRA_INCLUDE_DIR AND DQSINFRA_LIBRARIES AND DQSINFRA_FOUND)
set(DQSINFRA_FOUND TRUE)
message(STATUS "Found DQSAnalyticsInfra. ")
message(STATUS "Include Path: ${DQSINFRA_INCLUDE_DIR}")
message(STATUS "Libraries ${DQSINFRA_LIBRARIES}")
else(DQSINFRA_INCLUDE_DIR AND DQSINFRA_LIBRARIES AND DQSINFRA_FOUND)
set(DQSINFRA_FOUND FALSE)
message(STATUS "DQSAnalyticsInfra not found.")
endif(DQSINFRA_INCLUDE_DIR AND DQSINFRA_LIBRARIES AND DQSINFRA_FOUND)
mark_as_advanced(DQSINFRA_INCLUDE_DIR DQSINFRA_LIBRARIES)
该文件工作正常。问题是在此文件中使用的 find_library 命令中,我将路径硬编码为 ${DQSINFRA_ROOT}/lib/Release。这意味着我不能使用此文件链接到调试版本(我必须手动更改文件以使用 ${DQSINFRA_ROOT}/lib/Debug)。关于如何解决这个问题的任何想法。谢谢。