|
| 1 | +include_guard() |
| 2 | + |
| 3 | +include(DsdaHelpers) |
| 4 | + |
| 5 | +set(DSDA_INTERNAL_GENERATED_CONFIG_DIR "${PROJECT_BINARY_DIR}/build-config") |
| 6 | + |
| 7 | +# Internal functions, these should not be called from outside this module |
| 8 | + |
| 9 | +function(dsda_internal_check_symbols) |
| 10 | + include(CheckSymbolExists) |
| 11 | + |
| 12 | + check_symbol_exists(stricmp "string.h" HAVE_STRICMP) |
| 13 | + check_symbol_exists(strnicmp "string.h" HAVE_STRNICMP) |
| 14 | + check_symbol_exists(getopt "unistd.h" HAVE_GETOPT) |
| 15 | + check_symbol_exists(mmap "sys/mman.h" HAVE_MMAP) |
| 16 | + check_symbol_exists(CreateFileMapping "windows.h" HAVE_CREATE_FILE_MAPPING) |
| 17 | + check_symbol_exists(strsignal "string.h" HAVE_STRSIGNAL) |
| 18 | + check_symbol_exists(mkstemp "stdlib.h" HAVE_MKSTEMP) |
| 19 | + check_symbol_exists(getpwuid "unistd.h;sys/types.h;pwd.h" HAVE_GETPWUID) |
| 20 | +endfunction() |
| 21 | + |
| 22 | +function(dsda_internal_check_includes) |
| 23 | + include(CheckIncludeFile) |
| 24 | + |
| 25 | + check_include_file("sys/wait.h" HAVE_SYS_WAIT_H) |
| 26 | + check_include_file("unistd.h" HAVE_UNISTD_H) |
| 27 | + check_include_file("asm/byteorder.h" HAVE_ASM_BYTEORDER_H) |
| 28 | + check_include_file("dirent.h" HAVE_DIRENT_H) |
| 29 | +endfunction() |
| 30 | + |
| 31 | +function(dsda_internal_check_variables) |
| 32 | + set(expected_vars |
| 33 | + PROJECT_NAME |
| 34 | + PROJECT_TARNAME |
| 35 | + WAD_DATA |
| 36 | + PROJECT_VERSION |
| 37 | + PROJECT_STRING |
| 38 | + DOOMWADDIR |
| 39 | + DSDA_ABSOLUTE_PWAD_PATH |
| 40 | + WORDS_BIGENDIAN |
| 41 | + SIMPLECHECKS |
| 42 | + RANGECHECK |
| 43 | + ) |
| 44 | + foreach(var IN LISTS expected_vars) |
| 45 | + if(NOT DEFINED ${var}) |
| 46 | + message(FATAL_ERROR "config.h cannot be generated: \"${var}\" is not set") |
| 47 | + endif() |
| 48 | + endforeach() |
| 49 | +endfunction() |
| 50 | + |
| 51 | +function(dsda_internal_generate_build_config) |
| 52 | + include(CheckBigEndian) |
| 53 | + check_big_endian(WORDS_BIGENDIAN) |
| 54 | + |
| 55 | + dsda_internal_check_symbols() |
| 56 | + dsda_internal_check_includes() |
| 57 | + dsda_internal_check_variables() |
| 58 | + |
| 59 | + configure_file( |
| 60 | + "${CMAKE_CURRENT_LIST_DIR}/config.h.cin" |
| 61 | + "${DSDA_INTERNAL_GENERATED_CONFIG_DIR}/config.h" |
| 62 | + ) |
| 63 | +endfunction() |
| 64 | + |
| 65 | +dsda_internal_generate_build_config() |
| 66 | + |
| 67 | +# Public functions |
| 68 | + |
| 69 | +function(dsda_target_use_config_h tgt) |
| 70 | + dsda_fail_if_invalid_target(${tgt}) |
| 71 | + |
| 72 | + target_sources(${tgt} |
| 73 | + PRIVATE |
| 74 | + "${DSDA_INTERNAL_GENERATED_CONFIG_DIR}/config.h" |
| 75 | + ) |
| 76 | + |
| 77 | + target_include_directories(${tgt} |
| 78 | + PRIVATE |
| 79 | + $<BUILD_INTERFACE:${DSDA_INTERNAL_GENERATED_CONFIG_DIR}> |
| 80 | + ) |
| 81 | + |
| 82 | + target_compile_definitions(${TARGET} |
| 83 | + PRIVATE |
| 84 | + HAVE_CONFIG_H |
| 85 | + $<$<NOT:$<BOOL:${HAVE_STRICMP}>>:stricmp=strcasecmp> |
| 86 | + $<$<NOT:$<BOOL:${HAVE_STRNICMP}>>:strnicmp=strncasecmp> |
| 87 | + ) |
| 88 | +endfunction() |
0 commit comments