diff options
| author | Friedrich W. H. Kossebau <kossebau@kde.org> | 2015-02-15 21:45:34 +0100 | 
|---|---|---|
| committer | Friedrich W. H. Kossebau <kossebau@kde.org> | 2015-02-15 21:45:34 +0100 | 
| commit | fc56bfbb62a9438960fec9e5960fde5f3e5c1a46 (patch) | |
| tree | c3d82ca95ed521d4790d2cf0d09ef4b0378ac9d3 /modules | |
| parent | 7c20867987d21fe36255e8b84fc0dd3003c88e14 (diff) | |
| download | extra-cmake-modules-fc56bfbb62a9438960fec9e5960fde5f3e5c1a46.tar.gz extra-cmake-modules-fc56bfbb62a9438960fec9e5960fde5f3e5c1a46.tar.bz2 | |
Extend ecm_generate_headers macro to also support CamelCase.h headers
REVIEW: 122317
Thanks alexmerry and dvratil for review
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/ECMGenerateHeaders.cmake | 77 | 
1 files changed, 49 insertions, 28 deletions
| diff --git a/modules/ECMGenerateHeaders.cmake b/modules/ECMGenerateHeaders.cmake index 5e5615b6..b6290223 100644 --- a/modules/ECMGenerateHeaders.cmake +++ b/modules/ECMGenerateHeaders.cmake @@ -6,26 +6,31 @@  #  # ::  # -#   ecm_generate_headers(<camelcase_headers_var> -#       HEADER_NAMES <CamelCaseHeader> [<CamelCaseHeader> [...]] +#   ecm_generate_headers(<camelcase_forwarding_headers_var> +#       HEADER_NAMES <CamelCaseName> [<CamelCaseName> [...]] +#       [ORIGINAL <CAMELCASE|LOWERCASE>]  #       [OUTPUT_DIR <output_dir>]  #       [PREFIX <prefix>]  #       [REQUIRED_HEADERS <variable>]  #       [RELATIVE <relative_path>])  #  # For each CamelCase header name passed to HEADER_NAMES, a file of that name -# will be generated that will include a lowercased version with ``.h`` appended. -# For example, the header ``ClassA`` will include ``classa.h``.  The file -# locations of these generated headers will be stored in -# <camelcase_headers_var>. -# -# PREFIX places the headers in subdirectories.  This should be a CamelCase name -# like KParts, which will cause the CamelCase headers to be placed in the KParts -# directory (eg: KParts/Part).  It will also, for the convenience of code in the -# source distribution, generate forwarding lowercase headers, like -# kparts/part.h.  This allows includes like "#include <kparts/part.h>" to be -# used before installation, as long as the include_directories are set -# appropriately. +# will be generated that will include a version with ``.h`` appended. +# For example, the generated header ``ClassA`` will include ``classa.h`` (or +# ``ClassA.h``, see ORIGINAL). +# The file locations of these generated headers will be stored in +# <camelcase_forwarding_headers_var>. +# +# ORIGINAL specifies how the name of the original header is written: lowercased +# or also camelcased.  The default is LOWERCASE. Since 1.8.0. +# +# PREFIX places the generated headers in subdirectories.  This should be a +# CamelCase name like ``KParts``, which will cause the CamelCase forwarding +# headers to be placed in the ``KParts`` directory (e.g. ``KParts/Part``).  It +# will also, for the convenience of code in the source distribution, generate +# forwarding headers based on the original names (e.g. ``kparts/part.h``).  This +# allows includes like ``"#include <kparts/part.h>"`` to be used before +# installation, as long as the include_directories are set appropriately.  #  # OUTPUT_DIR specifies where the files will be generated; this should be within  # the build directory. By default, ``${CMAKE_CURRENT_BINARY_DIR}`` will be used. @@ -35,14 +40,14 @@  # headers will be appended so that they can be installed together with the  # generated ones.  This is mostly intended as a convenience so that adding a new  # header to a project only requires specifying the CamelCase variant in the -# CMakeLists.txt file; the lowercase variant will then be added to this +# CMakeLists.txt file; the original variant will then be added to this  # variable.  # -# The RELATIVE argument indicates where the lowercase headers can be found +# The RELATIVE argument indicates where the original headers can be found  # relative to CMAKE_CURRENT_SOURCE_DIR.  It does not affect the generated -# CamelCase files, but ecm_generate_headers() uses it when checking that the -# lowercase header exists, and to generate lowercase forwarding headers when -# PREFIX is set. +# CamelCase forwarding files, but ecm_generate_headers() uses it when checking +# that the original header exists, and to generate originally named forwarding +# headers when PREFIX is set.  #  # To allow other parts of the source distribution (eg: tests) to use the  # generated headers before installation, it may be desirable to set the @@ -107,9 +112,9 @@  include(CMakeParseArguments) -function(ECM_GENERATE_HEADERS camelcase_headers_var) +function(ECM_GENERATE_HEADERS camelcase_forwarding_headers_var)      set(options) -    set(oneValueArgs OUTPUT_DIR PREFIX REQUIRED_HEADERS RELATIVE) +    set(oneValueArgs ORIGINAL OUTPUT_DIR PREFIX REQUIRED_HEADERS RELATIVE)      set(multiValueArgs HEADER_NAMES)      cmake_parse_arguments(EGH "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -121,6 +126,14 @@ function(ECM_GENERATE_HEADERS camelcase_headers_var)         message(FATAL_ERROR "Missing header_names argument to ECM_GENERATE_HEADERS")      endif() +    if(NOT EGH_ORIGINAL) +        # default +        set(EGH_ORIGINAL "LOWERCASE") +    endif() +    if(NOT EGH_ORIGINAL STREQUAL "LOWERCASE" AND NOT EGH_ORIGINAL STREQUAL "CAMELCASE") +        message(FATAL_ERROR "Unexpected value for original argument to ECM_GENERATE_HEADERS: ${EGH_ORIGINAL}") +    endif() +      if(NOT EGH_OUTPUT_DIR)          set(EGH_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")      endif() @@ -134,33 +147,41 @@ function(ECM_GENERATE_HEADERS camelcase_headers_var)          if (NOT "${EGH_PREFIX}" MATCHES "^.*/$")              set(EGH_PREFIX "${EGH_PREFIX}/")          endif() -        string(TOLOWER "${EGH_PREFIX}" lowercaseprefix) +        if (EGH_ORIGINAL STREQUAL "CAMELCASE") +            set(originalprefix "${EGH_PREFIX}") +        else() +            string(TOLOWER "${EGH_PREFIX}" originalprefix) +        endif()      endif()      foreach(_CLASSNAME ${EGH_HEADER_NAMES}) -        string(TOLOWER "${_CLASSNAME}" lowercaseclassname) +        if (EGH_ORIGINAL STREQUAL "CAMELCASE") +            set(originalclassname "${_CLASSNAME}") +        else() +            string(TOLOWER "${_CLASSNAME}" originalclassname) +        endif()          set(FANCY_HEADER_FILE "${EGH_OUTPUT_DIR}/${EGH_PREFIX}${_CLASSNAME}") -        set(_actualheader "${CMAKE_CURRENT_SOURCE_DIR}/${EGH_RELATIVE}${lowercaseclassname}.h") +        set(_actualheader "${CMAKE_CURRENT_SOURCE_DIR}/${EGH_RELATIVE}${originalclassname}.h")          if (NOT EXISTS ${_actualheader})              message(FATAL_ERROR "Could not find \"${_actualheader}\"")          endif()          if (NOT EXISTS ${FANCY_HEADER_FILE}) -            file(WRITE ${FANCY_HEADER_FILE} "#include \"${lowercaseprefix}${lowercaseclassname}.h\"\n") +            file(WRITE ${FANCY_HEADER_FILE} "#include \"${originalprefix}${originalclassname}.h\"\n")          endif() -        list(APPEND ${camelcase_headers_var} "${FANCY_HEADER_FILE}") +        list(APPEND ${camelcase_forwarding_headers_var} "${FANCY_HEADER_FILE}")          if (EGH_REQUIRED_HEADERS)              list(APPEND ${EGH_REQUIRED_HEADERS} "${_actualheader}")          endif()          if (EGH_PREFIX)              # Local forwarding header, for namespaced headers, e.g. kparts/part.h -            set(REGULAR_HEADER_NAME ${EGH_OUTPUT_DIR}/${lowercaseprefix}${lowercaseclassname}.h) +            set(REGULAR_HEADER_NAME ${EGH_OUTPUT_DIR}/${originalprefix}${originalclassname}.h)              if (NOT EXISTS ${REGULAR_HEADER_NAME})                  file(WRITE ${REGULAR_HEADER_NAME} "#include \"${_actualheader}\"\n")              endif()          endif()      endforeach() -    set(${camelcase_headers_var} ${${camelcase_headers_var}} PARENT_SCOPE) +    set(${camelcase_forwarding_headers_var} ${${camelcase_forwarding_headers_var}} PARENT_SCOPE)      if (NOT EGH_REQUIRED_HEADERS STREQUAL "")          set(${EGH_REQUIRED_HEADERS} ${${EGH_REQUIRED_HEADERS}} PARENT_SCOPE)      endif () | 
