[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 |
---|
[7143] | 36 | # MODULE: For dynamic module libraries (libraries only) |
---|
| 37 | # WIN32: Inherited from ADD_EXECUTABLE (executables only) |
---|
[3117] | 38 | # PCH_NO_DEFAULT: Do not make precompiled header files default if |
---|
| 39 | # specified with PCH_FILE |
---|
[5693] | 40 | # NO_INSTALL: Do not install the target at all |
---|
[7123] | 41 | # NO_VERSION: Prevents adding any version to a target |
---|
[5693] | 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 | |
---|
[5929] | 69 | MACRO(ORXONOX_ADD_LIBRARY _target_name) |
---|
[7143] | 70 | TU_ADD_TARGET(${_target_name} LIBRARY "MODULE" ${ARGN}) |
---|
[5929] | 71 | ENDMACRO(ORXONOX_ADD_LIBRARY) |
---|
[3116] | 72 | |
---|
[5929] | 73 | MACRO(ORXONOX_ADD_EXECUTABLE _target_name) |
---|
[3116] | 74 | TU_ADD_TARGET(${_target_name} EXECUTABLE "WIN32" ${ARGN}) |
---|
[5929] | 75 | ENDMACRO(ORXONOX_ADD_EXECUTABLE) |
---|
[3116] | 76 | |
---|
| 77 | |
---|
[5929] | 78 | MACRO(TU_ADD_TARGET _target_name _target_type _additional_switches) |
---|
[3116] | 79 | CAPITALISE_NAME(${_target_name} _target_name_capitalised) |
---|
[7132] | 80 | STRING(TOUPPER "${_target_name}" _target_name_upper) |
---|
[3116] | 81 | |
---|
| 82 | # Specify all possible options (either switch or with add. arguments) |
---|
| 83 | SET(_switches FIND_HEADER_FILES EXCLUDE_FROM_ALL ORXONOX_EXTERNAL |
---|
[7143] | 84 | NO_DLL_INTERFACE NO_SOURCE_GROUPS PCH_NO_DEFAULT |
---|
| 85 | NO_INSTALL NO_VERSION ${_additional_switches}) |
---|
[7415] | 86 | SET(_list_names LINK_LIBRARIES VERSION SOURCE_FILES |
---|
| 87 | DEFINE_SYMBOL TOLUA_FILES PCH_FILE |
---|
| 88 | PCH_EXCLUDE OUTPUT_NAME) |
---|
| 89 | |
---|
[3116] | 90 | PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN}) |
---|
| 91 | |
---|
| 92 | |
---|
[5929] | 93 | # Workaround: Source file properties get lost when leaving a subdirectory |
---|
| 94 | # Therefore an "H" after a file means we have to set it as HEADER_FILE_ONLY |
---|
| 95 | FOREACH(_file ${_arg_SOURCE_FILES}) |
---|
| 96 | IF(_file STREQUAL "H") |
---|
| 97 | SET_SOURCE_FILES_PROPERTIES(${_last_file} PROPERTIES HEADER_FILE_ONLY TRUE) |
---|
| 98 | ELSE() |
---|
| 99 | SET(_last_file ${_file}) |
---|
| 100 | LIST(APPEND _${_target_name}_source_files ${_file}) |
---|
| 101 | ENDIF() |
---|
| 102 | ENDFOREACH(_file) |
---|
| 103 | |
---|
| 104 | # Assemble all header files of the library |
---|
[3116] | 105 | IF(_arg_FIND_HEADER_FILES) |
---|
[5929] | 106 | GET_ALL_HEADER_FILES(_${_target_name}_header_files) |
---|
[3116] | 107 | ENDIF() |
---|
| 108 | |
---|
[7415] | 109 | # Combine source and header files |
---|
| 110 | SET(_${_target_name}_files |
---|
| 111 | ${_${_target_name}_header_files} |
---|
| 112 | ${_${_target_name}_source_files} |
---|
| 113 | ) |
---|
[3116] | 114 | # Remove potential duplicates |
---|
| 115 | LIST(REMOVE_DUPLICATES _${_target_name}_files) |
---|
| 116 | |
---|
| 117 | # TOLUA_FILES |
---|
| 118 | IF(_arg_TOLUA_FILES) |
---|
| 119 | GENERATE_TOLUA_BINDINGS(${_target_name_capitalised} _${_target_name}_files |
---|
| 120 | INPUTFILES ${_arg_TOLUA_FILES}) |
---|
[7619] | 121 | # Workaround for XCode: The folder where the bind files are written to has |
---|
| 122 | # to be present beforehand. |
---|
| 123 | IF(CMAKE_CONFIGURATION_TYPES) |
---|
| 124 | FOREACH(_dir ${CMAKE_CONFIGURATION_TYPES}) |
---|
| 125 | FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_dir}) |
---|
| 126 | ENDFOREACH(_dir) |
---|
| 127 | ENDIF() |
---|
[3116] | 128 | ENDIF() |
---|
| 129 | |
---|
[3117] | 130 | # First part (pre target) of precompiled header files |
---|
[5695] | 131 | IF(PCH_COMPILER_SUPPORT AND _arg_PCH_FILE) |
---|
[3117] | 132 | # Provide convenient option to control PCH |
---|
| 133 | IF(_arg_PCH_NO_DEFAULT) |
---|
| 134 | SET(PCH_DEFAULT FALSE) |
---|
| 135 | ELSE() |
---|
| 136 | SET(PCH_DEFAULT TRUE) |
---|
| 137 | ENDIF() |
---|
[5695] | 138 | CMAKE_DEPENDENT_OPTION(PCH_ENABLE_${_target_name_upper} |
---|
| 139 | "Enable using precompiled header files for library ${_target_name}." ${PCH_DEFAULT} PCH_ENABLE OFF) |
---|
[3117] | 140 | |
---|
| 141 | IF(PCH_ENABLE_${_target_name_upper}) |
---|
| 142 | PRECOMPILED_HEADER_FILES_PRE_TARGET(${_target_name} ${_arg_PCH_FILE} _${_target_name}_files EXCLUDE ${_arg_PCH_EXCLUDE}) |
---|
| 143 | ENDIF() |
---|
| 144 | ENDIF() |
---|
| 145 | |
---|
[7415] | 146 | # Generate the source groups |
---|
| 147 | IF(MSVC AND NOT _arg_NO_SOURCE_GROUPS) |
---|
| 148 | GENERATE_SOURCE_GROUPS(${_${_target_name}_files}) |
---|
| 149 | |
---|
| 150 | IF(NOT _arg_ORXONOX_EXTERNAL) |
---|
| 151 | # Move the prereqs.h file to the config section |
---|
| 152 | IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_target_name_capitalised}Prereqs.h) |
---|
| 153 | SOURCE_GROUP("Config" FILES ${_target_name_capitalised}Prereqs.h) |
---|
| 154 | ENDIF() |
---|
| 155 | # Add config files to the config section |
---|
| 156 | LIST(APPEND _${_target_name}_files ${ORXONOX_CONFIG_FILES}) |
---|
| 157 | SOURCE_GROUP("Config" FILES ${ORXONOX_CONFIG_FILES}) |
---|
| 158 | ENDIF() |
---|
[7416] | 159 | ENDIF() |
---|
[7415] | 160 | |
---|
[7143] | 161 | # Set link mode (SHARED/STATIC) |
---|
[3116] | 162 | IF(MSVC AND _arg_NO_DLL_INTERFACE) |
---|
[7143] | 163 | # Certain libraries don't have dllexport/dllimport and can't be linked shared with MSVC |
---|
| 164 | SET(_link_mode STATIC) |
---|
| 165 | ELSEIF(_arg_ORXONOX_EXTERNAL) |
---|
| 166 | # Externals can be linked shared or statically |
---|
| 167 | SET(_link_mode ${ORXONOX_EXTERNAL_LINK_MODE}) |
---|
| 168 | ELSE() |
---|
| 169 | # All our own libraries are linked dynamically because of static symbols |
---|
| 170 | SET(_link_mode SHARED) |
---|
[3116] | 171 | ENDIF() |
---|
| 172 | |
---|
[5929] | 173 | # No warnings needed from third party libraries |
---|
| 174 | IF(_arg_ORXONOX_EXTERNAL) |
---|
| 175 | REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC) |
---|
| 176 | ADD_COMPILER_FLAGS("-w") |
---|
| 177 | ENDIF() |
---|
[8083] | 178 | |
---|
[5901] | 179 | # Don't compile header files |
---|
| 180 | FOREACH(_file ${_${_target_name}_files}) |
---|
[8083] | 181 | IF(NOT _file MATCHES "\\.(c|cc|cpp|cxx|mm)$") |
---|
[5901] | 182 | SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE) |
---|
| 183 | ENDIF() |
---|
| 184 | ENDFOREACH(_file) |
---|
| 185 | |
---|
[3116] | 186 | # Add the library/executable |
---|
| 187 | IF("${_target_type}" STREQUAL "LIBRARY") |
---|
[7143] | 188 | ADD_LIBRARY(${_target_name} ${_link_mode} |
---|
[3116] | 189 | ${_arg_EXCLUDE_FROM_ALL} ${_${_target_name}_files}) |
---|
| 190 | ELSE() |
---|
| 191 | ADD_EXECUTABLE(${_target_name} ${_arg_WIN32} ${_arg_EXCLUDE_FROM_ALL} |
---|
| 192 | ${_${_target_name}_files}) |
---|
| 193 | ENDIF() |
---|
| 194 | |
---|
[5963] | 195 | |
---|
| 196 | |
---|
[5929] | 197 | # Change library prefix to "lib" |
---|
| 198 | IF(MSVC AND ${_target_type} STREQUAL "LIBRARY") |
---|
| 199 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES |
---|
| 200 | PREFIX "lib" |
---|
| 201 | ) |
---|
| 202 | ENDIF() |
---|
| 203 | |
---|
[5963] | 204 | # MSVC hack to exclude external library sources from the intellisense database |
---|
| 205 | # (IntelliSense stops working when adding "-Zm1000" as compile flag. "/Zm1000" |
---|
| 206 | # would not work because of the slash) |
---|
| 207 | IF(_arg_ORXONOX_EXTERNAL AND MSVC) |
---|
[7137] | 208 | GET_TARGET_PROPERTY(_compile_flags ${_target_name} COMPILE_FLAGS) |
---|
| 209 | IF(NOT _compile_flags) |
---|
| 210 | SET(_compile_flags) |
---|
| 211 | ENDIF() |
---|
| 212 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES COMPILE_FLAGS "${_compile_flags} -Zm1000") |
---|
[5963] | 213 | ENDIF() |
---|
| 214 | |
---|
[7143] | 215 | # Configure modules |
---|
[5693] | 216 | IF (_arg_MODULE) |
---|
| 217 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES |
---|
| 218 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_MODULE_OUTPUT_DIRECTORY} # Windows |
---|
| 219 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_MODULE_OUTPUT_DIRECTORY} # Unix |
---|
| 220 | ) |
---|
| 221 | ADD_MODULE(${_target_name}) |
---|
[7401] | 222 | # Ensure that the main program depends on the module |
---|
| 223 | SET(ORXONOX_MODULES ${ORXONOX_MODULES} ${_target_name} CACHE STRING "" FORCE) |
---|
[5693] | 224 | ENDIF() |
---|
| 225 | |
---|
[3116] | 226 | # LINK_LIBRARIES |
---|
| 227 | IF(_arg_LINK_LIBRARIES) |
---|
| 228 | TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBRARIES}) |
---|
| 229 | ENDIF() |
---|
| 230 | |
---|
| 231 | # DEFINE_SYMBOL |
---|
[7143] | 232 | IF(_arg_DEFINE_SYMBOL) |
---|
| 233 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL ${_arg_DEFINE_SYMBOL}) |
---|
| 234 | ELSEIF(NOT _arg_ORXONOX_EXTERNAL) |
---|
| 235 | # Automatically add the macro definitions for our own libraries |
---|
| 236 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL "${_target_name_upper}_SHARED_BUILD") |
---|
[3116] | 237 | ENDIF() |
---|
| 238 | |
---|
| 239 | # VERSION |
---|
| 240 | IF(_arg_VERSION) |
---|
| 241 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${_arg_VERSION}) |
---|
[7131] | 242 | ELSEIF(NOT _arg_ORXONOX_EXTERNAL AND NOT _arg_NO_VERSION AND NOT ${_target_type} STREQUAL "EXECUTABLE") |
---|
[3116] | 243 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${ORXONOX_VERSION}) |
---|
| 244 | ENDIF() |
---|
| 245 | |
---|
[5693] | 246 | # OUTPUT_NAME |
---|
| 247 | IF(_arg_OUTPUT_NAME) |
---|
| 248 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES OUTPUT_NAME ${_arg_OUTPUT_NAME}) |
---|
| 249 | ENDIF() |
---|
| 250 | |
---|
[3117] | 251 | # Second part of precompiled header files |
---|
| 252 | IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE_${_target_name_upper} AND _arg_PCH_FILE) |
---|
| 253 | PRECOMPILED_HEADER_FILES_POST_TARGET(${_target_name} ${_arg_PCH_FILE}) |
---|
| 254 | ENDIF() |
---|
| 255 | |
---|
[7143] | 256 | # Install all targets except for static ones (executables also have SHARED in _link_mode) |
---|
[7170] | 257 | IF(${_link_mode} STREQUAL "SHARED" AND NOT _arg_NO_INSTALL) |
---|
[5693] | 258 | IF(_arg_MODULE) |
---|
| 259 | INSTALL(TARGETS ${_target_name} |
---|
[5695] | 260 | RUNTIME DESTINATION ${MODULE_INSTALL_DIRECTORY} |
---|
| 261 | LIBRARY DESTINATION ${MODULE_INSTALL_DIRECTORY} |
---|
[5693] | 262 | ) |
---|
| 263 | ELSE() |
---|
| 264 | INSTALL(TARGETS ${_target_name} |
---|
[5695] | 265 | RUNTIME DESTINATION ${RUNTIME_INSTALL_DIRECTORY} |
---|
| 266 | LIBRARY DESTINATION ${LIBRARY_INSTALL_DIRECTORY} |
---|
[5693] | 267 | ) |
---|
| 268 | ENDIF() |
---|
[3116] | 269 | ENDIF() |
---|
| 270 | |
---|
[5929] | 271 | ENDMACRO(TU_ADD_TARGET) |
---|
[5693] | 272 | |
---|
| 273 | |
---|
[5695] | 274 | # Creates a helper file with name <name_of_the_library>${ORXONOX_MODULE_EXTENSION} |
---|
[5693] | 275 | # This helps finding dynamically loadable modules at runtime |
---|
| 276 | |
---|
| 277 | FUNCTION(ADD_MODULE _target) |
---|
| 278 | # We use the properties to get the name because the librarys name may differ from |
---|
| 279 | # the target name (for example orxonox <-> liborxonox) |
---|
| 280 | |
---|
| 281 | GET_TARGET_PROPERTY(_target_loc ${_target} LOCATION) |
---|
| 282 | GET_FILENAME_COMPONENT(_target_name ${_target_loc} NAME_WE) |
---|
| 283 | |
---|
| 284 | IF(CMAKE_CONFIGURATION_TYPES) |
---|
| 285 | FOREACH(_config ${CMAKE_CONFIGURATION_TYPES}) |
---|
| 286 | SET(_module_filename ${CMAKE_MODULE_OUTPUT_DIRECTORY}/${_config}/${_target_name}${ORXONOX_MODULE_EXTENSION}) |
---|
| 287 | |
---|
| 288 | FILE(WRITE ${_module_filename}) |
---|
| 289 | |
---|
| 290 | INSTALL( |
---|
| 291 | FILES ${_module_filename} |
---|
[5695] | 292 | DESTINATION ${MODULE_INSTALL_DIRECTORY} |
---|
[5693] | 293 | CONFIGURATIONS ${_config} |
---|
| 294 | ) |
---|
| 295 | ENDFOREACH() |
---|
| 296 | ELSE() |
---|
| 297 | SET(_module_filename ${CMAKE_MODULE_OUTPUT_DIRECTORY}/${_target_name}${ORXONOX_MODULE_EXTENSION}) |
---|
| 298 | |
---|
| 299 | FILE(WRITE ${_module_filename}) |
---|
| 300 | |
---|
| 301 | INSTALL( |
---|
| 302 | FILES ${_module_filename} |
---|
[5695] | 303 | DESTINATION ${MODULE_INSTALL_DIRECTORY} |
---|
[5693] | 304 | ) |
---|
| 305 | ENDIF() |
---|
| 306 | ENDFUNCTION(ADD_MODULE) |
---|