Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/cmake/tools/TargetUtilities.cmake @ 10547

Last change on this file since 10547 was 10547, checked in by landauf, 9 years ago

added support for plugins in the buildsystem. plugins are like modules, but can be loaded/unloaded at runtime

  • Property svn:eol-style set to native
File size: 19.8 KB
Line 
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.
26 #    The output is then stored in "_arg_ARGNAME" where ARGNAME is the the
27 #    name of the switch or list.
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
36 #      MODULE:            For dynamic module libraries (libraries only)
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
40 #      WIN32:             Inherited from ADD_EXECUTABLE (executables only)
41 #      PCH_NO_DEFAULT:    Do not make precompiled header files default if
42 #                         specified with PCH_FILE
43 #      NO_INSTALL:        Do not install the target at all
44 #      NO_VERSION:        Prevents adding any version to a target
45 #      NO_BUILD_UNITS:    Disables automatic (full) build units
46 #
47 #    Lists:
48 #      LINK_LIBRARIES:    Redirects to TARGET_LINK_LIBRARIES
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
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
57 #      PCH_FILE:          Precompiled header file
58 #      PCH_EXCLUDE:       Source files to be excluded from PCH support
59 #      OUTPUT_NAME:       If you want a different name than the target name
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)
63 #  Note:
64 #    This function also installs the target!
65 #  Prerequisistes:
66 #    ORXONOX_DEFAULT_LINK
67 #  Parameters:
68 #    _target_name, ARGN for the macro arguments
69 #
70
71INCLUDE(BuildUnits)
72INCLUDE(CMakeDependentOption)
73INCLUDE(CapitaliseName)
74INCLUDE(GenerateToluaBindings)
75INCLUDE(ParseMacroArguments)
76INCLUDE(SourceFileUtilities)
77IF(PCH_COMPILER_SUPPORT)
78  INCLUDE(PrecompiledHeaderFiles)
79ENDIF()
80
81MACRO(ORXONOX_ADD_LIBRARY _target_name)
82  SET(_additional_switches MODULE PLUGIN)
83  TU_ADD_TARGET(${_target_name} LIBRARY "${_additional_switches}" ${ARGN})
84ENDMACRO(ORXONOX_ADD_LIBRARY)
85
86MACRO(ORXONOX_ADD_EXECUTABLE _target_name)
87  SET(_additional_switches WIN32)
88  TU_ADD_TARGET(${_target_name} EXECUTABLE "${_additional_switches}" ${ARGN})
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)
98    IF(CMAKE_CL_64)
99      SET(MSVC_PLATFORM "x64")
100    ELSE()
101      SET(MSVC_PLATFORM "Win32")
102    ENDIF()
103    IF(NOT (MSVC_VERSION LESS 1600)) #For all versions >= Visual Studio 2010
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)
111ENDMACRO(ORXONOX_ADD_EXECUTABLE)
112
113
114MACRO(TU_ADD_TARGET _target_name _target_type _additional_switches)
115  CAPITALISE_NAME(${_target_name} _target_name_capitalised)
116  STRING(TOUPPER "${_target_name}" _target_name_upper)
117
118  # Specify all possible options (either switch or with add. arguments)
119  SET(_switches   FIND_HEADER_FILES  EXCLUDE_FROM_ALL  ORXONOX_EXTERNAL
120                  NO_DLL_INTERFACE   NO_SOURCE_GROUPS  PCH_NO_DEFAULT 
121                  NO_INSTALL         NO_VERSION        NO_BUILD_UNITS
122                  ${_additional_switches})
123  SET(_list_names LINK_LIBRARIES     VERSION           SOURCE_FILES
124                  DEFINE_SYMBOL      TOLUA_FILES       PCH_FILE
125                  PCH_EXCLUDE        OUTPUT_NAME       LINK_LIBS_LINUX
126                  LINK_LIBS_WIN32    LINK_LIBS_APPLE   LINK_LIBS_UNIX
127                  EXCLUDE_FROM_BUILD_UNITS)
128
129  PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
130
131  # Process source files with support for build units
132  # Note: All file paths are relative to the root source directory, even the
133  #       name of the build unit.
134  SET(_${_target_name}_source_files)
135  SET(_get_build_unit_file FALSE)
136  SET(_add_to_build_unit FALSE)
137  FOREACH(_file ${_arg_SOURCE_FILES})
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")
144      ENDIF()
145      IF(ENABLE_BUILD_UNITS)
146        IF(NOT _build_unit_include_string)
147          MESSAGE(STATUS "Warning: Empty build unit!")
148        ENDIF()
149        IF(EXISTS ${_build_unit_file})
150          FILE(READ ${_build_unit_file} _include_string_file)
151        ENDIF()
152        IF(NOT _build_unit_include_string STREQUAL "${_include_string_file}")
153          FILE(WRITE ${_build_unit_file} "${_build_unit_include_string}")
154        ENDIF()
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}")
160      ENDIF()
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")
169    ELSE()
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
186      LIST(APPEND _${_target_name}_source_files ${_file})
187
188      # Handle build units
189      IF(_add_to_build_unit AND ENABLE_BUILD_UNITS)
190        IF(_file MATCHES "\\.(c|cc|cpp|cxx)$")
191          SET(_build_unit_include_string "${_build_unit_include_string}#include \"${_file}\"\n")
192          MATH(EXPR _build_unit_count "1 + ${_build_unit_count}")
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()
197    ENDIF()
198  ENDFOREACH(_file)
199
200  # Assemble all header files of the library
201  IF(_arg_FIND_HEADER_FILES)
202    GET_ALL_HEADER_FILES(_${_target_name}_header_files)
203  ENDIF()
204
205  # Combine source and header files
206  SET(_${_target_name}_files
207    ${_${_target_name}_header_files}
208    ${_${_target_name}_source_files}
209  )
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})
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()
224  ENDIF()
225
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
240  # First part (pre target) of precompiled header files
241  IF(PCH_COMPILER_SUPPORT AND _arg_PCH_FILE)
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()
248    CMAKE_DEPENDENT_OPTION(PCH_ENABLE_${_target_name_upper}
249      "Enable using precompiled header files for library ${_target_name}." ${PCH_DEFAULT} PCH_ENABLE OFF)
250    # Almost never used individually, but produces a lot of options --> hide
251    MARK_AS_ADVANCED(PCH_ENABLE_${_target_name_upper})
252
253    IF(PCH_ENABLE_${_target_name_upper} AND NOT PCH_DISABLE_${_target_name})
254      PRECOMPILED_HEADER_FILES_PRE_TARGET(${_target_name} ${_arg_PCH_FILE} _${_target_name}_files EXCLUDE ${_arg_PCH_EXCLUDE})
255    ENDIF()
256  ENDIF()
257
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)
263      # Move the ...Prereqs.h and the PCH files to the 'Config' section
264      IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_target_name_capitalised}Prereqs.h)
265        SOURCE_GROUP("Config" FILES ${_target_name_capitalised}Prereqs.h)
266      ENDIF()
267      IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_arg_PCH_FILE})
268        SOURCE_GROUP("Config" FILES ${CMAKE_CURRENT_SOURCE_DIR}/${_arg_PCH_FILE})
269      ENDIF()
270    ENDIF()
271  ENDIF()
272
273  # Set link mode (SHARED/STATIC)
274  IF(MSVC AND _arg_NO_DLL_INTERFACE)
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)
283  ENDIF()
284
285  # No warnings needed from third party libraries
286  IF(_arg_ORXONOX_EXTERNAL)
287    REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC)
288    ADD_COMPILER_FLAGS("-w" NOT MSVC)
289    ADD_COMPILER_FLAGS("-W0" MSVC)
290  ENDIF()
291
292  # Don't compile header files
293  FOREACH(_file ${_${_target_name}_files})
294    IF(NOT _file MATCHES "\\.(c|cc|cpp|cxx|mm|rc)$")
295      SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
296    ENDIF()
297  ENDFOREACH(_file)
298
299
300
301  # Add the library/executable
302  IF("${_target_type}" STREQUAL "LIBRARY")
303    ADD_LIBRARY(${_target_name} ${_link_mode}
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
310
311
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
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)
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")
328  ENDIF()
329
330  # Configure modules
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    )
336    ADD_MODULE_OR_PLUGIN(${_target_name} ${CMAKE_MODULE_OUTPUT_DIRECTORY} ${MODULE_INSTALL_DIRECTORY} ${ORXONOX_MODULE_EXTENSION})
337    # Ensure that the main program depends on the module
338    SET(ORXONOX_MODULES ${ORXONOX_MODULES} ${_target_name} CACHE INTERNAL "")
339  ENDIF()
340
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})
348  ENDIF()
349
350  # Static library flags are not globally available
351  IF(ORXONOX_STATIC_LINKER_FLAGS)
352    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES STATIC_LIBRARY_FLAGS ${ORXONOX_STATIC_LINKER_FLAGS})
353  ENDIF()
354
355  # LINK_LIBRARIES
356  IF(_arg_LINK_LIBRARIES)
357    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBRARIES})
358  ENDIF()
359  IF(_arg_LINK_LIBS_LINUX AND LINUX)
360    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_LINUX})
361  ENDIF()
362  IF(_arg_LINK_LIBS_WIN32 AND WIN32)
363    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_WIN32})
364  ENDIF()
365  IF(_arg_LINK_LIBS_APPLE AND APPLE)
366    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_APPLE})
367  ENDIF()
368  IF(_arg_LINK_LIBS_UNIX AND UNIX)
369    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_UNIX})
370  ENDIF()
371
372  # Enable gcov (gcc code coverage analysis tool) if ENABLE_GCOV flag is defined
373  IF(ENABLE_GCOV)
374    TARGET_LINK_LIBRARIES(${_target_name} gcov)
375    ADD_COMPILER_FLAGS("-fprofile-arcs")
376    ADD_COMPILER_FLAGS("-ftest-coverage")
377  ENDIF()
378
379  # Visual Leak Detector specific stuff (avoids the include)
380  IF(VISUAL_LEAK_DETECTOR_ENABLE)
381    TARGET_LINK_LIBRARIES(${_target_name} debug ${VLD_LIBRARY})
382  ENDIF()
383
384  # RPATH settings for the installation
385  IF("${_target_type}" STREQUAL "LIBRARY")
386    IF(_arg_MODULE)
387      SET(_rpath "${MODULE_RPATH}")
388    ELSEIF(_arg_PLUGIN)
389      SET(_rpath "${PLUGIN_RPATH}")
390    ELSE()
391      SET(_rpath "${LIBRARY_RPATH}")
392    ENDIF()
393  ELSE()
394    SET(_rpath "${RUNTIME_RPATH}")
395  ENDIF()
396  SET_TARGET_PROPERTIES(${_target_name} PROPERTIES INSTALL_RPATH "${_rpath}")
397
398  # DEFINE_SYMBOL
399  IF(_arg_DEFINE_SYMBOL)
400    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL ${_arg_DEFINE_SYMBOL})
401  ELSEIF(NOT _arg_ORXONOX_EXTERNAL)
402    # Automatically add the macro definitions for our own libraries
403    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL "${_target_name_upper}_SHARED_BUILD")
404  ENDIF()
405
406  # VERSION
407  IF(_arg_VERSION)
408    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${_arg_VERSION})
409  ELSEIF(NOT _arg_ORXONOX_EXTERNAL AND NOT _arg_NO_VERSION AND NOT ${_target_type} STREQUAL "EXECUTABLE")
410    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${ORXONOX_VERSION})
411  ENDIF()
412
413  # OUTPUT_NAME
414  IF(_arg_OUTPUT_NAME)
415    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES OUTPUT_NAME  ${_arg_OUTPUT_NAME})
416  ENDIF()
417
418  # Second part of precompiled header files
419  IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE_${_target_name_upper} AND _arg_PCH_FILE AND NOT PCH_DISABLE_${_target_name})
420    PRECOMPILED_HEADER_FILES_POST_TARGET(${_target_name} ${_arg_PCH_FILE})
421  ENDIF()
422
423  # Install all targets except for static ones (executables also have SHARED in _link_mode)
424  IF(${_link_mode} STREQUAL "SHARED" AND NOT _arg_NO_INSTALL)
425    IF(_arg_MODULE)
426      INSTALL(TARGETS ${_target_name}
427        RUNTIME DESTINATION ${MODULE_INSTALL_DIRECTORY}
428        LIBRARY DESTINATION ${MODULE_INSTALL_DIRECTORY}
429      )
430    ELSEIF(_arg_PLUGIN)
431      INSTALL(TARGETS ${_target_name}
432        RUNTIME DESTINATION ${PLUGIN_INSTALL_DIRECTORY}
433        LIBRARY DESTINATION ${PLUGIN_INSTALL_DIRECTORY}
434      )
435    ELSE()
436      INSTALL(TARGETS ${_target_name}
437        RUNTIME DESTINATION ${RUNTIME_INSTALL_DIRECTORY}
438        LIBRARY DESTINATION ${LIBRARY_INSTALL_DIRECTORY}
439      )
440    ENDIF()
441    IF(INSTALL_PDB_FILES) # MSVC specific: install debug symbols files
442      FOREACH(_config RelForDevs RelWithDebInfo)
443        GET_TARGET_PROPERTY(_location ${_target_name} LOCATION_${_config})
444        # Get absolute location without dll/exe extension
445        STRING(REGEX REPLACE "^(.+)\\.(dll|exe)$" "\\1" _location_we ${_location})
446        IF(_arg_MODULE)
447          INSTALL(FILES ${_location_we}.pdb
448            DESTINATION ${MODULE_INSTALL_DIRECTORY}
449            CONFIGURATIONS ${_config}
450          )
451        ELSEIF(_arg_PLUGIN)
452          INSTALL(FILES ${_location_we}.pdb
453            DESTINATION ${PLUGIN_INSTALL_DIRECTORY}
454            CONFIGURATIONS ${_config}
455          )
456        ELSE()
457          INSTALL(FILES ${_location_we}.pdb
458            DESTINATION ${RUNTIME_INSTALL_DIRECTORY}
459            CONFIGURATIONS ${_config}
460          )
461        ENDIF()
462      ENDFOREACH(_config)
463    ENDIF()
464  ENDIF()
465
466ENDMACRO(TU_ADD_TARGET)
467
468
469# Creates a helper file with name <name_of_the_library>.<extension>
470# This helps finding dynamically loadable modules or plugins at runtime
471
472FUNCTION(ADD_MODULE_OR_PLUGIN _target _output_dir _install_dir _extension)
473  # We use the properties to get the name because the librarys name may differ from
474  # the target name (for example orxonox <-> liborxonox)
475  IF (POLICY CMP0026)
476    CMAKE_POLICY(PUSH)
477    CMAKE_POLICY(SET CMP0026 OLD) # we only use the file's name, not its actual location, so the old policy is fine
478  ENDIF()
479  GET_TARGET_PROPERTY(_target_loc ${_target} LOCATION)
480  GET_FILENAME_COMPONENT(_target_name ${_target_loc} NAME_WE)
481  IF (POLICY CMP0026)
482    CMAKE_POLICY(POP) # set policy back to original settings
483  ENDIF()
484
485  IF(CMAKE_CONFIGURATION_TYPES)
486    FOREACH(_config ${CMAKE_CONFIGURATION_TYPES})
487      SET(_helper_filename ${_output_dir}/${_config}/${_target_name}${_extension})
488
489      FILE(WRITE ${_helper_filename})
490
491      INSTALL(
492        FILES ${_helper_filename}
493        DESTINATION ${_install_dir}
494        CONFIGURATIONS ${_config}
495      )
496    ENDFOREACH()
497  ELSE()
498    SET(_helper_filename ${_output_dir}/${_target_name}${_extension})
499
500    FILE(WRITE ${_helper_filename})
501
502    INSTALL(
503      FILES ${_helper_filename}
504      DESTINATION ${_install_dir}
505    )
506  ENDIF()
507ENDFUNCTION(ADD_MODULE_OR_PLUGIN)
Note: See TracBrowser for help on using the repository browser.