Changeset 11904

Show
Ignore:
Timestamp:
11/09/10 15:39:32 (4 years ago)
Author:
robert
Message:

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
"

Location:
OpenSceneGraph/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/CMakeLists.txt

    r11817 r11904  
    387387FIND_PACKAGE(SDL) 
    388388 
     389# Include macro utilities here 
     390INCLUDE(OsgMacroUtils) 
     391 
    389392# To select a specific version of QT define DESIRED_QT_VERSION 
    390393# via cmake -DDESIRED_QT_VERSION=4 
     
    532535# On CMake 2.6.x use the newly minted CMAKE_LIBRARY_OUTPUT_DIRECTORY, 
    533536# CMAKE_ARCHIVE_OUTPUT_DIRECTORY & CMAKE_RUNTIME_OUTPUT_DIRECTORY 
    534  
     537# 
     538# CMake >= 2.8.1 changed the output directory algorithm (See doc). 
     539# 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. 
     540# (Doc reads "multi-configuration generators (VS, Xcode) do NOT append a per-configuration subdirectory to the specified directory"). 
     541# 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. 
    535542IF(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION LESS 5) 
     543    # If CMake < 2.6.0 
    536544    SET(EXECUTABLE_OUTPUT_PATH ${OUTPUT_BINDIR}) 
    537545    SET(LIBRARY_OUTPUT_PATH    ${OUTPUT_LIBDIR}) 
     
    545553        SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_LIBDIR}) 
    546554    ENDIF(WIN32) 
     555 
     556    # Testing CMAKE_VERSION is possible in >= 2.6.4 only 
     557    BUILDER_VERSION_GREATER(2 8 0) 
     558    IF(VALID_BUILDER_VERSION)  # If CMake >= 2.8.1 
     559        FOREACH(CONF ${CMAKE_CONFIGURATION_TYPES})        # For each configuration (Debug, Release, MinSizeRel... and/or anything the user chooses) 
     560            STRING(TOUPPER "${CONF}" CONF)                # Go uppercase (DEBUG, RELEASE...) 
     561            SET("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_LIBDIR}") 
     562            SET("CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_BINDIR}") 
     563            IF(WIN32) 
     564                SET("CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_BINDIR}") 
     565            ELSE() 
     566                SET("CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONF}" "${OUTPUT_LIBDIR}") 
     567            ENDIF() 
     568        ENDFOREACH() 
     569    ENDIF(VALID_BUILDER_VERSION) 
    547570ENDIF() 
    548571 
     
    647670ENDIF() 
    648671 
    649 INCLUDE(OsgMacroUtils) 
     672 
    650673# OSG Core 
    651674ADD_SUBDIRECTORY(src) 
  • OpenSceneGraph/trunk/CMakeModules/OsgMacroUtils.cmake

    r11817 r11904  
    1010####################################################################################################### 
    1111 
     12# 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). 
     13# This can be replaced by "IF(${CMAKE_VERSION} VERSION_LESS "x.y.z")" from 2.6.4. 
     14SET(VALID_BUILDER_VERSION OFF) 
     15MACRO(BUILDER_VERSION_GREATER MAJOR_VER MINOR_VER PATCH_VER) 
     16    SET(VALID_BUILDER_VERSION OFF) 
     17    IF(CMAKE_MAJOR_VERSION GREATER ${MAJOR_VER}) 
     18        SET(VALID_BUILDER_VERSION ON) 
     19    ELSEIF(CMAKE_MAJOR_VERSION EQUAL ${MAJOR_VER}) 
     20        IF(CMAKE_MINOR_VERSION GREATER ${MINOR_VER}) 
     21            SET(VALID_BUILDER_VERSION ON) 
     22        ELSEIF(CMAKE_MINOR_VERSION EQUAL ${MINOR_VER}) 
     23            IF(CMAKE_PATCH_VERSION GREATER ${PATCH_VER}) 
     24                SET(VALID_BUILDER_VERSION ON) 
     25            ENDIF(CMAKE_PATCH_VERSION GREATER ${PATCH_VER}) 
     26        ENDIF() 
     27    ENDIF() 
     28ENDMACRO(BUILDER_VERSION_GREATER MAJOR_VER MINOR_VER PATCH_VER) 
     29 
     30# CMAKE24: if CMake version is <2.6.0. 
     31SET(CMAKE24 OFF) 
     32IF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} LESS 5) 
     33    SET(CMAKE24 ON) 
     34ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} LESS 5) 
     35 
     36# CMAKE_VERSION_TEST: Define whether "IF(${CMAKE_VERSION} VERSION_LESS "x.y.z")" can be used or not. 
     37BUILDER_VERSION_GREATER(2 6 3) 
     38SET(CMAKE_VERSION_TEST ${VALID_BUILDER_VERSION})        # >= 2.6.4 
     39 
     40SET(VALID_BUILDER_VERSION OFF) 
     41 
    1242 
    1343MACRO(LINK_WITH_VARIABLES TRGTNAME) 
     
    2252 
    2353MACRO(LINK_INTERNAL TRGTNAME) 
    24     IF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4) 
     54    IF(NOT CMAKE24) 
    2555        TARGET_LINK_LIBRARIES(${TRGTNAME} ${ARGN}) 
    26     ELSE(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4) 
     56    ELSE(NOT CMAKE24) 
    2757        FOREACH(LINKLIB ${ARGN}) 
    2858            IF(MSVC AND OSG_MSVC_VERSIONED_DLL) 
     
    3767            ENDIF(MSVC AND OSG_MSVC_VERSIONED_DLL) 
    3868        ENDFOREACH(LINKLIB) 
    39     ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4) 
     69    ENDIF(NOT CMAKE24) 
    4070ENDMACRO(LINK_INTERNAL TRGTNAME) 
    4171 
     
    130160# 
    131161 
     162# Sets the output directory property for CMake >= 2.6.0, giving an output path RELATIVE to default one 
     163MACRO(SET_OUTPUT_DIR_PROPERTY_260 TARGET_TARGETNAME RELATIVE_OUTDIR) 
     164    BUILDER_VERSION_GREATER(2 8 0) 
     165    IF(NOT VALID_BUILDER_VERSION) 
     166        # If CMake <= 2.8.0 (Testing CMAKE_VERSION is possible in >= 2.6.4) 
     167        IF(MSVC_IDE) 
     168            # Using the "prefix" hack 
     169            SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../${RELATIVE_OUTDIR}/") 
     170        ELSE(MSVC_IDE) 
     171            SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "${RELATIVE_OUTDIR}/") 
     172        ENDIF(MSVC_IDE) 
     173    ELSE(NOT VALID_BUILDER_VERSION) 
     174        # Using the output directory properties 
     175 
     176        # Global properties (All generators but VS & Xcode) 
     177        FILE(TO_CMAKE_PATH TMPVAR "CMAKE_ARCHIVE_OUTPUT_DIRECTORY/${RELATIVE_OUTDIR}") 
     178        SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${TMPVAR}") 
     179        FILE(TO_CMAKE_PATH TMPVAR "CMAKE_RUNTIME_OUTPUT_DIRECTORY/${RELATIVE_OUTDIR}") 
     180        SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TMPVAR}") 
     181        FILE(TO_CMAKE_PATH TMPVAR "CMAKE_LIBRARY_OUTPUT_DIRECTORY/${RELATIVE_OUTDIR}") 
     182        SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TMPVAR}") 
     183 
     184        # Per-configuration property (VS, Xcode) 
     185        FOREACH(CONF ${CMAKE_CONFIGURATION_TYPES})        # For each configuration (Debug, Release, MinSizeRel... and/or anything the user chooses) 
     186            STRING(TOUPPER "${CONF}" CONF)                # Go uppercase (DEBUG, RELEASE...) 
     187 
     188            # We use "FILE(TO_CMAKE_PATH", to create nice looking paths 
     189            FILE(TO_CMAKE_PATH "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONF}}/${RELATIVE_OUTDIR}" TMPVAR) 
     190            SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONF}" "${TMPVAR}") 
     191            FILE(TO_CMAKE_PATH "${CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONF}}/${RELATIVE_OUTDIR}" TMPVAR) 
     192            SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONF}" "${TMPVAR}") 
     193            FILE(TO_CMAKE_PATH "${CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONF}}/${RELATIVE_OUTDIR}" TMPVAR) 
     194            SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONF}" "${TMPVAR}") 
     195        ENDFOREACH(CONF ${CMAKE_CONFIGURATION_TYPES}) 
     196    ENDIF(NOT VALID_BUILDER_VERSION) 
     197ENDMACRO(SET_OUTPUT_DIR_PROPERTY_260 TARGET_TARGETNAME RELATIVE_OUTDIR) 
     198 
     199 
    132200MACRO(SETUP_PLUGIN PLUGIN_NAME) 
    133201 
     
    169237        ENDIF(NOT UNIX) 
    170238    ELSE(NOT MSVC) 
    171         IF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4) 
    172             IF(NOT MSVC_IDE) 
    173                 SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "${OSG_PLUGINS}/")                      
    174             ELSE(NOT MSVC_IDE) 
    175                 IF(MSVC_VERSION LESS 1600) 
    176                     SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../${OSG_PLUGINS}/") 
    177                 ENDIF() 
    178             ENDIF(NOT MSVC_IDE) 
    179         ELSE(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4) 
     239        IF(NOT CMAKE24) 
     240            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 
     241        ELSE(NOT CMAKE24) 
     242 
    180243            IF(OSG_MSVC_VERSIONED_DLL)  
    181244 
     
    200263                SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "${OSG_PLUGINS}/") 
    201264            ENDIF(OSG_MSVC_VERSIONED_DLL) 
    202         ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 4) 
     265 
     266        ENDIF(NOT CMAKE24) 
    203267    ENDIF(NOT MSVC) 
    204268 
     
    279343 
    280344    IF(MSVC_IDE AND OSG_MSVC_VERSIONED_DLL) 
    281         IF(MSVC_VERSION LESS 1600) 
    282             SET_TARGET_PROPERTIES(${TARGET_TARGETNAME} PROPERTIES PREFIX "../")     
    283         ENDIF() 
     345        SET_OUTPUT_DIR_PROPERTY_260(${TARGET_TARGETNAME} "")        # Ensure the /Debug /Release are removed 
    284346    ENDIF(MSVC_IDE AND OSG_MSVC_VERSIONED_DLL) 
    285347 
     
    365427                SET(LIB_SOVERSION ${OPENSCENEGRAPH_SOVERSION}) 
    366428        ENDIF(${ARGC} GREATER 1) 
    367      
     429 
     430        SET_OUTPUT_DIR_PROPERTY_260(${LIB_NAME} "")        # Ensure the /Debug /Release are removed 
    368431        IF(NOT MSVC_IDE)  
    369             SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../bin/${LIB_PREFIX}${LIB_SOVERSION}-") 
    370             IF (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)  
     432            IF (NOT CMAKE24) 
     433                BUILDER_VERSION_GREATER(2 8 0) 
     434                IF(NOT VALID_BUILDER_VERSION) 
     435                    # If CMake < 2.8.1 
     436                    SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../bin/${LIB_PREFIX}${LIB_SOVERSION}-" IMPORT_PREFIX "../") 
     437                ELSE(NOT VALID_BUILDER_VERSION) 
     438                    SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "${LIB_PREFIX}${LIB_SOVERSION}-") 
     439                ENDIF(NOT VALID_BUILDER_VERSION) 
     440            ELSE (NOT CMAKE24) 
     441                SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../bin/${LIB_PREFIX}${LIB_SOVERSION}-" IMPORT_PREFIX "../") 
    371442                SET(NEW_LIB_NAME "${OUTPUT_BINDIR}/${LIB_PREFIX}${LIB_SOVERSION}-${LIB_NAME}") 
    372443                ADD_CUSTOM_COMMAND( 
     
    378449                    COMMAND ${CMAKE_COMMAND} -E remove "${NEW_LIB_NAME}.exp" 
    379450                    ) 
    380             ENDIF (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)  
    381         ELSE(NOT MSVC_IDE)  
    382             IF(MSVC_VERSION LESS 1600) 
     451            ENDIF (NOT CMAKE24) 
     452        ELSE(NOT MSVC_IDE) 
     453            IF (NOT CMAKE24) 
     454                BUILDER_VERSION_GREATER(2 8 0) 
     455                IF(NOT VALID_BUILDER_VERSION) 
     456                    # If CMake < 2.8.1 
     457                    SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../../bin/${LIB_PREFIX}${LIB_SOVERSION}-" IMPORT_PREFIX "../") 
     458                ELSE(NOT VALID_BUILDER_VERSION) 
     459                    SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "${LIB_PREFIX}${LIB_SOVERSION}-") 
     460                ENDIF(NOT VALID_BUILDER_VERSION) 
     461            ELSE (NOT CMAKE24) 
    383462                SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES PREFIX "../../bin/${LIB_PREFIX}${LIB_SOVERSION}-" IMPORT_PREFIX "../") 
    384             ENDIF() 
     463            ENDIF (NOT CMAKE24) 
    385464        ENDIF(NOT MSVC_IDE)  
    386465