anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
Anope.cmake (27685B)
1 ############################################################################### 2 # strip_string(<input string> <output string>) 3 # 4 # A macro to handle stripping the leading and trailing spaces from a string, 5 # uses string(STRIP) if using CMake 2.6.x or better, otherwise uses 6 # string(REGEX REPLACE). 7 ############################################################################### 8 macro(strip_string INPUT_STRING OUTPUT_STRING) 9 if(CMAKE26_OR_BETTER) 10 # For CMake 2.6.x or better, we can just use the STRIP sub-command of string() 11 string(STRIP ${INPUT_STRING} ${OUTPUT_STRING}) 12 else(CMAKE26_OR_BETTER) 13 # For CMake 2.4.x, we will have to use the REGEX REPLACE sub-command of string() instead 14 # First check if the input string is empty or not 15 if (${INPUT_STRING} STREQUAL "") 16 set(${OUTPUT_STRING} "") 17 else(${INPUT_STRING} STREQUAL "") 18 # Determine if the string is entirely empty or not 19 string(REGEX MATCH "^[ \t]*$" EMPTY_STRING "${INPUT_STRING}") 20 if(EMPTY_STRING) 21 set(${OUTPUT_STRING} "") 22 else(EMPTY_STRING) 23 # We detect if there is any leading whitespace and remove any if there is 24 string(SUBSTRING "${INPUT_STRING}" 0 1 FIRST_CHAR) 25 if(FIRST_CHAR STREQUAL " " OR FIRST_CHAR STREQUAL "\t") 26 string(REGEX REPLACE "^[ \t]+" "" TEMP_STRING "${INPUT_STRING}") 27 else(FIRST_CHAR STREQUAL " " OR FIRST_CHAR STREQUAL "\t") 28 set(TEMP_STRING "${INPUT_STRING}") 29 endif(FIRST_CHAR STREQUAL " " OR FIRST_CHAR STREQUAL "\t") 30 # Next we detect if there is any trailing whitespace and remove any if there is 31 string(LENGTH "${TEMP_STRING}" STRING_LEN) 32 math(EXPR STRING_LEN "${STRING_LEN} - 1") 33 string(SUBSTRING "${TEMP_STRING}" ${STRING_LEN} 1 LAST_CHAR) 34 if(LAST_CHAR STREQUAL " " OR LAST_CHAR STREQUAL "\t") 35 string(REGEX REPLACE "[ \t]+$" "" ${OUTPUT_STRING} "${TEMP_STRING}") 36 else(LAST_CHAR STREQUAL " " OR LAST_CHAR STREQUAL "\t") 37 set(${OUTPUT_STRING} "${TEMP_STRING}") 38 endif(LAST_CHAR STREQUAL " " OR LAST_CHAR STREQUAL "\t") 39 endif(EMPTY_STRING) 40 endif(${INPUT_STRING} STREQUAL "") 41 endif(CMAKE26_OR_BETTER) 42 endmacro(strip_string) 43 44 ############################################################################### 45 # append_to_list(<list> <args>...) 46 # 47 # A macro to handle appending to lists, uses list(APPEND) if using CMake 2.4.2 48 # or better, otherwise uses set() instead. 49 ############################################################################### 50 macro(append_to_list LIST) 51 if(CMAKE242_OR_BETTER) 52 # For CMake 2.4.2 or better, we can just use the APPEND sub-command of list() 53 list(APPEND ${LIST} ${ARGN}) 54 else(CMAKE242_OR_BETTER) 55 # For CMake 2.4.x before 2.4.2, we have to do this manually use set() instead 56 set(${LIST} ${${LIST}} ${ARGN}) 57 endif(CMAKE242_OR_BETTER) 58 endmacro(append_to_list) 59 60 ############################################################################### 61 # find_in_list(<list> <value> <output variable>) 62 # 63 # A macro to handle searching within a list, will store the result in the 64 # given <output variable>, uses list(FIND) if using CMake 2.6.x or better 65 # (or CMake 2.4.8 or better), otherwise it iterates through the list to find 66 # the item. 67 ############################################################################### 68 macro(find_in_list LIST ITEM_TO_FIND FOUND) 69 if(CMAKE248_OR_BETTER) 70 # For CMake 2.4.8 or better, we can use the FIND sub-command of list() 71 list(FIND ${LIST} ${ITEM_TO_FIND} ITEM_FOUND) 72 else(CMAKE248_OR_BETTER) 73 # For CMake 2.4.x before 2.4.8, we have to do this ourselves (NOTE: This is very slow due to a lack of break() as well) 74 # Firstly we set the position to -1 indicating nothing found, we also use a temporary position 75 set(ITEM_FOUND -1) 76 set(POS 0) 77 # Iterate through the list 78 foreach(ITEM ${${LIST}}) 79 # If the item we are looking at is the item we are trying to find, set that we've found the item 80 if(${ITEM} STREQUAL ${ITEM_TO_FIND}) 81 set(ITEM_FOUND ${POS}) 82 endif(${ITEM} STREQUAL ${ITEM_TO_FIND}) 83 # Increase the position value by 1 84 math(EXPR POS "${POS} + 1") 85 endforeach(ITEM) 86 endif(CMAKE248_OR_BETTER) 87 # Set the given FOUND variable to the result 88 set(${FOUND} ${ITEM_FOUND}) 89 endmacro(find_in_list) 90 91 ############################################################################### 92 # remove_list_duplicates(<list>) 93 # 94 # A macro to handle removing duplicates from a list, uses 95 # list(REMOVE_DUPLICATES) if using CMake 2.6.x or better, otherwise it uses 96 # a slower method of creating a temporary list and only adding to it when 97 # a duplicate item hasn't been found. 98 ############################################################################### 99 macro(remove_list_duplicates LIST) 100 if(CMAKE26_OR_BETTER) 101 # For CMake 2.6.x or better, this can be done automatically 102 list(REMOVE_DUPLICATES ${LIST}) 103 else(CMAKE26_OR_BETTER) 104 # For CMake 2.4.x, we have to do this ourselves, firstly we'll clear a temporary list 105 set(NEW_LIST) 106 # Iterate through the old list 107 foreach(ITEM ${${LIST}}) 108 # Check if the item is in the new list 109 find_in_list(NEW_LIST ${ITEM} FOUND_ITEM) 110 if(FOUND_ITEM EQUAL -1) 111 # If the item was not found, append it to the list 112 append_to_list(NEW_LIST ${ITEM}) 113 endif(FOUND_ITEM EQUAL -1) 114 endforeach(ITEM) 115 # Replace the old list with the new list 116 set(${LIST} ${NEW_LIST}) 117 endif(CMAKE26_OR_BETTER) 118 endmacro(remove_list_duplicates) 119 120 ############################################################################### 121 # remove_item_from_list(<list> <value>) 122 # 123 # A macro to handle removing a value from a list, uses list(REMOVE_ITEM) in 124 # both cases, but can remove the value itself using CMake 2.4.2 or better, 125 # while older versions use a slower method of iterating the list to find the 126 # index of the value to remove. 127 ############################################################################### 128 macro(remove_item_from_list LIST VALUE) 129 if(CMAKE242_OR_BETTER) 130 # For CMake 2.4.2 or better, this can be done automatically 131 list(REMOVE_ITEM ${LIST} ${VALUE}) 132 else(CMAKE242_OR_BETTER) 133 # For CMake 2.4.x before 2.4.2, we have to do this ourselves, firstly we set the index and a variable to indicate if the item was found 134 set(INDEX 0) 135 set(FOUND FALSE) 136 # Iterate through the old list 137 foreach(ITEM ${${LIST}}) 138 # If the item hasn't been found yet, but the current item is the same, remove it 139 if(NOT FOUND) 140 if(ITEM STREQUAL ${VALUE}) 141 set(FOUND TRUE) 142 list(REMOVE_ITEM ${LIST} ${INDEX}) 143 endif(ITEM STREQUAL ${VALUE}) 144 endif(NOT FOUND) 145 # Increase the index value by 1 146 math(EXPR INDEX "${INDEX} + 1") 147 endforeach(ITEM) 148 endif(CMAKE242_OR_BETTER) 149 endmacro(remove_item_from_list) 150 151 ############################################################################### 152 # sort_list(<list>) 153 # 154 # A macro to handle sorting a list, uses list(SORT) if using CMake 2.4.4 or 155 # better, otherwise it uses a slower method of creating a temporary list and 156 # adding elements in alphabetical order. 157 ############################################################################### 158 macro(sort_list LIST) 159 if(CMAKE244_OR_BETTER) 160 # For CMake 2.4.4 or better, this can be done automatically 161 list(SORT ${LIST}) 162 else(CMAKE244_OR_BETTER) 163 # For CMake 2.4.x before 2.4.4, we have to do this ourselves, firstly we'll create a temporary list 164 set(NEW_LIST) 165 # Iterate through the old list 166 foreach(ITEM ${${LIST}}) 167 # Temporary index position for the new list, as well as temporary value to store if the item was ever found 168 set(INDEX 0) 169 set(FOUND FALSE) 170 # Iterate through the new list 171 foreach(NEW_ITEM ${NEW_LIST}) 172 # Compare the items, only if nothing was found before 173 if(NOT FOUND) 174 if(NEW_ITEM STRGREATER "${ITEM}") 175 set(FOUND TRUE) 176 list(INSERT NEW_LIST ${INDEX} ${ITEM}) 177 endif(NEW_ITEM STRGREATER "${ITEM}") 178 endif(NOT FOUND) 179 # Increase the index value by 1 180 math(EXPR INDEX "${INDEX} + 1") 181 endforeach(NEW_ITEM) 182 # If the item was never found, just append it to the end 183 if(NOT FOUND) 184 append_to_list(NEW_LIST ${ITEM}) 185 endif(NOT FOUND) 186 endforeach(ITEM) 187 # Replace the old list with the new list 188 set(${LIST} ${NEW_LIST}) 189 endif(CMAKE244_OR_BETTER) 190 endmacro(sort_list) 191 192 ############################################################################### 193 # read_from_file(<filename> <regex> <output variable>) 194 # 195 # A macro to handle reading specific lines from a file, uses file(STRINGS) if 196 # using CMake 2.6.x or better, otherwise we read in the entire file and 197 # perform a string(REGEX MATCH) on each line of the file instead. This 198 # macro can also be used to read in all the lines of a file if REGEX is set 199 # to "". 200 ############################################################################### 201 macro(read_from_file FILE REGEX STRINGS) 202 if(CMAKE26_OR_BETTER) 203 # For CMake 2.6.x or better, we can just use the STRINGS sub-command to get the lines that match the given regular expression (if one is given, otherwise get all lines) 204 if(REGEX STREQUAL "") 205 file(STRINGS ${FILE} RESULT) 206 else(REGEX STREQUAL "") 207 file(STRINGS ${FILE} RESULT REGEX ${REGEX}) 208 endif(REGEX STREQUAL "") 209 else(CMAKE26_OR_BETTER) 210 # For CMake 2.4.x, we need to do this manually, firstly we read the file in 211 execute_process(COMMAND ${CMAKE_COMMAND} -DFILE:STRING=${FILE} -P ${Anope_SOURCE_DIR}/cmake/ReadFile.cmake ERROR_VARIABLE ALL_STRINGS) 212 # Next we replace all newlines with semicolons 213 string(REGEX REPLACE "\n" ";" ALL_STRINGS ${ALL_STRINGS}) 214 if(REGEX STREQUAL "") 215 # For no regular expression, just set the result to all the lines 216 set(RESULT ${ALL_STRINGS}) 217 else(REGEX STREQUAL "") 218 # Clear the result list 219 set(RESULT) 220 # Iterate through all the lines of the file 221 foreach(STRING ${ALL_STRINGS}) 222 # Check for a match against the given regular expression 223 string(REGEX MATCH ${REGEX} STRING_MATCH ${STRING}) 224 # If we had a match, append the match to the list 225 if(STRING_MATCH) 226 append_to_list(RESULT ${STRING}) 227 endif(STRING_MATCH) 228 endforeach(STRING) 229 endif(REGEX STREQUAL "") 230 endif(CMAKE26_OR_BETTER) 231 # Set the given STRINGS variable to the result 232 set(${STRINGS} ${RESULT}) 233 endmacro(read_from_file) 234 235 ############################################################################### 236 # extract_include_filename(<line> <output variable> [<optional output variable of quote type>]) 237 # 238 # This macro will take a #include line and extract the filename. 239 ############################################################################### 240 macro(extract_include_filename INCLUDE FILENAME) 241 # Strip the leading and trailing spaces from the include line 242 strip_string(${INCLUDE} INCLUDE_STRIPPED) 243 # Make sure to only do the following if there is a string 244 if(INCLUDE_STRIPPED STREQUAL "") 245 set(FILE "") 246 else(INCLUDE_STRIPPED STREQUAL "") 247 # Extract the filename including the quotes or angle brackets 248 string(REGEX REPLACE "^.*([\"<].*[\">]).*$" "\\1" FILE "${INCLUDE_STRIPPED}") 249 # If an optional 3rd argument is given, we'll store if the quote style was quoted or angle bracketed 250 if(${ARGC} GREATER 2) 251 string(SUBSTRING ${FILE} 0 1 QUOTE) 252 if(QUOTE STREQUAL "<") 253 set(${ARGV2} "angle brackets") 254 else(QUOTE STREQUAL "<") 255 set(${ARGV2} "quotes") 256 endif(QUOTE STREQUAL "<") 257 endif(${ARGC} GREATER 2) 258 # Now remove the quotes or angle brackets 259 string(REGEX REPLACE "^[\"<](.*)[\">]$" "\\1" FILE "${FILE}") 260 endif(INCLUDE_STRIPPED STREQUAL "") 261 # Set the filename to the the given variable 262 set(${FILENAME} "${FILE}") 263 endmacro(extract_include_filename) 264 265 ############################################################################### 266 # find_includes(<source filename> <output variable>) 267 # 268 # This macro will search through a file for #include lines, regardless of 269 # whitespace, but only returns the lines that are valid for the current 270 # platform CMake is running on. 271 ############################################################################### 272 macro(find_includes SRC INCLUDES) 273 # Read all lines from the file that start with #, regardless of whitespace before the # 274 read_from_file(${SRC} "^[ \t]*#.*$" LINES) 275 # Set that any #include lines found are valid, and create temporary variables for the last found #ifdef/#ifndef 276 set(VALID_LINE TRUE) 277 set(LAST_DEF) 278 set(LAST_CHECK) 279 # Create an empty include list 280 set(INCLUDES_LIST) 281 # Iterate through all the # lines 282 foreach(LINE ${LINES}) 283 # Search for #ifdef, #ifndef, #else, #endif, and #include 284 string(REGEX MATCH "^[ \t]*#[ \t]*ifdef[ \t]*.*$" FOUND_IFDEF ${LINE}) 285 string(REGEX MATCH "^[ \t]*#[ \t]*ifndef[ \t]*.*$" FOUND_IFNDEF ${LINE}) 286 string(REGEX MATCH "^[ \t]*#[ \t]*else.*$" FOUND_ELSE ${LINE}) 287 string(REGEX MATCH "^[ \t]*#[ \t]*endif.*$" FOUND_ENDIF ${LINE}) 288 string(REGEX MATCH "^[ \t]*#[ \t]*include[ \t]*[\"<].*[\">][\ t]*.*$" FOUND_INCLUDE ${LINE}) 289 # If we found a #ifdef on the line, extract the data after the #ifdef and set if the lines after it are valid based on the variables in CMake 290 if(FOUND_IFDEF) 291 # Extract the define 292 string(REGEX REPLACE "^[ \t]*#[ \t]*ifdef[ \t]*(.*)$" "\\1" DEFINE ${LINE}) 293 # Replace _WIN32 with WIN32, so we can check if the WIN32 variable of CMake is set instead of _WIN32 294 if(DEFINE STREQUAL "_WIN32") 295 set(DEFINE WIN32) 296 endif(DEFINE STREQUAL "_WIN32") 297 # Set the last define to this one, and set the last check to true, so when #else is encountered, we can do an opposing check 298 set(LAST_DEF ${DEFINE}) 299 set(LAST_CHECK TRUE) 300 # If the define is true (it either exists or is a non-false result), the lines following will be checked, otherwise they will be skipped 301 if(${DEFINE}) 302 set(VALID_LINE TRUE) 303 else(${DEFINE}) 304 set(VALID_LINE FALSE) 305 endif(${DEFINE}) 306 else(FOUND_IFDEF) 307 # If we found a #ifndef on the line, the same thing as #ifdef is done, except with the checks in the opposite direction 308 if(FOUND_IFNDEF) 309 # Extract the define 310 string(REGEX REPLACE "^[ \t]*#[ \t]*ifndef[ \t]*(.*)$" "\\1" DEFINE ${LINE}) 311 # Replace _WIN32 with WIN32, so we can check if the WIN32 variable of CMake is set instead of _WIN32 312 if(DEFINE STREQUAL "_WIN32") 313 set(DEFINE WIN32) 314 endif(DEFINE STREQUAL "_WIN32") 315 # Set the last define to this one, and set the last check to false, so when #else is encountered, we can do an opposing check 316 set(LAST_DEF ${DEFINE}) 317 set(LAST_CHECK FALSE) 318 # If the define is not true (it either doesn't exists or is a false result), the lines following will be checked, otherwise they will be skipped 319 if(${DEFINE}) 320 set(VALID_LINE FALSE) 321 else(${DEFINE}) 322 set(VALUE_LINE TRUE) 323 endif(${DEFINE}) 324 else(FOUND_IFNDEF) 325 # If we found a #else on the line, we check the last define in the opposite direction 326 if(FOUND_ELSE) 327 # When LAST_CHECK is true, we were inside a #ifdef, now act as if we are entering a #ifndef section by doing an opposing check 328 if(LAST_CHECK) 329 if(${LAST_DEF}) 330 set(VALID_LINE FALSE) 331 else(${LAST_DEF}) 332 set(VALID_LINE TRUE) 333 endif(${LAST_DEF}) 334 # When LAST_CHECK is false, we were inside a #ifndef, now act as if we are entering a #ifdef section by doing an opposing check 335 else(LAST_CHECK) 336 if(${LAST_DEF}) 337 set(VALID_LINE TRUE) 338 else(${LAST_DEF}) 339 set(VALID_LINE FALSE) 340 endif(${LAST_DEF}) 341 endif(LAST_CHECK) 342 else(FOUND_ELSE) 343 # If we found a #endif on the line, we'll assume everything following the line is valid until we meet another one of the above lines 344 if(FOUND_ENDIF) 345 set(VALID_LINE TRUE) 346 else(FOUND_ENDIF) 347 # If we found a #include on the line, add the entire line to the list of includes unless the line isn't valid 348 if(FOUND_INCLUDE) 349 if(VALID_LINE) 350 append_to_list(INCLUDES_LIST "${LINE}") 351 endif(VALID_LINE) 352 endif(FOUND_INCLUDE) 353 endif(FOUND_ENDIF) 354 endif(FOUND_ELSE) 355 endif(FOUND_IFNDEF) 356 endif(FOUND_IFDEF) 357 endforeach(LINE) 358 set(${INCLUDES} ${INCLUDES_LIST}) 359 endmacro(find_includes) 360 361 ############################################################################### 362 # calculate_depends(<source filename> [<optional output variable for includes>]) 363 # 364 # This macro is used in most of the src (sub)directories to calculate the 365 # header file dependencies for the given source file. 366 ############################################################################### 367 macro(calculate_depends SRC) 368 # Temporarily set that we didn't get a 3rd argument before we actually check if we did get one or not 369 set(CHECK_ANGLE_INCLUDES FALSE) 370 # Check for a third argument 371 if(${ARGC} GREATER 1) 372 set(CHECK_ANGLE_INCLUDES TRUE) 373 endif(${ARGC} GREATER 1) 374 # Find all the lines in the given source file that have any form of #include on them, regardless of whitespace, but only if they are valid for the platform we are on 375 find_includes(${SRC} INCLUDES) 376 # Reset the list of headers to empty 377 set(HEADERS) 378 # Iterate through the strings containing #include (if any) 379 foreach(INCLUDE ${INCLUDES}) 380 # Extract the filename from the #include line 381 extract_include_filename(${INCLUDE} FILENAME QUOTE_TYPE) 382 if(QUOTE_TYPE STREQUAL "angle brackets") 383 # The following checks will only be done if there was a request for angle includes to be checked 384 if(CHECK_ANGLE_INCLUDES) 385 # Find the path of the include file 386 if(DEFAULT_INCLUDE_DIRS OR WSDK_PATH OR DEFINED $ENV{VCINSTALLDIR}) 387 find_path(FOUND_${FILENAME}_INCLUDE NAMES ${FILENAME} PATHS ${DEFAULT_INCLUDE_DIRS} ${WSDK_PATH}/include $ENV{VCINSTALLDIR}/include ${EXTRA_INCLUDE}) 388 else(DEFAULT_INCLUDE_DIRS OR WSDK_PATH OR DEFINED $ENV{VCINSTALLDIR}) 389 find_path(FOUND_${FILENAME}_INCLUDE NAMES ${FILENAME} ${EXTRA_INCLUDE}) 390 endif(DEFAULT_INCLUDE_DIRS OR WSDK_PATH OR DEFINED $ENV{VCINSTALLDIR}) 391 # If the include file was found, add it's path to the list of include paths, but only if it doesn't already exist and isn't in the defaults for the compiler 392 if(FOUND_${FILENAME}_INCLUDE) 393 # This used to be find_in_list, but it was changed to this loop to do a find on each default include directory, this fixes Mac OS X trying to get it's framework directories in here 394 set(FOUND_IN_DEFAULTS -1) 395 foreach(DEFAULT_INCLUDE_DIR ${DEFAULT_INCLUDE_DIRS}) 396 string(REGEX REPLACE "\\+" "\\\\+" DEFAULT_INCLUDE_DIR ${DEFAULT_INCLUDE_DIR}) 397 string(REGEX MATCH ${DEFAULT_INCLUDE_DIR} FOUND_DEFAULT ${FOUND_${FILENAME}_INCLUDE}) 398 if(FOUND_DEFAULT) 399 set(FOUND_IN_DEFAULTS 0) 400 endif(FOUND_DEFAULT) 401 endforeach(DEFAULT_INCLUDE_DIR) 402 if(FOUND_IN_DEFAULTS EQUAL -1) 403 find_in_list(${ARGV1} "${FOUND_${FILENAME}_INCLUDE}" FOUND_IN_INCLUDES) 404 if(FOUND_IN_INCLUDES EQUAL -1) 405 append_to_list(${ARGV1} "${FOUND_${FILENAME}_INCLUDE}") 406 endif(FOUND_IN_INCLUDES EQUAL -1) 407 endif(FOUND_IN_DEFAULTS EQUAL -1) 408 else(FOUND_${FILENAME}_INCLUDE) 409 # XXX 410 if(NOT ${FILENAME} STREQUAL "libintl.h") 411 message(FATAL_ERROR "${SRC} needs header file ${FILENAME} but we were unable to locate that header file! Check that the header file is within the search path of your OS.") 412 endif(NOT ${FILENAME} STREQUAL "libintl.h") 413 endif(FOUND_${FILENAME}_INCLUDE) 414 endif(CHECK_ANGLE_INCLUDES) 415 endif(QUOTE_TYPE STREQUAL "angle brackets") 416 endforeach(INCLUDE) 417 endmacro(calculate_depends) 418 419 ############################################################################### 420 # calculate_libraries(<source filename> <output variable for linker flags> <output variable for extra depends>) 421 # 422 # This macro is used in most of the module (sub)directories to calculate the 423 # library dependencies for the given source file. 424 ############################################################################### 425 macro(calculate_libraries SRC SRC_LDFLAGS EXTRA_DEPENDS) 426 # Set up a temporary LDFLAGS for this file 427 set(THIS_LDFLAGS "${LDFLAGS}") 428 # Reset extra dependencies 429 set(EXTRA_DEPENDENCIES) 430 # Reset library paths 431 set(LIBRARY_PATHS) 432 # Reset libraries 433 set(LIBRARIES) 434 # Check to see if there are any lines matching: /* RequiredLibraries: [something] */ 435 if(WIN32) 436 read_from_file(${SRC} "/\\\\*[ \t]*RequiredWindowsLibraries:[ \t]*.*[ \t]*\\\\*/" REQUIRED_LIBRARIES) 437 else(WIN32) 438 read_from_file(${SRC} "/\\\\*[ \t]*RequiredLibraries:[ \t]*.*[ \t]*\\\\*/" REQUIRED_LIBRARIES) 439 endif(WIN32) 440 # Iterate through those lines 441 foreach(REQUIRED_LIBRARY ${REQUIRED_LIBRARIES}) 442 # Strip off the /* RequiredLibraries: and */ from the line 443 string(REGEX REPLACE "/\\*[ \t]*Required.*Libraries:[ \t]*([^ \t]*)[ \t]*\\*/" "\\1" REQUIRED_LIBRARY ${REQUIRED_LIBRARY}) 444 # Replace all commas with semicolons 445 string(REGEX REPLACE "," ";" REQUIRED_LIBRARY ${REQUIRED_LIBRARY}) 446 # Iterate through the libraries given 447 foreach(LIBRARY ${REQUIRED_LIBRARY}) 448 # If the library has multiple names extract the alternate. 449 unset(LIBRARY_ALT) 450 if (${LIBRARY} MATCHES "^.+\\|.+$") 451 string(REGEX REPLACE ".+\\|(.*)" "\\1" LIBRARY_ALT ${LIBRARY}) 452 string(REGEX REPLACE "(.+)\\|.*" "\\1" LIBRARY ${LIBRARY}) 453 endif(${LIBRARY} MATCHES "^.+\\|.+$") 454 # Locate the library to see if it exists 455 if(DEFAULT_LIBRARY_DIRS OR WSDK_PATH OR DEFINED $ENV{VCINSTALLDIR}) 456 find_library(FOUND_${LIBRARY}_LIBRARY NAMES ${LIBRARY} ${LIBRARY_ALT} PATHS ${DEFAULT_LIBRARY_DIRS} ${WSDK_PATH}/lib $ENV{VCINSTALLDIR}/lib ${EXTRA_INCLUDE} ${EXTRA_LIBS}) 457 else(DEFAULT_LIBRARY_DIRS OR WSDK_PATH OR DEFINED $ENV{VCINSTALLDIR}) 458 find_library(FOUND_${LIBRARY}_LIBRARY NAMES ${LIBRARY} ${LIBRARY_ALT} PATHS ${EXTRA_INCLUDE} ${EXTRA_LIBS} NO_DEFAULT_PATH) 459 find_library(FOUND_${LIBRARY}_LIBRARY NAMES ${LIBRARY} ${LIBRARY_ALT} PATHS ${EXTRA_INCLUDE} ${EXTRA_LIBS}) 460 endif(DEFAULT_LIBRARY_DIRS OR WSDK_PATH OR DEFINED $ENV{VCINSTALLDIR}) 461 # If the library was found, we will add it to the linker flags 462 if(FOUND_${LIBRARY}_LIBRARY) 463 if(MSVC) 464 # For Visual Studio, instead of editing the linker flags, we'll add the library to a separate list of extra dependencies 465 append_to_list(EXTRA_DEPENDENCIES "${FOUND_${LIBRARY}_LIBRARY}") 466 else(MSVC) 467 # Get the path only of the library, to add it to library paths. 468 get_filename_component(LIBRARY_PATH ${FOUND_${LIBRARY}_LIBRARY} PATH) 469 append_to_list(LIBRARY_PATHS "${LIBRARY_PATH}") 470 # Extract the library short name, add it to the library path 471 get_filename_component(LIBRARY_NAME ${FOUND_${LIBRARY}_LIBRARY} NAME_WE) 472 string(REGEX REPLACE "^lib" "" LIBRARY_NAME ${LIBRARY_NAME}) 473 append_to_list(LIBRARIES ${LIBRARY_NAME}) 474 endif(MSVC) 475 else(FOUND_${LIBRARY}_LIBRARY) 476 # In the case of the library not being found, we fatally error so CMake stops trying to generate 477 message(FATAL_ERROR "${SRC} needs library ${LIBRARY} but we were unable to locate that library! Check that the library is within the search path of your OS.") 478 endif(FOUND_${LIBRARY}_LIBRARY) 479 endforeach(LIBRARY) 480 endforeach(REQUIRED_LIBRARY) 481 # Remove duplicates from the library paths 482 if(LIBRARY_PATHS) 483 remove_list_duplicates(LIBRARY_PATHS) 484 endif(LIBRARY_PATHS) 485 # Remove diplicates from the libraries 486 if(LIBRARIES) 487 remove_list_duplicates(LIBRARIES) 488 endif(LIBRARIES) 489 # Iterate through library paths and add them to the linker flags 490 foreach(LIBRARY_PATH ${LIBRARY_PATHS}) 491 find_in_list(DEFAULT_LIBRARY_DIRS "${LIBRARY_PATH}" FOUND_IN_DEFAULTS) 492 if(FOUND_IN_DEFAULTS EQUAL -1) 493 set(THIS_LDFLAGS "${THIS_LDFLAGS} -L${LIBRARY_PATH}") 494 endif(FOUND_IN_DEFAULTS EQUAL -1) 495 endforeach(LIBRARY_PATH) 496 # Iterate through libraries and add them to the linker flags 497 foreach(LIBRARY ${LIBRARIES}) 498 append_to_list(EXTRA_DEPENDENCIES "${LIBRARY}") 499 endforeach(LIBRARY) 500 set(${SRC_LDFLAGS} "${THIS_LDFLAGS}") 501 set(${EXTRA_DEPENDS} "${EXTRA_DEPENDENCIES}") 502 endmacro(calculate_libraries) 503 504 ############################################################################### 505 # check_functions(<source filename> <output variable set to TRUE on success>) 506 # 507 # This macro is used in most of the module (sub)directories to calculate the 508 # function dependencies for the given source file. 509 ############################################################################### 510 macro(check_functions SRC SUCCESS) 511 # Default to true 512 set(${SUCCESS} TRUE) 513 # Check to see if there are any lines matching: /* RequiredFunctions: [something] */ 514 read_from_file(${SRC} "/\\\\*[ \t]*RequiredFunctions:[ \t]*.*[ \t]*\\\\*/" REQUIRED_FUNCTIONS) 515 # Iterate through those lines 516 foreach(REQUIRED_FUNCTION ${REQUIRED_FUNCTIONS}) 517 # Strip off the /* RequiredFunctions: and */ from the line 518 string(REGEX REPLACE "/\\*[ \t]*RequiredFunctions:[ \t]*([^ \t]*)[ \t]*\\*/" "\\1" REQUIRED_FUNCTION ${REQUIRED_FUNCTION}) 519 # Replace all commas with semicolons 520 string(REGEX REPLACE "," ";" REQUIRED_FUNCTION ${REQUIRED_FUNCTION}) 521 # Iterate through the functions given 522 foreach(FUNCTION ${REQUIRED_FUNCTION}) 523 # Check if the function exists 524 check_function_exists(${REQUIRED_FUNCTION} HAVE_${REQUIRED_FUNCTION}) 525 # If we don't have the function warn the user and set SUCCESS to FALSE 526 if(NOT HAVE_${REQUIRED_FUNCTION}) 527 message("${SRC} needs function ${REQUIRED_FUNCTION} but we were unable to locate that function!") 528 set(${SUCCESS} FALSE) 529 endif(NOT HAVE_${REQUIRED_FUNCTION}) 530 endforeach(FUNCTION) 531 endforeach(REQUIRED_FUNCTION) 532 endmacro(check_functions) 533 534 ############################################################################### 535 # add_to_cpack_ignored_files(<item> [TRUE]) 536 # 537 # A macro to update the environment variable CPACK_IGNORED_FILES which 538 # contains a list of files for CPack to ignore. If the optional 2nd argument 539 # of TRUE is given, periods will be converted to \\. for CPack. 540 ############################################################################### 541 macro(add_to_cpack_ignored_files ITEM) 542 # Temporary copy of the orignal item 543 set(REAL_ITEM "${ITEM}") 544 # If we have 2+ arguments, assume that the second one was something like TRUE (doesn't matter really) and convert periods so they will be \\. for CPack 545 if(${ARGC} GREATER 1) 546 string(REPLACE "." "\\\\." REAL_ITEM ${REAL_ITEM}) 547 endif(${ARGC} GREATER 1) 548 # If the environment variable is already defined, just tack the item to the end 549 if(DEFINED ENV{CPACK_IGNORED_FILES}) 550 set(ENV{CPACK_IGNORED_FILES} "$ENV{CPACK_IGNORED_FILES};${REAL_ITEM}") 551 # Otherwise set the environment variable to the item 552 else(DEFINED ENV{CPACK_IGNORED_FILES}) 553 set(ENV{CPACK_IGNORED_FILES} "${REAL_ITEM}") 554 endif(DEFINED ENV{CPACK_IGNORED_FILES}) 555 endmacro(add_to_cpack_ignored_files)