Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.