Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7143


Ignore:
Timestamp:
Jun 10, 2010, 1:44:21 PM (14 years ago)
Author:
rgrieder
Message:

Static linking to the libraries in src/external should work now (at least on Windows with MSVC).
There are no STATIC/SHARED options anymore. Instead all of our own libraries get linked dynamically anyway because it simply doesn't work otherwise (there is really no way to link them statically).
The linking behaviour for external libraries can be changed with the CMake cache variable ORXONOX_EXTERNAL_LINK_MODE, but it defaults to SHARED.
Also, I had to revert the DEFINE_SYMBOL changes.

Location:
code/branches/presentation3
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/cmake/tools/TargetUtilities.cmake

    r7139 r7143  
    3434 #      NO_DLL_INTERFACE:  Link statically with MSVC
    3535 #      NO_SOURCE_GROUPS:  Don't create msvc source groups
    36  #      STATIC/SHARED:     Inherited from ADD_LIBRARY
    37  #      MODULE:            For dynamic module libraries
    38  #      WIN32:             Inherited from ADD_EXECUTABLE
     36 #      MODULE:            For dynamic module libraries (libraries only)
     37 #      WIN32:             Inherited from ADD_EXECUTABLE (executables only)
    3938 #      PCH_NO_DEFAULT:    Do not make precompiled header files default if
    4039 #                         specified with PCH_FILE
     
    4746 #      SOURCE_FILES:      Source files for the target
    4847 #      DEFINE_SYMBOL:     Sets the DEFINE_SYMBOL target property
    49  #                         Usage: DEFINE_SYMBOL static "symbol" shared "symbol2"
    50  #                         (or shared "symbol2" static "symbol")
    5148 #      TOLUA_FILES:       Files with tolua interface
    5249 #      PCH_FILE:          Precompiled header file
     
    7168
    7269MACRO(ORXONOX_ADD_LIBRARY _target_name)
    73   TU_ADD_TARGET(${_target_name} LIBRARY "STATIC;SHARED" ${ARGN})
     70  TU_ADD_TARGET(${_target_name} LIBRARY "MODULE" ${ARGN})
    7471ENDMACRO(ORXONOX_ADD_LIBRARY)
    7572
     
    8582  # Specify all possible options (either switch or with add. arguments)
    8683  SET(_switches   FIND_HEADER_FILES  EXCLUDE_FROM_ALL  ORXONOX_EXTERNAL
    87                   NO_DLL_INTERFACE   NO_SOURCE_GROUPS  ${_additional_switches}
    88                   PCH_NO_DEFAULT     NO_INSTALL        MODULE NO_VERSION)
     84                  NO_DLL_INTERFACE   NO_SOURCE_GROUPS  PCH_NO_DEFAULT
     85                  NO_INSTALL         NO_VERSION        ${_additional_switches})
    8986  SET(_list_names LINK_LIBRARIES  VERSION   SOURCE_FILES  DEFINE_SYMBOL
    90                   TOLUA_FILES     PCH_FILE  PCH_EXCLUDE OUTPUT_NAME)
     87                  TOLUA_FILES     PCH_FILE  PCH_EXCLUDE   OUTPUT_NAME)
    9188  PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
    9289
     
    149146  ENDIF()
    150147
    151   # Certain libraries don't have dllexport/dllimport and can't be linked shared with msvc
     148  # Set link mode (SHARED/STATIC)
    152149  IF(MSVC AND _arg_NO_DLL_INTERFACE)
    153     SET(_arg_SHARED)
    154     SET(_arg_STATIC STATIC)
     150    # Certain libraries don't have dllexport/dllimport and can't be linked shared with MSVC
     151    SET(_link_mode STATIC)
     152  ELSEIF(_arg_ORXONOX_EXTERNAL)
     153    # Externals can be linked shared or statically
     154    SET(_link_mode ${ORXONOX_EXTERNAL_LINK_MODE})
     155  ELSE()
     156    # All our own libraries are linked dynamically because of static symbols
     157    SET(_link_mode SHARED)
    155158  ENDIF()
    156159
     
    161164  ENDIF()
    162165
    163   # Set default linking if required
    164   IF(NOT _arg_SHARED AND NOT _arg_STATIC)
    165     IF("${ORXONOX_DEFAULT_LINK}" STREQUAL "STATIC")
    166       SET(_arg_STATIC STATIC)
    167     ELSEIF("${ORXONOX_DEFAULT_LINK}" STREQUAL "SHARED")
    168       SET(_arg_SHARED SHARED)
    169     ENDIF()
    170   ENDIF()
    171 
    172   # MODULE A
    173   # Always create shared libraries
    174   IF(_arg_MODULE)
    175     SET(_arg_SHARED SHARED)
    176     SET(_arg_STATIC)
    177   ENDIF()
    178 
    179166  # Don't compile header files
    180167  FOREACH(_file ${_${_target_name}_files})
     
    188175  # Add the library/executable
    189176  IF("${_target_type}" STREQUAL "LIBRARY")
    190     ADD_LIBRARY(${_target_name} ${_arg_STATIC} ${_arg_SHARED}
     177    ADD_LIBRARY(${_target_name} ${_link_mode}
    191178                ${_arg_EXCLUDE_FROM_ALL} ${_${_target_name}_files})
    192179  ELSE()
     
    215202  ENDIF()
    216203
    217   # MODULE B
     204  # Configure modules
    218205  IF (_arg_MODULE)
    219206    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES
     
    230217
    231218  # DEFINE_SYMBOL
    232   IF(_arg_DEFINE_SYMBOL OR NOT _arg_ORXONOX_EXTERNAL)
    233     IF(_arg_DEFINE_SYMBOL)
    234       # Format is: static "static_symbol" shared "shared_symbol"
    235       # but the order doesn't matter
    236       LIST(LENGTH _arg_DEFINE_SYMBOL _define_symbol_length)
    237       IF (_define_symbol_length LESS 2)
    238         MESSAGE(FATAL_ERROR "Number of expected arguments for DEFINE_SYMBOL is at least 2: static \"STATIC_SYMBOL\" shared \"SHARED_SYMBOL\"")
    239       ENDIF()
    240       STRING(TOLOWER "${_arg_STATIC}${_arg_SHARED}" _static_shared_lower)
    241       LIST(FIND _arg_DEFINE_SYMBOL ${_static_shared_lower} _symbol_definition_index)
    242       MATH(EXPR _symbol_definition_index "${_symbol_definition_index} + 1")
    243       IF(_symbol_definition_index LESS _define_symbol_length)
    244         LIST(GET _arg_DEFINE_SYMBOL ${_symbol_definition_index} _symbol_definition)
    245       ENDIF()
    246     ELSE()
    247       # Automatically add the macro definitions for our own libraries
    248       SET(_symbol_definition "${_target_name_upper}_${_arg_STATIC}${_arg_SHARED}_BUILD")
    249     ENDIF()
    250 
    251     # Use the DEFINE_SYMBOL property for shared builds (not used by CMake for static builds),
    252     # but if we only use COMPILE_FLAGS, CMake will define a symbol anyway.
    253     IF(_arg_SHARED)
    254       SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL ${_symbol_definition})
    255     ELSE()
    256       GET_TARGET_PROPERTY(_compile_flags ${_target_name} COMPILE_FLAGS)
    257       IF(NOT _compile_flags)
    258         SET(_compile_flags)
    259       ENDIF()
    260       SET_TARGET_PROPERTIES(${_target_name} PROPERTIES COMPILE_FLAGS "${_compile_flags} -D${_symbol_definition}")
    261     ENDIF()
     219  IF(_arg_DEFINE_SYMBOL)
     220    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL ${_arg_DEFINE_SYMBOL})
     221  ELSEIF(NOT _arg_ORXONOX_EXTERNAL)
     222    # Automatically add the macro definitions for our own libraries
     223    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL "${_target_name_upper}_SHARED_BUILD")
    262224  ENDIF()
    263225
     
    279241  ENDIF()
    280242
    281   IF((${_target_type} STREQUAL "EXECUTABLE" OR NOT _arg_STATIC) AND NOT _arg_NO_INSTALL)
     243  # Install all targets except for static ones (executables also have SHARED in _link_mode)
     244  IF((${_link_mode} STREQUAL "SHARED") AND NOT _arg_NO_INSTALL)
    282245    IF(_arg_MODULE)
    283246      INSTALL(TARGETS ${_target_name}
  • code/branches/presentation3/src/CMakeLists.txt

    r7142 r7143  
    3131INCLUDE(OrxonoxConfig.cmake)
    3232
    33 ################ Library Defines ################
     33####### Library Behaviour (dependencies) ########
    3434
    3535# Disable Boost auto linking completely
     
    4646ADD_COMPILER_FLAGS("-DSTATIC_BUILD"       WIN32 NOT LINK_TCL_DYNAMIC)
    4747
     48######### Library Behaviour (external) ##########
     49
    4850# Use TinyXML++
    4951ADD_COMPILER_FLAGS("-DTIXML_USE_TICPP")
     52
     53# Default linking for externals is SHARED
     54SET(ORXONOX_EXTERNAL_LINK_MODE SHARED CACHE STRING "Link mode for external libraries that we build ourselves. Note: on Windows, some libraries cannot be linked shared.")
     55
     56IF(ORXONOX_EXTERNAL_LINK_MODE STREQUAL "SHARED")
     57  SET(_external_shared_link TRUE)
     58ELSE()
     59  SET(_external_shared_link FALSE)
     60ENDIF()
     61# If no defines are specified, these libs get linked dynamically
     62ADD_COMPILER_FLAGS("-DCEGUILUA_STATIC"             WIN32 NOT _external_shared_link)
     63ADD_COMPILER_FLAGS("-DOGRE_GUIRENDERER_STATIC_LIB" WIN32 NOT _external_shared_link)
     64ADD_COMPILER_FLAGS("-DOIS_STATIC_LIB"              WIN32 NOT _external_shared_link)
     65ADD_COMPILER_FLAGS("-DTOLUA_STATIC_BUILD"          WIN32 NOT _external_shared_link)
    5066
    5167############## Include Directories ##############
  • code/branches/presentation3/src/OrxonoxConfig.cmake

    r5929 r7143  
    2727
    2828#################### Options ####################
    29 
    30 # Default linking is SHARED
    31 SET(ORXONOX_DEFAULT_LINK SHARED)
    3229
    3330# Use, i.e. don't skip the full RPATH for the build tree
  • code/branches/presentation3/src/external/ceguilua/CMakeLists.txt

    r7135 r7143  
    7575  NO_SOURCE_GROUPS
    7676  DEFINE_SYMBOL
    77     shared "CEGUILUA_EXPORTS" static "CEGUILUA_STATIC"
     77    "CEGUILUA_EXPORTS"
    7878  VERSION
    7979    ${CEGUI_VERSION}
  • code/branches/presentation3/src/external/ogreceguirenderer/CMakeLists.txt

    r7135 r7143  
    3232ORXONOX_ADD_LIBRARY(ogreceguirenderer_orxonox
    3333  ORXONOX_EXTERNAL
     34  DEFINE_SYMBOL
     35    "OGRE_GUIRENDERER_EXPORTS"
     36  VERSION
     37    1.4.9
    3438  LINK_LIBRARIES
    3539    ${OGRE_LIBRARY}
    3640    ${CEGUI_LIBRARY}
    37   DEFINE_SYMBOL
    38     shared "OGRE_GUIRENDERER_EXPORTS" static "OGRE_GUIRENDERER_STATIC_LIB"
    39   VERSION
    40     1.4.9
    4141  SOURCE_FILES
    4242    ${OCR_FILES}
  • code/branches/presentation3/src/external/ois/CMakeLists.txt

    r7142 r7143  
    5757  ORXONOX_EXTERNAL
    5858  DEFINE_SYMBOL
    59     shared "OIS_NONCLIENT_BUILD" static "OIS_STATIC_LIB"
     59    "OIS_NONCLIENT_BUILD"
    6060  VERSION
    6161    1.2
  • code/branches/presentation3/src/external/tolua/CMakeLists.txt

    r7135 r7143  
    3535  ORXONOX_EXTERNAL
    3636  DEFINE_SYMBOL
    37     shared "TOLUA_SHARED_BUILD" static "TOLUA_STATIC_BUILD"
     37    "TOLUA_SHARED_BUILD"
    3838  VERSION
    3939    1.0.92
Note: See TracChangeset for help on using the changeset viewer.