Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/libraries/cmake/TargetUtilities.cmake @ 5615

Last change on this file since 5615 was 5615, checked in by rgrieder, 15 years ago

Added some forgotten documentation.

  • Property svn:eol-style set to native
File size: 7.3 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 #      STATIC/SHARED:     Inherited from ADD_LIBRARY
37 #      WIN32:             Inherited from ADD_EXECUTABLE
38 #      PCH_NO_DEFAULT:    Do not make precompiled header files default if
39 #                         specified with PCH_FILE
40 #      NO_INSTALL:        Do not install the target at all
41 #
42 #    Lists:
43 #      LINK_LIBRARIES:    Redirects to TARGET_LINK_LIBRARIES
44 #      VERSION:           Set version to the binary
45 #      SOURCE_FILES:      Source files for the target
46 #      DEFINE_SYMBOL:     Sets the DEFINE_SYMBOL target property
47 #      TOLUA_FILES:       Files with tolua interface
48 #      PCH_FILE:          Precompiled header file
49 #      PCH_EXCLUDE:       Source files to be excluded from PCH support
50 #      OUTPUT_NAME:       If you want a different name than the target name
51 #  Note:
52 #    This function also installs the target!
53 #  Prerequisistes:
54 #    ORXONOX_DEFAULT_LINK, ORXONOX_CONFIG_FILES
55 #  Parameters:
56 #    _target_name, ARGN for the macro arguments
57 #
58
59INCLUDE(CapitaliseName)
60INCLUDE(GenerateToluaBindings)
61INCLUDE(ParseMacroArguments)
62INCLUDE(SourceFileUtilities)
63IF(PCH_COMPILER_SUPPORT)
64  INCLUDE(PrecompiledHeaderFiles)
65ENDIF()
66
67FUNCTION(ORXONOX_ADD_LIBRARY _target_name)
68  TU_ADD_TARGET(${_target_name} LIBRARY "STATIC;SHARED" ${ARGN})
69ENDFUNCTION(ORXONOX_ADD_LIBRARY)
70
71FUNCTION(ORXONOX_ADD_EXECUTABLE _target_name)
72  TU_ADD_TARGET(${_target_name} EXECUTABLE "WIN32" ${ARGN})
73ENDFUNCTION(ORXONOX_ADD_EXECUTABLE)
74
75
76FUNCTION(TU_ADD_TARGET _target_name _target_type _additional_switches)
77  CAPITALISE_NAME(${_target_name} _target_name_capitalised)
78
79  # Specify all possible options (either switch or with add. arguments)
80  SET(_switches   FIND_HEADER_FILES  EXCLUDE_FROM_ALL  ORXONOX_EXTERNAL
81                  NO_DLL_INTERFACE   NO_SOURCE_GROUPS  ${_additional_switches}
82                  PCH_NO_DEFAULT NO_INSTALL)
83  SET(_list_names LINK_LIBRARIES  VERSION   SOURCE_FILES  DEFINE_SYMBOL
84                  TOLUA_FILES     PCH_FILE  PCH_EXCLUDE OUTPUT_NAME)
85  PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
86
87
88  # GET_HEADER_FILES
89  IF(_arg_FIND_HEADER_FILES)
90    GET_ALL_HEADER_FILES(_${target_name}_header_files)
91  ENDIF()
92
93  # Remove potential duplicates
94  SET(_${_target_name}_files ${_${target_name}_header_files} ${_arg_SOURCE_FILES})
95  LIST(REMOVE_DUPLICATES _${_target_name}_files)
96
97  # Generate the source groups
98  IF(NOT _arg_NO_SOURCE_GROUPS)
99    GENERATE_SOURCE_GROUPS(${_${_target_name}_files})
100
101    IF(NOT _arg_ORXONOX_EXTERNAL)
102      # Move the prereqs.h file to the config section
103      IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_target_name_capitalised}Prereqs.h)
104        SOURCE_GROUP("Config" FILES ${_target_name_capitalised}Prereqs.h)
105      ENDIF()
106      # Add the config files in a special source group
107      LIST(APPEND _${_target_name}_files ${ORXONOX_CONFIG_FILES})
108      SOURCE_GROUP("Config" FILES ${ORXONOX_CONFIG_FILES})
109    ENDIF()
110  ENDIF(NOT _arg_NO_SOURCE_GROUPS)
111
112  # TOLUA_FILES
113  IF(_arg_TOLUA_FILES)
114    GENERATE_TOLUA_BINDINGS(${_target_name_capitalised} _${_target_name}_files
115                            INPUTFILES ${_arg_TOLUA_FILES})
116  ENDIF()
117
118  # First part (pre target) of precompiled header files
119  IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE AND _arg_PCH_FILE)
120    # Provide convenient option to control PCH
121    STRING(TOUPPER "${_target_name}" _target_name_upper)
122    IF(_arg_PCH_NO_DEFAULT)
123      SET(PCH_DEFAULT FALSE)
124    ELSE()
125      SET(PCH_DEFAULT TRUE)
126    ENDIF()
127    OPTION(PCH_ENABLE_${_target_name_upper} "Enable using precompiled header files for library ${_target_name}." ${PCH_DEFAULT})
128
129    IF(PCH_ENABLE_${_target_name_upper})
130      PRECOMPILED_HEADER_FILES_PRE_TARGET(${_target_name} ${_arg_PCH_FILE} _${_target_name}_files EXCLUDE ${_arg_PCH_EXCLUDE})
131    ENDIF()
132  ENDIF()
133
134  # Certain libraries don't have dllexport/dllimport and can't be linked shared with msvc
135  IF(MSVC AND _arg_NO_DLL_INTERFACE)
136    SET(_arg_SHARED)
137    SET(_arg_STATIC STATIC)
138  ENDIF()
139
140  # Set default linking if required
141  IF(NOT _arg_SHARED AND NOT _arg_STATIC)
142    IF("${ORXONOX_DEFAULT_LINK}" STREQUAL "STATIC")
143      SET(_arg_STATIC STATIC)
144    ELSEIF("${ORXONOX_DEFAULT_LINK}" STREQUAL "SHARED")
145      SET(_arg_SHARED SHARED)
146    ENDIF()
147  ENDIF()
148
149  # Add the library/executable
150  IF("${_target_type}" STREQUAL "LIBRARY")
151    ADD_LIBRARY(${_target_name} ${_arg_STATIC} ${_arg_SHARED}
152                ${_arg_EXCLUDE_FROM_ALL} ${_${_target_name}_files})
153  ELSE()
154    ADD_EXECUTABLE(${_target_name} ${_arg_WIN32} ${_arg_EXCLUDE_FROM_ALL}
155                   ${_${_target_name}_files})
156  ENDIF()
157
158  # LINK_LIBRARIES
159  IF(_arg_LINK_LIBRARIES)
160    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBRARIES})
161  ENDIF()
162
163  # DEFINE_SYMBOL
164  IF(_arg_DEFINE_SYMBOL)
165    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL ${_arg_DEFINE_SYMBOL})
166  ENDIF()
167
168  # VERSION
169  IF(_arg_VERSION)
170    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${_arg_VERSION})
171  ELSEIF(NOT _arg_ORXONOX_EXTERNAL)
172    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${ORXONOX_VERSION})
173  ENDIF()
174
175  # OUTPUT_NAME
176  IF(_arg_OUTPUT_NAME )
177    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES OUTPUT_NAME  ${_arg_OUTPUT_NAME})
178  ENDIF()
179
180  # Second part of precompiled header files
181  IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE_${_target_name_upper} AND _arg_PCH_FILE)
182    PRECOMPILED_HEADER_FILES_POST_TARGET(${_target_name} ${_arg_PCH_FILE})
183  ENDIF()
184
185  IF(NOT _arg_STATIC AND NOT _arg_NO_INSTALL)
186    INSTALL(TARGETS ${_target_name}
187      RUNTIME DESTINATION ${ORXONOX_RUNTIME_INSTALL_PATH}
188      LIBRARY DESTINATION ${ORXONOX_LIBRARY_INSTALL_PATH}
189      #ARCHIVE DESTINATION ${ORXONOX_ARCHIVE_INSTALL_PATH}
190    )
191  ENDIF()
192
193ENDFUNCTION(TU_ADD_TARGET)
Note: See TracBrowser for help on using the repository browser.