[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. |
---|
[5615] | 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 |
---|
| 36 | # STATIC/SHARED: Inherited from ADD_LIBRARY |
---|
[5666] | 37 | # MODULE: For dynamic module libraries |
---|
[3116] | 38 | # WIN32: Inherited from ADD_EXECUTABLE |
---|
[3117] | 39 | # PCH_NO_DEFAULT: Do not make precompiled header files default if |
---|
| 40 | # specified with PCH_FILE |
---|
[5615] | 41 | # NO_INSTALL: Do not install the target at all |
---|
| 42 | # |
---|
[3116] | 43 | # Lists: |
---|
| 44 | # LINK_LIBRARIES: Redirects to TARGET_LINK_LIBRARIES |
---|
| 45 | # VERSION: Set version to the binary |
---|
| 46 | # SOURCE_FILES: Source files for the target |
---|
| 47 | # DEFINE_SYMBOL: Sets the DEFINE_SYMBOL target property |
---|
| 48 | # TOLUA_FILES: Files with tolua interface |
---|
[3117] | 49 | # PCH_FILE: Precompiled header file |
---|
| 50 | # PCH_EXCLUDE: Source files to be excluded from PCH support |
---|
[5613] | 51 | # OUTPUT_NAME: If you want a different name than the target name |
---|
[3116] | 52 | # Note: |
---|
| 53 | # This function also installs the target! |
---|
| 54 | # Prerequisistes: |
---|
| 55 | # ORXONOX_DEFAULT_LINK, ORXONOX_CONFIG_FILES |
---|
| 56 | # Parameters: |
---|
| 57 | # _target_name, ARGN for the macro arguments |
---|
| 58 | # |
---|
| 59 | |
---|
| 60 | INCLUDE(CapitaliseName) |
---|
| 61 | INCLUDE(GenerateToluaBindings) |
---|
| 62 | INCLUDE(ParseMacroArguments) |
---|
| 63 | INCLUDE(SourceFileUtilities) |
---|
[3117] | 64 | IF(PCH_COMPILER_SUPPORT) |
---|
| 65 | INCLUDE(PrecompiledHeaderFiles) |
---|
| 66 | ENDIF() |
---|
[3116] | 67 | |
---|
| 68 | FUNCTION(ORXONOX_ADD_LIBRARY _target_name) |
---|
| 69 | TU_ADD_TARGET(${_target_name} LIBRARY "STATIC;SHARED" ${ARGN}) |
---|
| 70 | ENDFUNCTION(ORXONOX_ADD_LIBRARY) |
---|
| 71 | |
---|
| 72 | FUNCTION(ORXONOX_ADD_EXECUTABLE _target_name) |
---|
| 73 | TU_ADD_TARGET(${_target_name} EXECUTABLE "WIN32" ${ARGN}) |
---|
| 74 | ENDFUNCTION(ORXONOX_ADD_EXECUTABLE) |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | FUNCTION(TU_ADD_TARGET _target_name _target_type _additional_switches) |
---|
| 78 | CAPITALISE_NAME(${_target_name} _target_name_capitalised) |
---|
| 79 | |
---|
| 80 | # Specify all possible options (either switch or with add. arguments) |
---|
| 81 | SET(_switches FIND_HEADER_FILES EXCLUDE_FROM_ALL ORXONOX_EXTERNAL |
---|
[3117] | 82 | NO_DLL_INTERFACE NO_SOURCE_GROUPS ${_additional_switches} |
---|
[5666] | 83 | PCH_NO_DEFAULT NO_INSTALL MODULE) |
---|
[3116] | 84 | SET(_list_names LINK_LIBRARIES VERSION SOURCE_FILES DEFINE_SYMBOL |
---|
[5613] | 85 | TOLUA_FILES PCH_FILE PCH_EXCLUDE OUTPUT_NAME) |
---|
[3116] | 86 | PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN}) |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | # GET_HEADER_FILES |
---|
| 90 | IF(_arg_FIND_HEADER_FILES) |
---|
| 91 | GET_ALL_HEADER_FILES(_${target_name}_header_files) |
---|
| 92 | ENDIF() |
---|
| 93 | |
---|
| 94 | # Remove potential duplicates |
---|
| 95 | SET(_${_target_name}_files ${_${target_name}_header_files} ${_arg_SOURCE_FILES}) |
---|
| 96 | LIST(REMOVE_DUPLICATES _${_target_name}_files) |
---|
| 97 | |
---|
| 98 | # Generate the source groups |
---|
| 99 | IF(NOT _arg_NO_SOURCE_GROUPS) |
---|
| 100 | GENERATE_SOURCE_GROUPS(${_${_target_name}_files}) |
---|
| 101 | |
---|
| 102 | IF(NOT _arg_ORXONOX_EXTERNAL) |
---|
| 103 | # Move the prereqs.h file to the config section |
---|
| 104 | IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_target_name_capitalised}Prereqs.h) |
---|
| 105 | SOURCE_GROUP("Config" FILES ${_target_name_capitalised}Prereqs.h) |
---|
| 106 | ENDIF() |
---|
| 107 | # Add the config files in a special source group |
---|
| 108 | LIST(APPEND _${_target_name}_files ${ORXONOX_CONFIG_FILES}) |
---|
| 109 | SOURCE_GROUP("Config" FILES ${ORXONOX_CONFIG_FILES}) |
---|
| 110 | ENDIF() |
---|
| 111 | ENDIF(NOT _arg_NO_SOURCE_GROUPS) |
---|
| 112 | |
---|
| 113 | # TOLUA_FILES |
---|
| 114 | IF(_arg_TOLUA_FILES) |
---|
| 115 | GENERATE_TOLUA_BINDINGS(${_target_name_capitalised} _${_target_name}_files |
---|
| 116 | INPUTFILES ${_arg_TOLUA_FILES}) |
---|
| 117 | ENDIF() |
---|
| 118 | |
---|
[3117] | 119 | # First part (pre target) of precompiled header files |
---|
[3330] | 120 | IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE AND _arg_PCH_FILE) |
---|
[3117] | 121 | # Provide convenient option to control PCH |
---|
| 122 | STRING(TOUPPER "${_target_name}" _target_name_upper) |
---|
| 123 | IF(_arg_PCH_NO_DEFAULT) |
---|
| 124 | SET(PCH_DEFAULT FALSE) |
---|
| 125 | ELSE() |
---|
| 126 | SET(PCH_DEFAULT TRUE) |
---|
| 127 | ENDIF() |
---|
| 128 | OPTION(PCH_ENABLE_${_target_name_upper} "Enable using precompiled header files for library ${_target_name}." ${PCH_DEFAULT}) |
---|
| 129 | |
---|
| 130 | IF(PCH_ENABLE_${_target_name_upper}) |
---|
| 131 | PRECOMPILED_HEADER_FILES_PRE_TARGET(${_target_name} ${_arg_PCH_FILE} _${_target_name}_files EXCLUDE ${_arg_PCH_EXCLUDE}) |
---|
| 132 | ENDIF() |
---|
| 133 | ENDIF() |
---|
| 134 | |
---|
[3116] | 135 | # Certain libraries don't have dllexport/dllimport and can't be linked shared with msvc |
---|
| 136 | IF(MSVC AND _arg_NO_DLL_INTERFACE) |
---|
| 137 | SET(_arg_SHARED) |
---|
| 138 | SET(_arg_STATIC STATIC) |
---|
| 139 | ENDIF() |
---|
| 140 | |
---|
| 141 | # Set default linking if required |
---|
| 142 | IF(NOT _arg_SHARED AND NOT _arg_STATIC) |
---|
| 143 | IF("${ORXONOX_DEFAULT_LINK}" STREQUAL "STATIC") |
---|
| 144 | SET(_arg_STATIC STATIC) |
---|
| 145 | ELSEIF("${ORXONOX_DEFAULT_LINK}" STREQUAL "SHARED") |
---|
| 146 | SET(_arg_SHARED SHARED) |
---|
| 147 | ENDIF() |
---|
| 148 | ENDIF() |
---|
| 149 | |
---|
[5666] | 150 | # MODULE A |
---|
| 151 | # Always create shared libraries |
---|
| 152 | IF(_arg_MODULE) |
---|
[5649] | 153 | SET(_arg_SHARED SHARED) |
---|
[5626] | 154 | SET(_arg_STATIC) |
---|
| 155 | ENDIF() |
---|
| 156 | |
---|
[3116] | 157 | # Add the library/executable |
---|
| 158 | IF("${_target_type}" STREQUAL "LIBRARY") |
---|
[5636] | 159 | ADD_LIBRARY(${_target_name} ${_arg_STATIC} ${_arg_SHARED} |
---|
[3116] | 160 | ${_arg_EXCLUDE_FROM_ALL} ${_${_target_name}_files}) |
---|
| 161 | ELSE() |
---|
| 162 | ADD_EXECUTABLE(${_target_name} ${_arg_WIN32} ${_arg_EXCLUDE_FROM_ALL} |
---|
| 163 | ${_${_target_name}_files}) |
---|
| 164 | ENDIF() |
---|
| 165 | |
---|
[5666] | 166 | # MODULE B |
---|
| 167 | IF (_arg_MODULE) |
---|
[5649] | 168 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES |
---|
[5666] | 169 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_MODULE_OUTPUT_DIRECTORY} # Windows |
---|
| 170 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_MODULE_OUTPUT_DIRECTORY} # Unix |
---|
[5649] | 171 | ) |
---|
[5666] | 172 | ADD_MODULE(${_target_name}) |
---|
[5626] | 173 | ENDIF() |
---|
| 174 | |
---|
[3116] | 175 | # LINK_LIBRARIES |
---|
| 176 | IF(_arg_LINK_LIBRARIES) |
---|
| 177 | TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBRARIES}) |
---|
| 178 | ENDIF() |
---|
| 179 | |
---|
| 180 | # DEFINE_SYMBOL |
---|
| 181 | IF(_arg_DEFINE_SYMBOL) |
---|
| 182 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL ${_arg_DEFINE_SYMBOL}) |
---|
| 183 | ENDIF() |
---|
| 184 | |
---|
| 185 | # VERSION |
---|
| 186 | IF(_arg_VERSION) |
---|
| 187 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${_arg_VERSION}) |
---|
[3167] | 188 | ELSEIF(NOT _arg_ORXONOX_EXTERNAL) |
---|
[3116] | 189 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${ORXONOX_VERSION}) |
---|
| 190 | ENDIF() |
---|
| 191 | |
---|
[5613] | 192 | # OUTPUT_NAME |
---|
[5626] | 193 | IF(_arg_OUTPUT_NAME) |
---|
[5613] | 194 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES OUTPUT_NAME ${_arg_OUTPUT_NAME}) |
---|
| 195 | ENDIF() |
---|
| 196 | |
---|
[3117] | 197 | # Second part of precompiled header files |
---|
| 198 | IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE_${_target_name_upper} AND _arg_PCH_FILE) |
---|
| 199 | PRECOMPILED_HEADER_FILES_POST_TARGET(${_target_name} ${_arg_PCH_FILE}) |
---|
| 200 | ENDIF() |
---|
| 201 | |
---|
[3368] | 202 | IF(NOT _arg_STATIC AND NOT _arg_NO_INSTALL) |
---|
[5666] | 203 | IF(_arg_MODULE) |
---|
[5649] | 204 | INSTALL(TARGETS ${_target_name} |
---|
[5666] | 205 | RUNTIME DESTINATION ${ORXONOX_MODULE_INSTALL_PATH} |
---|
| 206 | LIBRARY DESTINATION ${ORXONOX_MODULE_INSTALL_PATH} |
---|
[5649] | 207 | ) |
---|
| 208 | ELSE() |
---|
| 209 | INSTALL(TARGETS ${_target_name} |
---|
| 210 | RUNTIME DESTINATION ${ORXONOX_RUNTIME_INSTALL_PATH} |
---|
| 211 | LIBRARY DESTINATION ${ORXONOX_LIBRARY_INSTALL_PATH} |
---|
| 212 | ) |
---|
[5626] | 213 | ENDIF() |
---|
[3116] | 214 | ENDIF() |
---|
| 215 | |
---|
| 216 | ENDFUNCTION(TU_ADD_TARGET) |
---|
[5626] | 217 | |
---|
| 218 | |
---|
[5666] | 219 | # Creates a helper file with name <name_of_the_library>.module |
---|
| 220 | # This helps finding dynamically loadable modules at runtime |
---|
[5626] | 221 | |
---|
[5666] | 222 | FUNCTION(ADD_MODULE _target) |
---|
[5626] | 223 | # We use the properties to get the name because the librarys name may differ from |
---|
[5636] | 224 | # the target name (for example orxonox <-> liborxonox) |
---|
[5626] | 225 | |
---|
[5636] | 226 | GET_TARGET_PROPERTY(_target_loc ${_target} LOCATION) |
---|
[5626] | 227 | GET_FILENAME_COMPONENT(_target_name ${_target_loc} NAME_WE) |
---|
| 228 | |
---|
[5636] | 229 | IF(CMAKE_CONFIGURATION_TYPES) |
---|
| 230 | FOREACH(_config ${CMAKE_CONFIGURATION_TYPES}) |
---|
[5666] | 231 | SET(_module_filename ${CMAKE_MODULE_OUTPUT_DIRECTORY}/${_config}/${_target_name}${ORXONOX_MODULE_EXTENSION}) |
---|
[5626] | 232 | |
---|
[5666] | 233 | FILE(WRITE ${_module_filename}) |
---|
[5626] | 234 | |
---|
[5636] | 235 | INSTALL( |
---|
[5666] | 236 | FILES ${_module_filename} |
---|
| 237 | DESTINATION ${ORXONOX_MODULE_INSTALL_PATH} |
---|
[5636] | 238 | CONFIGURATIONS ${_config} |
---|
| 239 | ) |
---|
| 240 | ENDFOREACH() |
---|
| 241 | ELSE() |
---|
[5666] | 242 | SET(_module_filename ${CMAKE_MODULE_OUTPUT_DIRECTORY}/${_target_name}${ORXONOX_MODULE_EXTENSION}) |
---|
[5636] | 243 | |
---|
[5666] | 244 | FILE(WRITE ${_module_filename}) |
---|
[5636] | 245 | |
---|
| 246 | INSTALL( |
---|
[5666] | 247 | FILES ${_module_filename} |
---|
| 248 | DESTINATION ${ORXONOX_MODULE_INSTALL_PATH} |
---|
[5636] | 249 | ) |
---|
| 250 | ENDIF() |
---|
[5666] | 251 | ENDFUNCTION(ADD_MODULE) |
---|