osg编译教程自行百度,着重记录一下再mingw下编译 带版本号的dll
前提:osg源码自带VS版本号的编译选项,为了实现用mingw编译带版本号的dll,看cmakelist文件,发现为了实现VS带版本号,
定义了 OSG_MSVC_VERSIONED_DLL 这个变量,项目中搜索,在CMakeModules 下发现了其使用文件,分别在OsgMacroUtils.cmake,UtilityMacros.cmake 文件中有其使用情况,阅读相关内容之后,发现MSVC 带版本号的部分代码。
在OsgMacroUtils.cmake 的最后,是相关函数
# Takes two optional arguments -- osg prefix and osg version
MACRO(HANDLE_MSVC_DLL)
#this is a hack... the build place is set to lib/or release> by LIBARARY_OUTPUT_PATH equal to OUTPUT_LIBDIR
#the .lib will be crated in ../ so going straight in lib by the IMPORT_PREFIX property
#because we want dll placed in OUTPUT_BINDIR ie the bin folder sibling of lib, we can use ../../bin to go there,
#it is hardcoded, we should compute OUTPUT_BINDIR position relative to OUTPUT_LIBDIR ... to be implemented
#changing bin to something else breaks this hack
#the dll are versioned by prefixing the name with osg${OPENSCENEGRAPH_SOVERSION}-
# LIB_PREFIX: use "osg" by default, else whatever we've been given.
IF(${ARGC} GREATER 0)
SET(LIB_PREFIX ${ARGV0})
ELSE(${ARGC} GREATER 0)
SET(LIB_PREFIX osg)
ENDIF(${ARGC} GREATER 0)
# LIB_SOVERSION: use OSG's soversion by default, else whatever we've been given
IF(${ARGC} GREATER 1)
SET(LIB_SOVERSION ${ARGV1})
ELSE(${ARGC} GREATER 1)
SET(LIB_SOVERSION ${OPENSCENEGRAPH_SOVERSION})
ENDIF(${ARGC} GREATER 1)
SET_OUTPUT_DIR_PROPERTY_260(${LIB_NAME} "") # Ensure the /Debug /Release are removed
IF(NOT MSVC_IDE)
IF (NOT CMAKE24)
BUILDER_VERSION_GREATER(2 8 0)
IF(NOT VALID_BUILDER_VERSION)
# If CMake < 2.8.1
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../bin/${LIB_PREFIX}${LIB_SOVERSION}-" IMPORT_PREFIX "../")
ELSE(NOT VALID_BUILDER_VERSION)
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "${LIB_PREFIX}${LIB_SOVERSION}-")
ENDIF(NOT VALID_BUILDER_VERSION)
ELSE (NOT CMAKE24)
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../bin/${LIB_PREFIX}${LIB_SOVERSION}-" IMPORT_PREFIX "../")
SET(NEW_LIB_NAME "${OUTPUT_BINDIR}/${LIB_PREFIX}${LIB_SOVERSION}-${LIB_NAME}")
ADD_CUSTOM_COMMAND(
TARGET ${LIB_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${NEW_LIB_NAME}.lib" "${OUTPUT_LIBDIR}/${LIB_NAME}.lib"
COMMAND ${CMAKE_COMMAND} -E copy "${NEW_LIB_NAME}.exp" "${OUTPUT_LIBDIR}/${LIB_NAME}.exp"
COMMAND ${CMAKE_COMMAND} -E remove "${NEW_LIB_NAME}.lib"
COMMAND ${CMAKE_COMMAND} -E remove "${NEW_LIB_NAME}.exp"
)
ENDIF (NOT CMAKE24)
ELSE(NOT MSVC_IDE)
IF (NOT CMAKE24)
BUILDER_VERSION_GREATER(2 8 0)
IF(NOT VALID_BUILDER_VERSION)
# If CMake < 2.8.1
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../../bin/${LIB_PREFIX}${LIB_SOVERSION}-" IMPORT_PREFIX "../")
ELSE(NOT VALID_BUILDER_VERSION)
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "${LIB_PREFIX}${LIB_SOVERSION}-")
ENDIF(NOT VALID_BUILDER_VERSION)
ELSE (NOT CMAKE24)
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../../bin/${LIB_PREFIX}${LIB_SOVERSION}-" IMPORT_PREFIX "../")
ENDIF (NOT CMAKE24)
ENDIF(NOT MSVC_IDE)
# SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../../bin/osg${OPENSCENEGRAPH_SOVERSION}-")
# SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES IMPORT_PREFIX "../")
ENDMACRO(HANDLE_MSVC_DLL)
仿照上面内容,写了自己的宏
MACRO(HANDLE_MINGW_DLL)
#this is a hack... the build place is set to lib/or release> by LIBARARY_OUTPUT_PATH equal to OUTPUT_LIBDIR
#the .lib will be crated in ../ so going straight in lib by the IMPORT_PREFIX property
#because we want dll placed in OUTPUT_BINDIR ie the bin folder sibling of lib, we can use ../../bin to go there,
#it is hardcoded, we should compute OUTPUT_BINDIR position relative to OUTPUT_LIBDIR ... to be implemented
#changing bin to something else breaks this hack
#the dll are versioned by prefixing the name with osg${OPENSCENEGRAPH_SOVERSION}-
# LIB_PREFIX: use "osg" by default, else whatever we've been given.
IF(${ARGC} GREATER 0)
SET(LIB_PREFIX ${ARGV0})
ELSE(${ARGC} GREATER 0)
SET(LIB_PREFIX osg)
ENDIF(${ARGC} GREATER 0)
# LIB_SOVERSION: use OSG's soversion by default, else whatever we've been given
IF(${ARGC} GREATER 1)
SET(LIB_SOVERSION ${ARGV1})
ELSE(${ARGC} GREATER 1)
SET(LIB_SOVERSION ${OPENSCENEGRAPH_SOVERSION})
ENDIF(${ARGC} GREATER 1)
SET_OUTPUT_DIR_PROPERTY_260(${LIB_NAME} "") # Ensure the /Debug /Release are removed
IF (NOT CMAKE24)
BUILDER_VERSION_GREATER(2 8 0)
IF(NOT VALID_BUILDER_VERSION)
# If CMake < 2.8.1
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../../bin/${LIB_PREFIX}${LIB_SOVERSION}-" IMPORT_PREFIX "../")
ELSE(NOT VALID_BUILDER_VERSION)
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "${LIB_PREFIX}${LIB_SOVERSION}-")
ENDIF(NOT VALID_BUILDER_VERSION)
ELSE (NOT CMAKE24)
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../../bin/${LIB_PREFIX}${LIB_SOVERSION}-" IMPORT_PREFIX "../")
ENDIF (NOT CMAKE24)
# SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../../bin/osg${OPENSCENEGRAPH_SOVERSION}-")
# SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES IMPORT_PREFIX "../")
ENDMACRO(HANDLE_MINGW_DLL)
关键语句只有一句
# SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "${LIB_PREFIX}${LIB_SOVERSION}-")
下来就是宏的调用了 在 UtilityMacros.cmake 文件中,找到MSVC HANDLE_MSVC_DLL 宏 的调用位置,修改一下,我为了偷懒直接改成如下了
IF(MSVC AND OSG_MSVC_VERSIONED_DLL)
HANDLE_MSVC_DLL()
ELSE()
HANDLE_MINGW_DLL()
ENDIF()
由于openthreads dll 的命名独立出来,所以还要修改一下源码中openthread文件夹下对下的对位 就是在.\src\openthreads\qt 和
.\src\openthreads\win32 文件夹下的 cmakelists.text 中,修改思路同上
IF(MSVC AND OSG_MSVC_VERSIONED_DLL)
HANDLE_MSVC_DLL(ot ${OPENTHREADS_SOVERSION})
ELSE()
HANDLE_MINGW_DLL(ot ${OPENTHREADS_SOVERSION})
ENDIF()
然后就是按照编译教程从新走一遍就好