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