Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/cmake/tools/TargetUtilities.cmake @ 12227

Last change on this file since 12227 was 11693, checked in by landauf, 7 years ago

apparently we must create the directory for module/plugin-files manually to make it work with some (older?) versions of CMake

  • Property svn:eol-style set to native
File size: 19.7 KB
RevLine 
[3116]1 #
2 #             ORXONOX - the hottest 3D action shooter ever to exist
3 #                             > www.orxonox.net <
4 #
5 #        This program is free software; you can redistribute it and/or
6 #         modify it under the terms of the GNU General Public License
7 #        as published by the Free Software Foundation; either version 2
8 #            of the License, or (at your option) any later version.
9 #
10 #       This program is distributed in the hope that it will be useful,
11 #        but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #                 GNU General Public License for more details.
14 #
15 #   You should have received a copy of the GNU General Public License along
16 #      with this program; if not, write to the Free Software Foundation,
17 #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 #
19 #
20 #  Author:
21 #    Reto Grieder
22 #  Description:
23 #    Adds a library or an executable like ADD_LIBRARY/ADD_EXECUTABLE, but
24 #    accepts a lot more input information. Simply supply the keywords
25 #    described below in any order you wish.
[5693]26 #    The output is then stored in "_arg_ARGNAME" where ARGNAME is the the
27 #    name of the switch or list.
[3116]28 #
29 #    Switches: (when given --> TRUE, FALSE otherwise)
30 #      FIND_HEADER_FILES: Searches the current directory for all header files
31 #                         and adds them to the target.
32 #      EXCLUDE_FROM_ALL:  Inherited from ADD_LIBRARY/ADD_EXECUTABLE
33 #      ORXONOX_EXTERNAL:  Specify this for third party libraries
34 #      NO_DLL_INTERFACE:  Link statically with MSVC
35 #      NO_SOURCE_GROUPS:  Don't create msvc source groups
[7143]36 #      MODULE:            For dynamic module libraries (libraries only)
[10624]37 #      PLUGIN:            For dynamic plugin libraries (libraries only)
38 #                         Plugins are a special kind of modules that can be
39 #                         loaded and unloaded during runtime on demand
[7143]40 #      WIN32:             Inherited from ADD_EXECUTABLE (executables only)
[3117]41 #      PCH_NO_DEFAULT:    Do not make precompiled header files default if
42 #                         specified with PCH_FILE
[5693]43 #      NO_INSTALL:        Do not install the target at all
[7123]44 #      NO_VERSION:        Prevents adding any version to a target
[8729]45 #      NO_BUILD_UNITS:    Disables automatic (full) build units
[5693]46 #
[3116]47 #    Lists:
48 #      LINK_LIBRARIES:    Redirects to TARGET_LINK_LIBRARIES
[8351]49 #      LINK_LIBS_LINUX:   Redirects to TARGET_LINK_LIBRARIES only on Linux
50 #      LINK_LIBS_WIN32:   Redirects to TARGET_LINK_LIBRARIES only on Windows
51 #      LINK_LIBS_APPLE:   Redirects to TARGET_LINK_LIBRARIES only on Apple
52 #      LINK_LIBS_UNIX:    Redirects to TARGET_LINK_LIBRARIES only on UNIX
[3116]53 #      VERSION:           Set version to the binary
54 #      SOURCE_FILES:      Source files for the target
55 #      DEFINE_SYMBOL:     Sets the DEFINE_SYMBOL target property
56 #      TOLUA_FILES:       Files with tolua interface
[3117]57 #      PCH_FILE:          Precompiled header file
58 #      PCH_EXCLUDE:       Source files to be excluded from PCH support
[5693]59 #      OUTPUT_NAME:       If you want a different name than the target name
[8729]60 #      EXCLUDE_FROM_BUILD_UNITS: Specifies files that are not put into
61 #                         automatic (full) build units. They can still
62 #                         explicitely be included in a BUILD_UNIT (partial)
[3116]63 #  Note:
64 #    This function also installs the target!
65 #  Prerequisistes:
[8351]66 #    ORXONOX_DEFAULT_LINK
[3116]67 #  Parameters:
68 #    _target_name, ARGN for the macro arguments
69 #
70
[8729]71INCLUDE(BuildUnits)
[5695]72INCLUDE(CMakeDependentOption)
[3116]73INCLUDE(CapitaliseName)
74INCLUDE(GenerateToluaBindings)
75INCLUDE(ParseMacroArguments)
76INCLUDE(SourceFileUtilities)
[3117]77IF(PCH_COMPILER_SUPPORT)
78  INCLUDE(PrecompiledHeaderFiles)
79ENDIF()
[3116]80
[5929]81MACRO(ORXONOX_ADD_LIBRARY _target_name)
[10624]82  SET(_additional_switches MODULE PLUGIN)
83  TU_ADD_TARGET(${_target_name} LIBRARY "${_additional_switches}" ${ARGN})
[5929]84ENDMACRO(ORXONOX_ADD_LIBRARY)
[3116]85
[5929]86MACRO(ORXONOX_ADD_EXECUTABLE _target_name)
[10624]87  SET(_additional_switches WIN32)
88  TU_ADD_TARGET(${_target_name} EXECUTABLE "${_additional_switches}" ${ARGN})
[9550]89 
90  # When using Visual Studio we want to use the output directory as working
91  # directory and we also want to specify where the external dlls
92  # (lua, ogre, etc.) are. The problem hereby is that these information cannot
93  # be specified in CMake because they are not stored in the actual project file.
94  # This workaround will create a configured *.vcproj.user file that holds the
95  # right values. When starting the solution for the first time,
96  # these get written to the *vcproj.yourPCname.yourname.user
97  IF(MSVC)
[9595]98    IF(CMAKE_CL_64)
99      SET(MSVC_PLATFORM "x64")
100    ELSE()
101      SET(MSVC_PLATFORM "Win32")
102    ENDIF()
[10252]103    IF(NOT (MSVC_VERSION LESS 1600)) #For all versions >= Visual Studio 2010
[9550]104      CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/src/template.vcxproj.user.in" "${CMAKE_CURRENT_BINARY_DIR}/${_target_name}.vcxproj.user")
105    ELSE()
106      STRING(REGEX REPLACE "^Visual Studio ([0-9][0-9]?).*$" "\\1"
107             VISUAL_STUDIO_VERSION_SIMPLE "${CMAKE_GENERATOR}")
108      CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/src/template.vcproj.user.in" "${CMAKE_CURRENT_BINARY_DIR}/${_target_name}.vcproj.user")
109    ENDIF()
110  ENDIF(MSVC)
[5929]111ENDMACRO(ORXONOX_ADD_EXECUTABLE)
[3116]112
113
[5929]114MACRO(TU_ADD_TARGET _target_name _target_type _additional_switches)
[3116]115  CAPITALISE_NAME(${_target_name} _target_name_capitalised)
[7132]116  STRING(TOUPPER "${_target_name}" _target_name_upper)
[3116]117
118  # Specify all possible options (either switch or with add. arguments)
119  SET(_switches   FIND_HEADER_FILES  EXCLUDE_FROM_ALL  ORXONOX_EXTERNAL
[7143]120                  NO_DLL_INTERFACE   NO_SOURCE_GROUPS  PCH_NO_DEFAULT 
[8729]121                  NO_INSTALL         NO_VERSION        NO_BUILD_UNITS
122                  ${_additional_switches})
[7415]123  SET(_list_names LINK_LIBRARIES     VERSION           SOURCE_FILES
124                  DEFINE_SYMBOL      TOLUA_FILES       PCH_FILE
[8351]125                  PCH_EXCLUDE        OUTPUT_NAME       LINK_LIBS_LINUX
[8729]126                  LINK_LIBS_WIN32    LINK_LIBS_APPLE   LINK_LIBS_UNIX
127                  EXCLUDE_FROM_BUILD_UNITS)
[7415]128
[3116]129  PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
130
[8729]131  # Process source files with support for build units
[7818]132  # Note: All file paths are relative to the root source directory, even the
[8729]133  #       name of the build unit.
[7818]134  SET(_${_target_name}_source_files)
[8729]135  SET(_get_build_unit_file FALSE)
136  SET(_add_to_build_unit FALSE)
[5929]137  FOREACH(_file ${_arg_SOURCE_FILES})
[8729]138    IF(_file STREQUAL "BUILD_UNIT")
139      # Next file is the name of the build unit
140      SET(_get_build_unit_file TRUE)
141    ELSEIF(_file STREQUAL "END_BUILD_UNIT")
142      IF(NOT _build_unit_file)
143        MESSAGE(FATAL_ERROR "No name provided for build unit")
[7818]144      ENDIF()
[8729]145      IF(ENABLE_BUILD_UNITS)
146        IF(NOT _build_unit_include_string)
147          MESSAGE(STATUS "Warning: Empty build unit!")
[8351]148        ENDIF()
[8729]149        IF(EXISTS ${_build_unit_file})
150          FILE(READ ${_build_unit_file} _include_string_file)
[7818]151        ENDIF()
[8729]152        IF(NOT _build_unit_include_string STREQUAL "${_include_string_file}")
153          FILE(WRITE ${_build_unit_file} "${_build_unit_include_string}")
[7818]154        ENDIF()
[8729]155        LIST(APPEND _${_target_name}_source_files ${_build_unit_file})
156        LIST(APPEND _${_target_name}_build_units ${_build_unit_file})
157        # Store the number of files included. May be used for full build units.
158        SET_SOURCE_FILES_PROPERTIES(${_build_unit_file}
159          PROPERTIES BUILD_UNIT_SIZE "${_build_unit_count}")
[7818]160      ENDIF()
[8729]161      SET(_add_to_build_unit FALSE)
162    ELSEIF(_get_build_unit_file)
163      # Note: ${_file} is relative to the binary directory
164      SET(_build_unit_file ${CMAKE_BINARY_DIR}/${_file})
165      SET(_get_build_unit_file FALSE)
166      SET(_add_to_build_unit TRUE)
167      SET(_build_unit_include_string)
168      SET(_build_unit_count "0")
[5929]169    ELSE()
[7818]170      # Default, add source file
171
172      # Prepare relative paths
173      IF(NOT _file MATCHES "^(.\\:|\\/)")
174        # Path can be relative to the current source directory if the file was
175        # not added with the source file macros. Otherwise there is a "./" at
176        # the beginning of each file and the filename is relative
177        # to the CMAKE_SOURCE_DIR
178        STRING(REGEX REPLACE "^\\.\\/(.+)$" "\\1" _temp ${_file})
179        IF(NOT ${_temp} STREQUAL ${_file})
180          SET(_file ${CMAKE_SOURCE_DIR}/${_temp})
181        ELSE()
182          SET(_file ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
183        ENDIF()
184      ENDIF()
185
[5929]186      LIST(APPEND _${_target_name}_source_files ${_file})
[7818]187
[8729]188      # Handle build units
189      IF(_add_to_build_unit AND ENABLE_BUILD_UNITS)
[7818]190        IF(_file MATCHES "\\.(c|cc|cpp|cxx)$")
[8729]191          SET(_build_unit_include_string "${_build_unit_include_string}#include \"${_file}\"\n")
192          MATH(EXPR _build_unit_count "1 + ${_build_unit_count}")
[7818]193        ENDIF()
194        # Don't compile these files, even if they are source files
195        SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
196      ENDIF()
[5929]197    ENDIF()
198  ENDFOREACH(_file)
199
200  # Assemble all header files of the library
[3116]201  IF(_arg_FIND_HEADER_FILES)
[5929]202    GET_ALL_HEADER_FILES(_${_target_name}_header_files)
[3116]203  ENDIF()
204
[7415]205  # Combine source and header files
206  SET(_${_target_name}_files
207    ${_${_target_name}_header_files}
208    ${_${_target_name}_source_files}
209  )
[3116]210  # Remove potential duplicates
211  LIST(REMOVE_DUPLICATES _${_target_name}_files)
212
213  # TOLUA_FILES
214  IF(_arg_TOLUA_FILES)
215    GENERATE_TOLUA_BINDINGS(${_target_name_capitalised} _${_target_name}_files
216                            INPUTFILES ${_arg_TOLUA_FILES})
[8351]217    # Workaround for XCode: The folder where the bind files are written to has
218    # to be present beforehand.
219    IF(CMAKE_CONFIGURATION_TYPES)
220      FOREACH(_dir ${CMAKE_CONFIGURATION_TYPES})
221        FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_dir})
222      ENDFOREACH(_dir)
223    ENDIF()
[3116]224  ENDIF()
225
[8729]226  # Mark files to be excluded from build units
227  IF(_arg_EXCLUDE_FROM_BUILD_UNITS)
228    SET_SOURCE_FILES_PROPERTIES(${_arg_EXCLUDE_FROM_BUILD_UNITS}
229      PROPERTIES EXCLUDE_FROM_BUILD_UNITS TRUE)
230  ENDIF()
231
232  # Full build units
233  IF(ENABLE_BUILD_UNITS AND NOT _arg_NO_BUILD_UNITS)
234    # Use full build units even in partial mode for externals
235    IF(ENABLE_BUILD_UNITS MATCHES "full" OR _arg_ORXONOX_EXTERNAL)
236      GENERATE_BUILD_UNITS(${_target_name} _${_target_name}_files)
237    ENDIF()
238  ENDIF()
239
[3117]240  # First part (pre target) of precompiled header files
[5695]241  IF(PCH_COMPILER_SUPPORT AND _arg_PCH_FILE)
[3117]242    # Provide convenient option to control PCH
243    IF(_arg_PCH_NO_DEFAULT)
244      SET(PCH_DEFAULT FALSE)
245    ELSE()
246      SET(PCH_DEFAULT TRUE)
247    ENDIF()
[5695]248    CMAKE_DEPENDENT_OPTION(PCH_ENABLE_${_target_name_upper}
249      "Enable using precompiled header files for library ${_target_name}." ${PCH_DEFAULT} PCH_ENABLE OFF)
[8421]250    # Almost never used individually, but produces a lot of options --> hide
251    MARK_AS_ADVANCED(PCH_ENABLE_${_target_name_upper})
[3117]252
[8729]253    IF(PCH_ENABLE_${_target_name_upper} AND NOT PCH_DISABLE_${_target_name})
[3117]254      PRECOMPILED_HEADER_FILES_PRE_TARGET(${_target_name} ${_arg_PCH_FILE} _${_target_name}_files EXCLUDE ${_arg_PCH_EXCLUDE})
255    ENDIF()
256  ENDIF()
257
[7415]258  # Generate the source groups
259  IF(MSVC AND NOT _arg_NO_SOURCE_GROUPS)
260    GENERATE_SOURCE_GROUPS(${_${_target_name}_files})
261
262    IF(NOT _arg_ORXONOX_EXTERNAL)
[8351]263      # Move the ...Prereqs.h and the PCH files to the 'Config' section
[7415]264      IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_target_name_capitalised}Prereqs.h)
265        SOURCE_GROUP("Config" FILES ${_target_name_capitalised}Prereqs.h)
266      ENDIF()
[8351]267      IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_arg_PCH_FILE})
268        SOURCE_GROUP("Config" FILES ${CMAKE_CURRENT_SOURCE_DIR}/${_arg_PCH_FILE})
269      ENDIF()
[7415]270    ENDIF()
[7416]271  ENDIF()
[7415]272
[7143]273  # Set link mode (SHARED/STATIC)
[3116]274  IF(MSVC AND _arg_NO_DLL_INTERFACE)
[7143]275    # Certain libraries don't have dllexport/dllimport and can't be linked shared with MSVC
276    SET(_link_mode STATIC)
277  ELSEIF(_arg_ORXONOX_EXTERNAL)
278    # Externals can be linked shared or statically
279    SET(_link_mode ${ORXONOX_EXTERNAL_LINK_MODE})
280  ELSE()
281    # All our own libraries are linked dynamically because of static symbols
282    SET(_link_mode SHARED)
[3116]283  ENDIF()
284
[5929]285  # No warnings needed from third party libraries
286  IF(_arg_ORXONOX_EXTERNAL)
287    REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC)
[8351]288    ADD_COMPILER_FLAGS("-w" NOT MSVC)
289    ADD_COMPILER_FLAGS("-W0" MSVC)
[5929]290  ENDIF()
291
[5901]292  # Don't compile header files
293  FOREACH(_file ${_${_target_name}_files})
[10267]294    IF(NOT _file MATCHES "\\.(c|cc|cpp|cxx|mm|rc)$")
[5901]295      SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
296    ENDIF()
297  ENDFOREACH(_file)
298
[5963]299
300
[3116]301  # Add the library/executable
302  IF("${_target_type}" STREQUAL "LIBRARY")
[7143]303    ADD_LIBRARY(${_target_name} ${_link_mode}
[3116]304                ${_arg_EXCLUDE_FROM_ALL} ${_${_target_name}_files})
305  ELSE()
306    ADD_EXECUTABLE(${_target_name} ${_arg_WIN32} ${_arg_EXCLUDE_FROM_ALL}
307                   ${_${_target_name}_files})
308  ENDIF()
309
[5963]310
311
[5929]312  # Change library prefix to "lib"
313  IF(MSVC AND ${_target_type} STREQUAL "LIBRARY")
314    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES
315      PREFIX "lib"
316    )
317  ENDIF()
318
[5963]319  # MSVC hack to exclude external library sources from the intellisense database
320  # (IntelliSense stops working when adding "-Zm1000" as compile flag. "/Zm1000"
321  # would not work because of the slash)
322  IF(_arg_ORXONOX_EXTERNAL AND MSVC)
[7137]323    GET_TARGET_PROPERTY(_compile_flags ${_target_name} COMPILE_FLAGS)
324    IF(NOT _compile_flags)
325      SET(_compile_flags)
326    ENDIF()
327    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES COMPILE_FLAGS "${_compile_flags} -Zm1000")
[5963]328  ENDIF()
329
[7143]330  # Configure modules
[5693]331  IF (_arg_MODULE)
332    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES
333      RUNTIME_OUTPUT_DIRECTORY ${CMAKE_MODULE_OUTPUT_DIRECTORY} # Windows
334      LIBRARY_OUTPUT_DIRECTORY ${CMAKE_MODULE_OUTPUT_DIRECTORY} # Unix
335    )
[10624]336    ADD_MODULE_OR_PLUGIN(${_target_name} ${CMAKE_MODULE_OUTPUT_DIRECTORY} ${MODULE_INSTALL_DIRECTORY} ${ORXONOX_MODULE_EXTENSION})
[7401]337    # Ensure that the main program depends on the module
[8079]338    SET(ORXONOX_MODULES ${ORXONOX_MODULES} ${_target_name} CACHE INTERNAL "")
[5693]339  ENDIF()
340
[10624]341  # Configure plugins
342  IF (_arg_PLUGIN)
343    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES
344      RUNTIME_OUTPUT_DIRECTORY ${CMAKE_PLUGIN_OUTPUT_DIRECTORY} # Windows
345      LIBRARY_OUTPUT_DIRECTORY ${CMAKE_PLUGIN_OUTPUT_DIRECTORY} # Unix
346    )
347    ADD_MODULE_OR_PLUGIN(${_target_name} ${CMAKE_PLUGIN_OUTPUT_DIRECTORY} ${PLUGIN_INSTALL_DIRECTORY} ${ORXONOX_PLUGIN_EXTENSION})
[10716]348    # Ensure that the main program depends on the plugin
349    SET(ORXONOX_MODULES ${ORXONOX_MODULES} ${_target_name} CACHE INTERNAL "")
[10624]350  ENDIF()
351
[7818]352  # Static library flags are not globally available
353  IF(ORXONOX_STATIC_LINKER_FLAGS)
354    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES STATIC_LIBRARY_FLAGS ${ORXONOX_STATIC_LINKER_FLAGS})
355  ENDIF()
356
[3116]357  # LINK_LIBRARIES
358  IF(_arg_LINK_LIBRARIES)
359    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBRARIES})
360  ENDIF()
[8351]361  IF(_arg_LINK_LIBS_LINUX AND LINUX)
362    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_LINUX})
363  ENDIF()
364  IF(_arg_LINK_LIBS_WIN32 AND WIN32)
365    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_WIN32})
366  ENDIF()
367  IF(_arg_LINK_LIBS_APPLE AND APPLE)
368    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_APPLE})
369  ENDIF()
370  IF(_arg_LINK_LIBS_UNIX AND UNIX)
371    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_UNIX})
372  ENDIF()
[3116]373
[9550]374  # Enable gcov (gcc code coverage analysis tool) if ENABLE_GCOV flag is defined
375  IF(ENABLE_GCOV)
376    TARGET_LINK_LIBRARIES(${_target_name} gcov)
377    ADD_COMPILER_FLAGS("-fprofile-arcs")
378    ADD_COMPILER_FLAGS("-ftest-coverage")
379  ENDIF()
380
[8409]381  # Visual Leak Detector specific stuff (avoids the include)
[8412]382  IF(VISUAL_LEAK_DETECTOR_ENABLE)
383    TARGET_LINK_LIBRARIES(${_target_name} debug ${VLD_LIBRARY})
[8409]384  ENDIF()
385
[8351]386  # RPATH settings for the installation
387  IF("${_target_type}" STREQUAL "LIBRARY")
388    IF(_arg_MODULE)
389      SET(_rpath "${MODULE_RPATH}")
[10624]390    ELSEIF(_arg_PLUGIN)
391      SET(_rpath "${PLUGIN_RPATH}")
[8351]392    ELSE()
393      SET(_rpath "${LIBRARY_RPATH}")
394    ENDIF()
395  ELSE()
396    SET(_rpath "${RUNTIME_RPATH}")
397  ENDIF()
398  SET_TARGET_PROPERTIES(${_target_name} PROPERTIES INSTALL_RPATH "${_rpath}")
399
[3116]400  # DEFINE_SYMBOL
[7143]401  IF(_arg_DEFINE_SYMBOL)
402    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL ${_arg_DEFINE_SYMBOL})
403  ELSEIF(NOT _arg_ORXONOX_EXTERNAL)
404    # Automatically add the macro definitions for our own libraries
405    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL "${_target_name_upper}_SHARED_BUILD")
[3116]406  ENDIF()
407
408  # VERSION
409  IF(_arg_VERSION)
410    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${_arg_VERSION})
[7131]411  ELSEIF(NOT _arg_ORXONOX_EXTERNAL AND NOT _arg_NO_VERSION AND NOT ${_target_type} STREQUAL "EXECUTABLE")
[3116]412    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${ORXONOX_VERSION})
413  ENDIF()
414
[5693]415  # OUTPUT_NAME
416  IF(_arg_OUTPUT_NAME)
417    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES OUTPUT_NAME  ${_arg_OUTPUT_NAME})
418  ENDIF()
419
[3117]420  # Second part of precompiled header files
[8729]421  IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE_${_target_name_upper} AND _arg_PCH_FILE AND NOT PCH_DISABLE_${_target_name})
[3117]422    PRECOMPILED_HEADER_FILES_POST_TARGET(${_target_name} ${_arg_PCH_FILE})
423  ENDIF()
424
[7143]425  # Install all targets except for static ones (executables also have SHARED in _link_mode)
[7170]426  IF(${_link_mode} STREQUAL "SHARED" AND NOT _arg_NO_INSTALL)
[5693]427    IF(_arg_MODULE)
428      INSTALL(TARGETS ${_target_name}
[5695]429        RUNTIME DESTINATION ${MODULE_INSTALL_DIRECTORY}
430        LIBRARY DESTINATION ${MODULE_INSTALL_DIRECTORY}
[5693]431      )
[10624]432    ELSEIF(_arg_PLUGIN)
433      INSTALL(TARGETS ${_target_name}
434        RUNTIME DESTINATION ${PLUGIN_INSTALL_DIRECTORY}
435        LIBRARY DESTINATION ${PLUGIN_INSTALL_DIRECTORY}
436      )
[5693]437    ELSE()
438      INSTALL(TARGETS ${_target_name}
[5695]439        RUNTIME DESTINATION ${RUNTIME_INSTALL_DIRECTORY}
440        LIBRARY DESTINATION ${LIBRARY_INSTALL_DIRECTORY}
[5693]441      )
442    ENDIF()
[8405]443    IF(INSTALL_PDB_FILES) # MSVC specific: install debug symbols files
444      FOREACH(_config RelForDevs RelWithDebInfo)
445        GET_TARGET_PROPERTY(_location ${_target_name} LOCATION_${_config})
446        # Get absolute location without dll/exe extension
447        STRING(REGEX REPLACE "^(.+)\\.(dll|exe)$" "\\1" _location_we ${_location})
448        IF(_arg_MODULE)
449          INSTALL(FILES ${_location_we}.pdb
450            DESTINATION ${MODULE_INSTALL_DIRECTORY}
451            CONFIGURATIONS ${_config}
452          )
[10624]453        ELSEIF(_arg_PLUGIN)
454          INSTALL(FILES ${_location_we}.pdb
455            DESTINATION ${PLUGIN_INSTALL_DIRECTORY}
456            CONFIGURATIONS ${_config}
457          )
[8405]458        ELSE()
459          INSTALL(FILES ${_location_we}.pdb
460            DESTINATION ${RUNTIME_INSTALL_DIRECTORY}
461            CONFIGURATIONS ${_config}
462          )
463        ENDIF()
464      ENDFOREACH(_config)
465    ENDIF()
[3116]466  ENDIF()
467
[5929]468ENDMACRO(TU_ADD_TARGET)
[5693]469
470
[11692]471# Creates a helper file with name <target_name>.<extension> and content <filename_of_the_library>
[10624]472# This helps finding dynamically loadable modules or plugins at runtime
[5693]473
[10624]474FUNCTION(ADD_MODULE_OR_PLUGIN _target_name _output_dir _install_dir _extension)
[5693]475
476  IF(CMAKE_CONFIGURATION_TYPES)
477    FOREACH(_config ${CMAKE_CONFIGURATION_TYPES})
[11693]478      SET(_helper_directory ${_output_dir}/${_config})
479      FILE(MAKE_DIRECTORY ${_helper_directory})
480      SET(_helper_filename ${_helper_directory}/${_target_name}${_extension})
[5693]481
[11692]482      FILE(GENERATE OUTPUT ${_helper_filename} CONTENT $<TARGET_FILE_NAME:${_target_name}>)
[5693]483
484      INSTALL(
[10624]485        FILES ${_helper_filename}
486        DESTINATION ${_install_dir}
[5693]487        CONFIGURATIONS ${_config}
488      )
489    ENDFOREACH()
490  ELSE()
[11693]491    SET(_helper_directory ${_output_dir})
492    FILE(MAKE_DIRECTORY ${_helper_directory})
493    SET(_helper_filename ${_helper_directory}/${_target_name}${_extension})
[5693]494
[11692]495    FILE(GENERATE OUTPUT ${_helper_filename} CONTENT $<TARGET_FILE_NAME:${_target_name}>)
[5693]496
497    INSTALL(
[10624]498      FILES ${_helper_filename}
499      DESTINATION ${_install_dir}
[5693]500    )
501  ENDIF()
[10624]502ENDFUNCTION(ADD_MODULE_OR_PLUGIN)
Note: See TracBrowser for help on using the repository browser.