| [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 | # WIN32: Inherited from ADD_EXECUTABLE (executables only) |
|---|
| [3117] | 37 | # PCH_NO_DEFAULT: Do not make precompiled header files default if |
|---|
| 38 | # specified with PCH_FILE |
|---|
| [5693] | 39 | # NO_INSTALL: Do not install the target at all |
|---|
| [7123] | 40 | # NO_VERSION: Prevents adding any version to a target |
|---|
| [5693] | 41 | # |
|---|
| [3116] | 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 |
|---|
| [3117] | 47 | # PCH_FILE: Precompiled header file |
|---|
| 48 | # PCH_EXCLUDE: Source files to be excluded from PCH support |
|---|
| [5693] | 49 | # OUTPUT_NAME: If you want a different name than the target name |
|---|
| [7421] | 50 | # QT_MOC_FILES: List of files to be processed by Qt MOC |
|---|
| 51 | # QT_UIC_FILES: List of files to be processed by Qt UIC |
|---|
| [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(ParseMacroArguments) |
|---|
| 63 | INCLUDE(SourceFileUtilities) |
|---|
| [3117] | 64 | IF(PCH_COMPILER_SUPPORT) |
|---|
| 65 | INCLUDE(PrecompiledHeaderFiles) |
|---|
| 66 | ENDIF() |
|---|
| [3116] | 67 | |
|---|
| [5929] | 68 | MACRO(ORXONOX_ADD_LIBRARY _target_name) |
|---|
| [7421] | 69 | TU_ADD_TARGET(${_target_name} LIBRARY "" ${ARGN}) |
|---|
| [5929] | 70 | ENDMACRO(ORXONOX_ADD_LIBRARY) |
|---|
| [3116] | 71 | |
|---|
| [5929] | 72 | MACRO(ORXONOX_ADD_EXECUTABLE _target_name) |
|---|
| [3116] | 73 | TU_ADD_TARGET(${_target_name} EXECUTABLE "WIN32" ${ARGN}) |
|---|
| [5929] | 74 | ENDMACRO(ORXONOX_ADD_EXECUTABLE) |
|---|
| [3116] | 75 | |
|---|
| 76 | |
|---|
| [5929] | 77 | MACRO(TU_ADD_TARGET _target_name _target_type _additional_switches) |
|---|
| [3116] | 78 | CAPITALISE_NAME(${_target_name} _target_name_capitalised) |
|---|
| [7132] | 79 | STRING(TOUPPER "${_target_name}" _target_name_upper) |
|---|
| [3116] | 80 | |
|---|
| 81 | # Specify all possible options (either switch or with add. arguments) |
|---|
| 82 | SET(_switches FIND_HEADER_FILES EXCLUDE_FROM_ALL ORXONOX_EXTERNAL |
|---|
| [7143] | 83 | NO_DLL_INTERFACE NO_SOURCE_GROUPS PCH_NO_DEFAULT |
|---|
| 84 | NO_INSTALL NO_VERSION ${_additional_switches}) |
|---|
| [7415] | 85 | SET(_list_names LINK_LIBRARIES VERSION SOURCE_FILES |
|---|
| [7421] | 86 | DEFINE_SYMBOL PCH_FILE PCH_EXCLUDE |
|---|
| 87 | OUTPUT_NAME QT_MOC_FILES QT_UIC_FILES) |
|---|
| [7415] | 88 | |
|---|
| [3116] | 89 | PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN}) |
|---|
| 90 | |
|---|
| 91 | |
|---|
| [5929] | 92 | # Workaround: Source file properties get lost when leaving a subdirectory |
|---|
| 93 | # Therefore an "H" after a file means we have to set it as HEADER_FILE_ONLY |
|---|
| 94 | FOREACH(_file ${_arg_SOURCE_FILES}) |
|---|
| 95 | IF(_file STREQUAL "H") |
|---|
| 96 | SET_SOURCE_FILES_PROPERTIES(${_last_file} PROPERTIES HEADER_FILE_ONLY TRUE) |
|---|
| 97 | ELSE() |
|---|
| 98 | SET(_last_file ${_file}) |
|---|
| 99 | LIST(APPEND _${_target_name}_source_files ${_file}) |
|---|
| 100 | ENDIF() |
|---|
| 101 | ENDFOREACH(_file) |
|---|
| 102 | |
|---|
| 103 | # Assemble all header files of the library |
|---|
| [3116] | 104 | IF(_arg_FIND_HEADER_FILES) |
|---|
| [5929] | 105 | GET_ALL_HEADER_FILES(_${_target_name}_header_files) |
|---|
| [3116] | 106 | ENDIF() |
|---|
| 107 | |
|---|
| [7421] | 108 | # Combine source, header and QT designer files |
|---|
| [7415] | 109 | SET(_${_target_name}_files |
|---|
| 110 | ${_${_target_name}_header_files} |
|---|
| 111 | ${_${_target_name}_source_files} |
|---|
| [7421] | 112 | ${_arg_QT_UIC_FILES} |
|---|
| [7415] | 113 | ) |
|---|
| [3116] | 114 | # Remove potential duplicates |
|---|
| 115 | LIST(REMOVE_DUPLICATES _${_target_name}_files) |
|---|
| 116 | |
|---|
| [7421] | 117 | # QT MOC and UIC preprocessing |
|---|
| 118 | IF(_arg_QT_MOC_FILES) |
|---|
| 119 | QT4_WRAP_CPP(_${_target_name}_files ${_arg_QT_MOC_FILES}) |
|---|
| [3116] | 120 | ENDIF() |
|---|
| [7421] | 121 | IF(_arg_QT_UIC_FILES) |
|---|
| 122 | QT4_WRAP_UI(_${_target_name}_files ${_arg_QT_UIC_FILES}) |
|---|
| 123 | ENDIF() |
|---|
| [3116] | 124 | |
|---|
| [3117] | 125 | # First part (pre target) of precompiled header files |
|---|
| [5695] | 126 | IF(PCH_COMPILER_SUPPORT AND _arg_PCH_FILE) |
|---|
| [3117] | 127 | # Provide convenient option to control PCH |
|---|
| 128 | IF(_arg_PCH_NO_DEFAULT) |
|---|
| 129 | SET(PCH_DEFAULT FALSE) |
|---|
| 130 | ELSE() |
|---|
| 131 | SET(PCH_DEFAULT TRUE) |
|---|
| 132 | ENDIF() |
|---|
| [5695] | 133 | CMAKE_DEPENDENT_OPTION(PCH_ENABLE_${_target_name_upper} |
|---|
| 134 | "Enable using precompiled header files for library ${_target_name}." ${PCH_DEFAULT} PCH_ENABLE OFF) |
|---|
| [3117] | 135 | |
|---|
| 136 | IF(PCH_ENABLE_${_target_name_upper}) |
|---|
| 137 | PRECOMPILED_HEADER_FILES_PRE_TARGET(${_target_name} ${_arg_PCH_FILE} _${_target_name}_files EXCLUDE ${_arg_PCH_EXCLUDE}) |
|---|
| 138 | ENDIF() |
|---|
| 139 | ENDIF() |
|---|
| 140 | |
|---|
| [7415] | 141 | # Generate the source groups |
|---|
| 142 | IF(MSVC AND NOT _arg_NO_SOURCE_GROUPS) |
|---|
| 143 | GENERATE_SOURCE_GROUPS(${_${_target_name}_files}) |
|---|
| 144 | |
|---|
| 145 | IF(NOT _arg_ORXONOX_EXTERNAL) |
|---|
| 146 | # Move the prereqs.h file to the config section |
|---|
| 147 | IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_target_name_capitalised}Prereqs.h) |
|---|
| 148 | SOURCE_GROUP("Config" FILES ${_target_name_capitalised}Prereqs.h) |
|---|
| 149 | ENDIF() |
|---|
| 150 | # Add config files to the config section |
|---|
| 151 | LIST(APPEND _${_target_name}_files ${ORXONOX_CONFIG_FILES}) |
|---|
| 152 | SOURCE_GROUP("Config" FILES ${ORXONOX_CONFIG_FILES}) |
|---|
| 153 | ENDIF() |
|---|
| [7416] | 154 | ENDIF() |
|---|
| [7415] | 155 | |
|---|
| [7143] | 156 | # Set link mode (SHARED/STATIC) |
|---|
| [3116] | 157 | IF(MSVC AND _arg_NO_DLL_INTERFACE) |
|---|
| [7143] | 158 | # Certain libraries don't have dllexport/dllimport and can't be linked shared with MSVC |
|---|
| 159 | SET(_link_mode STATIC) |
|---|
| 160 | ELSEIF(_arg_ORXONOX_EXTERNAL) |
|---|
| 161 | # Externals can be linked shared or statically |
|---|
| 162 | SET(_link_mode ${ORXONOX_EXTERNAL_LINK_MODE}) |
|---|
| 163 | ELSE() |
|---|
| 164 | # All our own libraries are linked dynamically because of static symbols |
|---|
| 165 | SET(_link_mode SHARED) |
|---|
| [3116] | 166 | ENDIF() |
|---|
| 167 | |
|---|
| [5929] | 168 | # No warnings needed from third party libraries |
|---|
| 169 | IF(_arg_ORXONOX_EXTERNAL) |
|---|
| 170 | REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC) |
|---|
| 171 | ADD_COMPILER_FLAGS("-w") |
|---|
| 172 | ENDIF() |
|---|
| 173 | |
|---|
| [5901] | 174 | # Don't compile header files |
|---|
| 175 | FOREACH(_file ${_${_target_name}_files}) |
|---|
| 176 | IF(NOT _file MATCHES "\\.(c|cc|cpp)") |
|---|
| 177 | SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE) |
|---|
| 178 | ENDIF() |
|---|
| 179 | ENDFOREACH(_file) |
|---|
| 180 | |
|---|
| [5963] | 181 | |
|---|
| 182 | |
|---|
| [3116] | 183 | # Add the library/executable |
|---|
| 184 | IF("${_target_type}" STREQUAL "LIBRARY") |
|---|
| [7143] | 185 | ADD_LIBRARY(${_target_name} ${_link_mode} |
|---|
| [3116] | 186 | ${_arg_EXCLUDE_FROM_ALL} ${_${_target_name}_files}) |
|---|
| 187 | ELSE() |
|---|
| 188 | ADD_EXECUTABLE(${_target_name} ${_arg_WIN32} ${_arg_EXCLUDE_FROM_ALL} |
|---|
| 189 | ${_${_target_name}_files}) |
|---|
| 190 | ENDIF() |
|---|
| 191 | |
|---|
| [5963] | 192 | |
|---|
| 193 | |
|---|
| [5929] | 194 | # Change library prefix to "lib" |
|---|
| 195 | IF(MSVC AND ${_target_type} STREQUAL "LIBRARY") |
|---|
| 196 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES |
|---|
| 197 | PREFIX "lib" |
|---|
| 198 | ) |
|---|
| 199 | ENDIF() |
|---|
| 200 | |
|---|
| [5963] | 201 | # MSVC hack to exclude external library sources from the intellisense database |
|---|
| 202 | # (IntelliSense stops working when adding "-Zm1000" as compile flag. "/Zm1000" |
|---|
| 203 | # would not work because of the slash) |
|---|
| 204 | IF(_arg_ORXONOX_EXTERNAL AND MSVC) |
|---|
| [7137] | 205 | GET_TARGET_PROPERTY(_compile_flags ${_target_name} COMPILE_FLAGS) |
|---|
| 206 | IF(NOT _compile_flags) |
|---|
| 207 | SET(_compile_flags) |
|---|
| 208 | ENDIF() |
|---|
| 209 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES COMPILE_FLAGS "${_compile_flags} -Zm1000") |
|---|
| [5963] | 210 | ENDIF() |
|---|
| 211 | |
|---|
| [3116] | 212 | # LINK_LIBRARIES |
|---|
| 213 | IF(_arg_LINK_LIBRARIES) |
|---|
| 214 | TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBRARIES}) |
|---|
| 215 | ENDIF() |
|---|
| 216 | |
|---|
| 217 | # DEFINE_SYMBOL |
|---|
| [7143] | 218 | IF(_arg_DEFINE_SYMBOL) |
|---|
| 219 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL ${_arg_DEFINE_SYMBOL}) |
|---|
| 220 | ELSEIF(NOT _arg_ORXONOX_EXTERNAL) |
|---|
| 221 | # Automatically add the macro definitions for our own libraries |
|---|
| 222 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL "${_target_name_upper}_SHARED_BUILD") |
|---|
| [3116] | 223 | ENDIF() |
|---|
| 224 | |
|---|
| 225 | # VERSION |
|---|
| 226 | IF(_arg_VERSION) |
|---|
| 227 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${_arg_VERSION}) |
|---|
| [7131] | 228 | ELSEIF(NOT _arg_ORXONOX_EXTERNAL AND NOT _arg_NO_VERSION AND NOT ${_target_type} STREQUAL "EXECUTABLE") |
|---|
| [3116] | 229 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${ORXONOX_VERSION}) |
|---|
| 230 | ENDIF() |
|---|
| 231 | |
|---|
| [5693] | 232 | # OUTPUT_NAME |
|---|
| 233 | IF(_arg_OUTPUT_NAME) |
|---|
| 234 | SET_TARGET_PROPERTIES(${_target_name} PROPERTIES OUTPUT_NAME ${_arg_OUTPUT_NAME}) |
|---|
| 235 | ENDIF() |
|---|
| 236 | |
|---|
| [3117] | 237 | # Second part of precompiled header files |
|---|
| 238 | IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE_${_target_name_upper} AND _arg_PCH_FILE) |
|---|
| 239 | PRECOMPILED_HEADER_FILES_POST_TARGET(${_target_name} ${_arg_PCH_FILE}) |
|---|
| 240 | ENDIF() |
|---|
| 241 | |
|---|
| [7143] | 242 | # Install all targets except for static ones (executables also have SHARED in _link_mode) |
|---|
| [7170] | 243 | IF(${_link_mode} STREQUAL "SHARED" AND NOT _arg_NO_INSTALL) |
|---|
| [7421] | 244 | INSTALL(TARGETS ${_target_name} |
|---|
| 245 | RUNTIME DESTINATION ${RUNTIME_INSTALL_DIRECTORY} |
|---|
| 246 | LIBRARY DESTINATION ${LIBRARY_INSTALL_DIRECTORY} |
|---|
| 247 | ) |
|---|
| [3116] | 248 | ENDIF() |
|---|
| 249 | |
|---|
| [5929] | 250 | ENDMACRO(TU_ADD_TARGET) |
|---|