CMake 设置每个配置链接器标志
CMake set per configuration linker flag
如标题所述,是否有 'neat' 方法来设置每个配置 linker 标志?我无法使用 target_link_options()
,因为我正在尝试 link 进入静态库。理想情况下,我想要实现的是设置 Visual Studio 的 Librarian -> Additional Dependencies 和 Additional Library Directories 并在 XCode 中也获得相同的结果。
这是我到目前为止所取得的成就:
set(LIB_LINKS_RUNTIME
${Vulkan_LIBRARIES}
${CMAKE_SOURCE_DIR}/bin/$<CONFIGURATION>/SDL2maind.lib
${CMAKE_SOURCE_DIR}/bin/$<CONFIGURATION>/SDL2d.lib
${CMAKE_SOURCE_DIR}/bin/$<CONFIGURATION>/imgui.lib
)
foreach(lib ${LIB_LINKS_RUNTIME})
set (CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${lib}")
endforeach()
根据https://cmake.org/cmake/help/latest/prop_tgt/STATIC_LIBRARY_OPTIONS.html STATIC_LIBRARY_OPTIONS 属性 做的技巧
set_property(TARGET Runtime PROPERTY STATIC_LIBRARY_OPTIONS ${LIB_LINKS_RUNTIME})
如标题所述,是否有 'neat' 方法来设置每个配置 linker 标志?我无法使用 target_link_options()
,因为我正在尝试 link 进入静态库。理想情况下,我想要实现的是设置 Visual Studio 的 Librarian -> Additional Dependencies 和 Additional Library Directories 并在 XCode 中也获得相同的结果。
这是我到目前为止所取得的成就:
set(LIB_LINKS_RUNTIME
${Vulkan_LIBRARIES}
${CMAKE_SOURCE_DIR}/bin/$<CONFIGURATION>/SDL2maind.lib
${CMAKE_SOURCE_DIR}/bin/$<CONFIGURATION>/SDL2d.lib
${CMAKE_SOURCE_DIR}/bin/$<CONFIGURATION>/imgui.lib
)
foreach(lib ${LIB_LINKS_RUNTIME})
set (CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${lib}")
endforeach()
根据https://cmake.org/cmake/help/latest/prop_tgt/STATIC_LIBRARY_OPTIONS.html STATIC_LIBRARY_OPTIONS 属性 做的技巧
set_property(TARGET Runtime PROPERTY STATIC_LIBRARY_OPTIONS ${LIB_LINKS_RUNTIME})