CMake:如何根据构建类型生成不同的共享库名称
这是我第一次使用 CMake,我正在尝试构建 QJSon,一个用于 Qt 4.x 的 JSON 解析器。我基本上想要的是根据构建配置构建不同的输出库名称。我使用 ${CMAKE_BUILD_TYPE}
宏生成不同的目标(qjson.lib/qjson.dll 和 qjsond.lib/qjsond.dll)。似乎 VS 2008 解决方案总是使用 qjson 名称构建(调试构建上没有 qjsond)。
我的 Makefile 指令的可怕部分如下:
IF("${CMAKE_BUILD_TYPE}" MATCHES "^Rel.*")
add_library ( qjson SHARED ${qjson_SRCS} ${qjson_MOC_SRCS})
target_link_libraries( qjson ${QT_LIBRARIES})
set_target_properties( qjson PROPERTIES
VERSION ${QJSON_LIB_MAJOR_VERSION}.
${QJSON_LIB_MINOR_VERSION}.${QJSON_LIB_PATCH_VERSION}
SOVERSION ${QJSON_LIB_MAJOR_VERSION}
DEFINE_SYMBOL QJSON_MAKEDLL
)
INSTALL(TARGETS qjson
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
)
ENDIF("${CMAKE_BUILD_TYPE}" MATCHES "^Rel.*")
IF("${CMAKE_BUILD_TYPE}" MATCHES "^Deb.*")
add_library ( qjsond SHARED ${qjson_SRCS} ${qjson_MOC_SRCS})
target_link_libraries( qjsond ${QT_LIBRARIES})
set_target_properties( qjsond PROPERTIES
VERSION ${QJSON_LIB_MAJOR_VERSION}.
${QJSON_LIB_MINOR_VERSION}.
${QJSON_LIB_PATCH_VERSION}
SOVERSION ${QJSON_LIB_MAJOR_VERSION}
DEFINE_SYMBOL QJSON_MAKEDLL
)
INSTALL(TARGETS qjsond
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
)
ENDIF("${CMAKE_BUILD_TYPE}" MATCHES "^Deb.*")
有什么想法吗?当然还有更简单的配置。谢谢。
This is my first time using CMake and I'm trying to build QJSon, a JSON parser for Qt 4.x. What I want basically is to build different output library names depending on the build configuration. I'm using ${CMAKE_BUILD_TYPE}
macro to generate different targets (qjson.lib/qjson.dll and qjsond.lib/qjsond.dll). Seems that the VS 2008 solution always builds with the qjson name (no qjsond on debug builds).
My horrible section of Makefile directives is as follows:
IF("${CMAKE_BUILD_TYPE}" MATCHES "^Rel.*")
add_library ( qjson SHARED ${qjson_SRCS} ${qjson_MOC_SRCS})
target_link_libraries( qjson ${QT_LIBRARIES})
set_target_properties( qjson PROPERTIES
VERSION ${QJSON_LIB_MAJOR_VERSION}.
${QJSON_LIB_MINOR_VERSION}.${QJSON_LIB_PATCH_VERSION}
SOVERSION ${QJSON_LIB_MAJOR_VERSION}
DEFINE_SYMBOL QJSON_MAKEDLL
)
INSTALL(TARGETS qjson
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
)
ENDIF("${CMAKE_BUILD_TYPE}" MATCHES "^Rel.*")
IF("${CMAKE_BUILD_TYPE}" MATCHES "^Deb.*")
add_library ( qjsond SHARED ${qjson_SRCS} ${qjson_MOC_SRCS})
target_link_libraries( qjsond ${QT_LIBRARIES})
set_target_properties( qjsond PROPERTIES
VERSION ${QJSON_LIB_MAJOR_VERSION}.
${QJSON_LIB_MINOR_VERSION}.
${QJSON_LIB_PATCH_VERSION}
SOVERSION ${QJSON_LIB_MAJOR_VERSION}
DEFINE_SYMBOL QJSON_MAKEDLL
)
INSTALL(TARGETS qjsond
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
)
ENDIF("${CMAKE_BUILD_TYPE}" MATCHES "^Deb.*")
Any ideas? Sure there's a simpler configuration. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://www.cmake.org/ cmake/help/cmake-2-8-docs.html#prop_tgt:OUTPUT_NAME_CONFIG
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:OUTPUT_NAME_CONFIG