我们有一个基于某些设置的项目,我们可能会或可能不会在项目中编译静态库。如果我们不构建它,我们将使用包装在DUMMY_LIB_IMPL宏中的虚拟实现。更加清楚;
{ROOT_DIR}/
CMakeLists.txt
|
|_ P1/CMakeLists.txt --> The cmake file which has the below snippet
|_ P2/CMakeLists.txt --> May/MayNot compile "lib_that_may_be_compiled_by_us"
所以这是我们在P1 / CMakeLists.txt中最终得到的结果的一部分
find_library(OPTIONAL_LIB lib_that_may_be_compiled_by_us)
if(OPTIONAL_LIB)
target_link_libraries(p1 lib_that_may_be_compiled_by_us)
message("Found library at" ${OPTIONAL_LIB})
else()
set(CMAKE_CXX_flaGS "${CMAKE_CXX_flaGS} -DDUMMY_LIB_IMPL")
message("Could not find client library enabling MACRO DUMMY_LIB_IMPL")
endif()
不幸的是,这里的find_lib(...)似乎无法找到该库。尝试将路径添加到我们构建它的路径,但无济于事。
是否有另一种方法可以实现类似目的?上面的当前代码片段出了什么问题?