Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5613 was 5613, checked in by landauf, 15 years ago

replaced the old orxonox executable with an orxonox library. linked that library into the new orxonox executable which only contains one file (Orxonox.cc).

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