From Sukender, "As discussed in osg-users, I found output directories with CMake >= 2.8.1 are wrong under MSVC (As Chuck said, it's to be related to CMake, and not MSVC).

But I also found rev. 11354 (from Wang Rui) added a change in OsgMacroUtils which adresses a similar issue: Wang told the "../../bin" prefix wasn't working. However I think the fix isn't correct because it checks the MSVC version instead of the CMake version. Here is my fix, against latest trunk (root CMakeLists.txt, and CMakeModules/OsgMacroUtils.cmake).

Tests I made:
           | Unix Makefiles | MSVC 9 | MSVC 10 x64
---------------------------------------------------
CMake 2.4   |                |   OK   | N/A
CMake 2.6.4 |                |   OK   | N/A
CMake 2.8.0 |                |   OK   | broken support?
CMake 2.8.2 |                |   OK   | OK
"
This commit is contained in:
Robert Osfield 2010-11-09 14:39:32 +00:00
parent b7cccf6258
commit 3fb3ef9f39
2 changed files with 127 additions and 25 deletions

View File

@ -386,6 +386,9 @@ FIND_PACKAGE(FFmpeg)
FIND_PACKAGE(DirectShow) FIND_PACKAGE(DirectShow)
FIND_PACKAGE(SDL) FIND_PACKAGE(SDL)
# Include macro utilities here
INCLUDE(OsgMacroUtils)
# To select a specific version of QT define DESIRED_QT_VERSION # To select a specific version of QT define DESIRED_QT_VERSION
# via cmake -DDESIRED_QT_VERSION=4 # via cmake -DDESIRED_QT_VERSION=4
IF (DESIRED_QT_VERSION) IF (DESIRED_QT_VERSION)
@ -531,8 +534,13 @@ ENDIF(NOT MSVC OR MSVC_IDE)
# #
# On CMake 2.6.x use the newly minted CMAKE_LIBRARY_OUTPUT_DIRECTORY, # On CMake 2.6.x use the newly minted CMAKE_LIBRARY_OUTPUT_DIRECTORY,
# CMAKE_ARCHIVE_OUTPUT_DIRECTORY & CMAKE_RUNTIME_OUTPUT_DIRECTORY # CMAKE_ARCHIVE_OUTPUT_DIRECTORY & CMAKE_RUNTIME_OUTPUT_DIRECTORY
#
# CMake >= 2.8.1 changed the output directory algorithm (See doc).
# Here we also set per-configuration directories (CMAKE_*_OUTPUT_DIRECTORY_<CONFIG>), or else binaries are generated in /bin/Debug and /bin/Release, etc. with MSVC and Xcode.
# (Doc reads "multi-configuration generators (VS, Xcode) do NOT append a per-configuration subdirectory to the specified directory").
# The workaround for 2.6.x (adding "../" as an output prefix for each target) seem to have no effect in >=2.8.1, so there is no need to change this.
IF(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION LESS 5) IF(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION LESS 5)
# If CMake < 2.6.0
SET(EXECUTABLE_OUTPUT_PATH ${OUTPUT_BINDIR}) SET(EXECUTABLE_OUTPUT_PATH ${OUTPUT_BINDIR})
SET(LIBRARY_OUTPUT_PATH ${OUTPUT_LIBDIR}) SET(LIBRARY_OUTPUT_PATH ${OUTPUT_LIBDIR})
ELSE() ELSE()
@ -544,6 +552,21 @@ ELSE()
ELSE(WIN32) ELSE(WIN32)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_LIBDIR}) SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_LIBDIR})
ENDIF(WIN32) ENDIF(WIN32)
# Testing CMAKE_VERSION is possible in >= 2.6.4 only
BUILDER_VERSION_GREATER(2 8 0)
IF(VALID_BUILDER_VERSION) # If CMake >= 2.8.1
FOREACH(CONF ${CMAKE_CONFIGURATION_TYPES}) # For each configuration (Debug, Release, MinSizeRel... and/or anything the user chooses)
STRING(TOUPPER "${CONF}" CONF) # Go uppercase (DEBUG, RELEASE...)
SET("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_LIBDIR}")
SET("CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_BINDIR}")
IF(WIN32)
SET("CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_BINDIR}")
ELSE()
SET("CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_LIBDIR}")
ENDIF()
ENDFOREACH()
ENDIF(VALID_BUILDER_VERSION)
ENDIF() ENDIF()
#SET(INSTALL_BINDIR OpenSceneGraph/bin) #SET(INSTALL_BINDIR OpenSceneGraph/bin)
@ -646,7 +669,7 @@ ELSE ()
SET(OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC "STATIC") SET(OPENSCENEGRAPH_USER_DEFINED_DYNAMIC_OR_STATIC "STATIC")
ENDIF() ENDIF()
INCLUDE(OsgMacroUtils)
# OSG Core # OSG Core
ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(src)

View File

@ -9,6 +9,36 @@
# the content of this library for linking when in debugging # the content of this library for linking when in debugging
####################################################################################################### #######################################################################################################
# VALID_BUILDER_VERSION: used for replacing CMAKE_VERSION (available in v2.6.3 RC9) and VERSION_GREATER/VERSION_LESS (available in 2.6.2 RC4).
# This can be replaced by "IF(${CMAKE_VERSION} VERSION_LESS "x.y.z")" from 2.6.4.
SET(VALID_BUILDER_VERSION OFF)
MACRO(BUILDER_VERSION_GREATER MAJOR_VER MINOR_VER PATCH_VER)
SET(VALID_BUILDER_VERSION OFF)
IF(CMAKE_MAJOR_VERSION GREATER ${MAJOR_VER})
SET(VALID_BUILDER_VERSION ON)
ELSEIF(CMAKE_MAJOR_VERSION EQUAL ${MAJOR_VER})
IF(CMAKE_MINOR_VERSION GREATER ${MINOR_VER})
SET(VALID_BUILDER_VERSION ON)
ELSEIF(CMAKE_MINOR_VERSION EQUAL ${MINOR_VER})
IF(CMAKE_PATCH_VERSION GREATER ${PATCH_VER})
SET(VALID_BUILDER_VERSION ON)
ENDIF(CMAKE_PATCH_VERSION GREATER ${PATCH_VER})
ENDIF()
ENDIF()
ENDMACRO(BUILDER_VERSION_GREATER MAJOR_VER MINOR_VER PATCH_VER)
# CMAKE24: if CMake version is <2.6.0.
SET(CMAKE24 OFF)
IF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} LESS 5)
SET(CMAKE24 ON)
ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} LESS 5)
# CMAKE_VERSION_TEST: Define whether "IF(${CMAKE_VERSION} VERSION_LESS "x.y.z")" can be used or not.
BUILDER_VERSION_GREATER(2 6 3)
SET(CMAKE_VERSION_TEST ${VALID_BUILDER_VERSION}) # >= 2.6.4
SET(VALID_BUILDER_VERSION OFF)
MACRO(LINK_WITH_VARIABLES TRGTNAME) MACRO(LINK_WITH_VARIABLES TRGTNAME)
FOREACH(varname ${ARGN}) FOREACH(varname ${ARGN})
@ -21,9 +51,9 @@ MACRO(LINK_WITH_VARIABLES TRGTNAME)
ENDMACRO(LINK_WITH_VARIABLES TRGTNAME) ENDMACRO(LINK_WITH_VARIABLES TRGTNAME)
MACRO(LINK_INTERNAL TRGTNAME) MACRO(LINK_INTERNAL TRGTNAME)
IF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4) IF(NOT CMAKE24)
TARGET_LINK_LIBRARIES(${TRGTNAME} ${ARGN}) TARGET_LINK_LIBRARIES(${TRGTNAME} ${ARGN})
ELSE(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4) ELSE(NOT CMAKE24)
FOREACH(LINKLIB ${ARGN}) FOREACH(LINKLIB ${ARGN})
IF(MSVC AND OSG_MSVC_VERSIONED_DLL) IF(MSVC AND OSG_MSVC_VERSIONED_DLL)
#when using versioned names, the .dll name differ from .lib name, there is a problem with that: #when using versioned names, the .dll name differ from .lib name, there is a problem with that:
@ -36,7 +66,7 @@ MACRO(LINK_INTERNAL TRGTNAME)
TARGET_LINK_LIBRARIES(${TRGTNAME} optimized "${LINKLIB}${CMAKE_RELEASE_POSTFIX}" debug "${LINKLIB}${CMAKE_DEBUG_POSTFIX}") TARGET_LINK_LIBRARIES(${TRGTNAME} optimized "${LINKLIB}${CMAKE_RELEASE_POSTFIX}" debug "${LINKLIB}${CMAKE_DEBUG_POSTFIX}")
ENDIF(MSVC AND OSG_MSVC_VERSIONED_DLL) ENDIF(MSVC AND OSG_MSVC_VERSIONED_DLL)
ENDFOREACH(LINKLIB) ENDFOREACH(LINKLIB)
ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4) ENDIF(NOT CMAKE24)
ENDMACRO(LINK_INTERNAL TRGTNAME) ENDMACRO(LINK_INTERNAL TRGTNAME)
MACRO(LINK_EXTERNAL TRGTNAME) MACRO(LINK_EXTERNAL TRGTNAME)
@ -129,6 +159,44 @@ ENDMACRO(SETUP_LINK_LIBRARIES)
# this is the common set of command for all the plugins # this is the common set of command for all the plugins
# #
# Sets the output directory property for CMake >= 2.6.0, giving an output path RELATIVE to default one
MACRO(SET_OUTPUT_DIR_PROPERTY_260 TARGET_TARGETNAME RELATIVE_OUTDIR)
BUILDER_VERSION_GREATER(2 8 0)
IF(NOT VALID_BUILDER_VERSION)
# If CMake <= 2.8.0 (Testing CMAKE_VERSION is possible in >= 2.6.4)
IF(MSVC_IDE)
# Using the "prefix" hack
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../${RELATIVE_OUTDIR}/")
ELSE(MSVC_IDE)
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "${RELATIVE_OUTDIR}/")
ENDIF(MSVC_IDE)
ELSE(NOT VALID_BUILDER_VERSION)
# Using the output directory properties
# Global properties (All generators but VS & Xcode)
FILE(TO_CMAKE_PATH TMPVAR "CMAKE_ARCHIVE_OUTPUT_DIRECTORY/${RELATIVE_OUTDIR}")
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${TMPVAR}")
FILE(TO_CMAKE_PATH TMPVAR "CMAKE_RUNTIME_OUTPUT_DIRECTORY/${RELATIVE_OUTDIR}")
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TMPVAR}")
FILE(TO_CMAKE_PATH TMPVAR "CMAKE_LIBRARY_OUTPUT_DIRECTORY/${RELATIVE_OUTDIR}")
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TMPVAR}")
# Per-configuration property (VS, Xcode)
FOREACH(CONF ${CMAKE_CONFIGURATION_TYPES}) # For each configuration (Debug, Release, MinSizeRel... and/or anything the user chooses)
STRING(TOUPPER "${CONF}" CONF) # Go uppercase (DEBUG, RELEASE...)
# We use "FILE(TO_CMAKE_PATH", to create nice looking paths
FILE(TO_CMAKE_PATH "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONF}}/${RELATIVE_OUTDIR}" TMPVAR)
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONF}" "${TMPVAR}")
FILE(TO_CMAKE_PATH "${CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONF}}/${RELATIVE_OUTDIR}" TMPVAR)
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONF}" "${TMPVAR}")
FILE(TO_CMAKE_PATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONF}}/${RELATIVE_OUTDIR}" TMPVAR)
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONF}" "${TMPVAR}")
ENDFOREACH(CONF ${CMAKE_CONFIGURATION_TYPES})
ENDIF(NOT VALID_BUILDER_VERSION)
ENDMACRO(SET_OUTPUT_DIR_PROPERTY_260 TARGET_TARGETNAME RELATIVE_OUTDIR)
MACRO(SETUP_PLUGIN PLUGIN_NAME) MACRO(SETUP_PLUGIN PLUGIN_NAME)
SET(TARGET_NAME ${PLUGIN_NAME} ) SET(TARGET_NAME ${PLUGIN_NAME} )
@ -168,15 +236,10 @@ MACRO(SETUP_PLUGIN PLUGIN_NAME)
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "") SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES DEBUG_POSTFIX "")
ENDIF(NOT UNIX) ENDIF(NOT UNIX)
ELSE(NOT MSVC) ELSE(NOT MSVC)
IF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4) IF(NOT CMAKE24)
IF(NOT MSVC_IDE) SET_OUTPUT_DIR_PROPERTY_260(${TARGET_TARGETNAME} "${OSG_PLUGINS}") # Sets the ouput to be /osgPlugin-X.X.X ; also ensures the /Debug /Release are removed
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "${OSG_PLUGINS}/") ELSE(NOT CMAKE24)
ELSE(NOT MSVC_IDE)
IF(MSVC_VERSION LESS 1600)
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../${OSG_PLUGINS}/")
ENDIF()
ENDIF(NOT MSVC_IDE)
ELSE(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4)
IF(OSG_MSVC_VERSIONED_DLL) IF(OSG_MSVC_VERSIONED_DLL)
#this is a hack... the build place is set to lib/<debug or release> by LIBARARY_OUTPUT_PATH equal to OUTPUT_LIBDIR #this is a hack... the build place is set to lib/<debug or release> by LIBARARY_OUTPUT_PATH equal to OUTPUT_LIBDIR
@ -199,7 +262,8 @@ MACRO(SETUP_PLUGIN PLUGIN_NAME)
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "${OSG_PLUGINS}/") SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "${OSG_PLUGINS}/")
ENDIF(OSG_MSVC_VERSIONED_DLL) ENDIF(OSG_MSVC_VERSIONED_DLL)
ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4)
ENDIF(NOT CMAKE24)
ENDIF(NOT MSVC) ENDIF(NOT MSVC)
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "${TARGET_LABEL}") SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PROJECT_LABEL "${TARGET_LABEL}")
@ -278,9 +342,7 @@ MACRO(SETUP_EXE IS_COMMANDLINE_APP)
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES MINSIZEREL_OUTPUT_NAME "${TARGET_NAME}${CMAKE_MINSIZEREL_POSTFIX}") SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES MINSIZEREL_OUTPUT_NAME "${TARGET_NAME}${CMAKE_MINSIZEREL_POSTFIX}")
IF(MSVC_IDE AND OSG_MSVC_VERSIONED_DLL) IF(MSVC_IDE AND OSG_MSVC_VERSIONED_DLL)
IF(MSVC_VERSION LESS 1600) SET_OUTPUT_DIR_PROPERTY_260(${TARGET_TARGETNAME} "") # Ensure the /Debug /Release are removed
SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../")
ENDIF()
ENDIF(MSVC_IDE AND OSG_MSVC_VERSIONED_DLL) ENDIF(MSVC_IDE AND OSG_MSVC_VERSIONED_DLL)
SETUP_LINK_LIBRARIES() SETUP_LINK_LIBRARIES()
@ -364,10 +426,19 @@ MACRO(HANDLE_MSVC_DLL)
ELSE(${ARGC} GREATER 1) ELSE(${ARGC} GREATER 1)
SET(LIB_SOVERSION ${OPENSCENEGRAPH_SOVERSION}) SET(LIB_SOVERSION ${OPENSCENEGRAPH_SOVERSION})
ENDIF(${ARGC} GREATER 1) ENDIF(${ARGC} GREATER 1)
SET_OUTPUT_DIR_PROPERTY_260(${LIB_NAME} "") # Ensure the /Debug /Release are removed
IF(NOT MSVC_IDE) IF(NOT MSVC_IDE)
SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../bin/${LIB_PREFIX}${LIB_SOVERSION}-") IF (NOT CMAKE24)
IF (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 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}") SET(NEW_LIB_NAME "${OUTPUT_BINDIR}/${LIB_PREFIX}${LIB_SOVERSION}-${LIB_NAME}")
ADD_CUSTOM_COMMAND( ADD_CUSTOM_COMMAND(
TARGET ${LIB_NAME} TARGET ${LIB_NAME}
@ -377,11 +448,19 @@ MACRO(HANDLE_MSVC_DLL)
COMMAND ${CMAKE_COMMAND} -E remove "${NEW_LIB_NAME}.lib" COMMAND ${CMAKE_COMMAND} -E remove "${NEW_LIB_NAME}.lib"
COMMAND ${CMAKE_COMMAND} -E remove "${NEW_LIB_NAME}.exp" COMMAND ${CMAKE_COMMAND} -E remove "${NEW_LIB_NAME}.exp"
) )
ENDIF (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) ENDIF (NOT CMAKE24)
ELSE(NOT MSVC_IDE) ELSE(NOT MSVC_IDE)
IF(MSVC_VERSION LESS 1600) 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_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../../bin/${LIB_PREFIX}${LIB_SOVERSION}-" IMPORT_PREFIX "../")
ENDIF() ENDIF (NOT CMAKE24)
ENDIF(NOT MSVC_IDE) ENDIF(NOT MSVC_IDE)
# SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../../bin/osg${OPENSCENEGRAPH_SOVERSION}-") # SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../../bin/osg${OPENSCENEGRAPH_SOVERSION}-")