aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/ECMGenerateHeaders.cmake75
-rw-r--r--tests/ECMGenerateHeadersTest/CommonHeader4
-rw-r--r--tests/ECMGenerateHeadersTest/headtest4.h0
-rw-r--r--tests/ECMGenerateHeadersTest/run_test.cmake.config65
4 files changed, 123 insertions, 21 deletions
diff --git a/modules/ECMGenerateHeaders.cmake b/modules/ECMGenerateHeaders.cmake
index b6290223..cefc82df 100644
--- a/modules/ECMGenerateHeaders.cmake
+++ b/modules/ECMGenerateHeaders.cmake
@@ -12,12 +12,16 @@
# [OUTPUT_DIR <output_dir>]
# [PREFIX <prefix>]
# [REQUIRED_HEADERS <variable>]
+# [COMMON_HEADER <HeaderName>]
# [RELATIVE <relative_path>])
#
# For each CamelCase header name passed to HEADER_NAMES, a file of that name
# 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).
+# If a CamelCaseName consists of multiple comma-separated files, e.g.
+# ``ClassA,ClassB,ClassC``, then multiple camelcase header files will be
+# generated which are redirects to the first header file.
# The file locations of these generated headers will be stored in
# <camelcase_forwarding_headers_var>.
#
@@ -43,6 +47,9 @@
# CMakeLists.txt file; the original variant will then be added to this
# variable.
#
+# COMMON_HEADER generates an additional convenience header which includes all
+# other header files.
+#
# The RELATIVE argument indicates where the original headers can be found
# relative to CMAKE_CURRENT_SOURCE_DIR. It does not affect the generated
# CamelCase forwarding files, but ecm_generate_headers() uses it when checking
@@ -69,6 +76,7 @@
# MLBar
# # etc
# REQUIRED_HEADERS MyLib_HEADERS
+# COMMON_HEADER MLGeneral
# )
# install(FILES ${MyLib_FORWARDING_HEADERS} ${MyLib_HEADERS}
# DESTINATION ${CMAKE_INSTALL_PREFIX}/include
@@ -82,7 +90,9 @@
# MyLib_FORWARDING_HEADERS
# HEADERS
# Foo
-# Bar
+# # several classes are contained in bar.h, so generate
+# # additional files
+# Bar,BarList
# # etc
# PREFIX MyLib
# REQUIRED_HEADERS MyLib_HEADERS
@@ -99,6 +109,7 @@
#=============================================================================
# Copyright 2013 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
# Copyright 2014 Alex Merry <alex.merry@kdemail.net>
+# Copyright 2015 Patrick Spendrin <patrick.spendrin@kdab.com>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file COPYING-CMAKE-SCRIPTS for details.
@@ -114,7 +125,7 @@ include(CMakeParseArguments)
function(ECM_GENERATE_HEADERS camelcase_forwarding_headers_var)
set(options)
- set(oneValueArgs ORIGINAL OUTPUT_DIR PREFIX REQUIRED_HEADERS RELATIVE)
+ set(oneValueArgs ORIGINAL OUTPUT_DIR PREFIX REQUIRED_HEADERS COMMON_HEADER RELATIVE)
set(multiValueArgs HEADER_NAMES)
cmake_parse_arguments(EGH "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@@ -154,35 +165,57 @@ function(ECM_GENERATE_HEADERS camelcase_forwarding_headers_var)
endif()
endif()
- foreach(_CLASSNAME ${EGH_HEADER_NAMES})
+ foreach(_classnameentry ${EGH_HEADER_NAMES})
+ string(REPLACE "," ";" _classnames ${_classnameentry})
+ list(GET _classnames 0 _baseclass)
+
if (EGH_ORIGINAL STREQUAL "CAMELCASE")
- set(originalclassname "${_CLASSNAME}")
+ set(originalbasename "${_baseclass}")
else()
- string(TOLOWER "${_CLASSNAME}" originalclassname)
+ string(TOLOWER "${_baseclass}" originalbasename)
endif()
- set(FANCY_HEADER_FILE "${EGH_OUTPUT_DIR}/${EGH_PREFIX}${_CLASSNAME}")
- set(_actualheader "${CMAKE_CURRENT_SOURCE_DIR}/${EGH_RELATIVE}${originalclassname}.h")
+
+ set(_actualheader "${CMAKE_CURRENT_SOURCE_DIR}/${EGH_RELATIVE}${originalbasename}.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 \"${originalprefix}${originalclassname}.h\"\n")
- endif()
- 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}/${originalprefix}${originalclassname}.h)
- if (NOT EXISTS ${REGULAR_HEADER_NAME})
- file(WRITE ${REGULAR_HEADER_NAME} "#include \"${_actualheader}\"\n")
+
+ foreach(_CLASSNAME ${_classnames})
+ set(FANCY_HEADER_FILE "${EGH_OUTPUT_DIR}/${EGH_PREFIX}${_CLASSNAME}")
+ if (NOT EXISTS ${FANCY_HEADER_FILE})
+ file(WRITE ${FANCY_HEADER_FILE} "#include \"${originalprefix}${originalbasename}.h\"\n")
endif()
- endif()
+ list(APPEND ${camelcase_forwarding_headers_var} "${FANCY_HEADER_FILE}")
+ if (EGH_PREFIX)
+ # Local forwarding header, for namespaced headers, e.g. kparts/part.h
+ if(EGH_ORIGINAL STREQUAL "CAMELCASE")
+ set(originalclassname "${_CLASSNAME}")
+ else()
+ string(TOLOWER "${_CLASSNAME}" originalclassname)
+ endif()
+ 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()
+
+ list(APPEND _REQUIRED_HEADERS "${_actualheader}")
endforeach()
+ if(EGH_COMMON_HEADER)
+ #combine required headers into 1 big convenience header
+ set(COMMON_HEADER ${EGH_OUTPUT_DIR}/${EGH_PREFIX}${EGH_COMMON_HEADER})
+ file(WRITE ${COMMON_HEADER} "// convenience header\n")
+ foreach(_header ${_REQUIRED_HEADERS})
+ get_filename_component(_base ${_header} NAME)
+ file(APPEND ${COMMON_HEADER} "#include \"${_base}\"\n")
+ endforeach()
+ list(APPEND ${camelcase_forwarding_headers_var} "${COMMON_HEADER}")
+ endif()
+
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)
+ set(${EGH_REQUIRED_HEADERS} ${${EGH_REQUIRED_HEADERS}} ${_REQUIRED_HEADERS} PARENT_SCOPE)
endif ()
endfunction()
diff --git a/tests/ECMGenerateHeadersTest/CommonHeader b/tests/ECMGenerateHeadersTest/CommonHeader
new file mode 100644
index 00000000..0d101fbc
--- /dev/null
+++ b/tests/ECMGenerateHeadersTest/CommonHeader
@@ -0,0 +1,4 @@
+// convenience header
+#include "headtest1.h"
+#include "headtest2.h"
+#include "headtest4.h"
diff --git a/tests/ECMGenerateHeadersTest/headtest4.h b/tests/ECMGenerateHeadersTest/headtest4.h
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/ECMGenerateHeadersTest/headtest4.h
diff --git a/tests/ECMGenerateHeadersTest/run_test.cmake.config b/tests/ECMGenerateHeadersTest/run_test.cmake.config
index 1db623b7..a9027dbc 100644
--- a/tests/ECMGenerateHeadersTest/run_test.cmake.config
+++ b/tests/ECMGenerateHeadersTest/run_test.cmake.config
@@ -288,5 +288,70 @@ check_files(GENERATED ${expfiles}
check_files(GENERATED ${expfiles}
ORIGINALS ${intermediatefiles})
+###########################################################
+
+message(STATUS "Test 12: COMMON_HEADER")
+
+set(camelcase_headers)
+set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest1"
+ "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2"
+ "${CMAKE_CURRENT_BINARY_DIR}/HeadTest4"
+ "${CMAKE_CURRENT_BINARY_DIR}/CommonHeader")
+set(origfiles headtest1.h headtest2.h)
+file(REMOVE ${expfiles})
+ecm_generate_headers(
+ camelcase_headers
+ ORIGINAL LOWERCASE
+ HEADER_NAMES HeadTest1 HeadTest2 HeadTest4
+ COMMON_HEADER CommonHeader
+)
+if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
+ message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
+endif()
+check_files(GENERATED ${expfiles}
+ ORIGINALS ${origfiles})
+
+file(READ CommonHeader file_contents)
+string(STRIP "${file_contents}" file_contents)
+file(READ "${CMAKE_CURRENT_BINARY_DIR}/CommonHeader" exp_contents)
+string(STRIP "${exp_contents}" exp_contents)
+if (NOT "${file_contents}" STREQUAL "${exp_contents}")
+ message(FATAL_ERROR "${generated_file} contains '${file_contents}' instead of '${exp_contents}'")
+endif()
+
+
+###########################################################
+
+message(STATUS "Test 13: multiple classes and COMMON_HEADER")
+
+set(camelcase_headers)
+set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest1"
+ "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2"
+ "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2Add1"
+ "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2Add2"
+ "${CMAKE_CURRENT_BINARY_DIR}/HeadTest4"
+ "${CMAKE_CURRENT_BINARY_DIR}/CommonHeader")
+set(origfiles headtest1.h headtest2.h headtest4.h)
+file(REMOVE ${expfiles})
+ecm_generate_headers(
+ camelcase_headers
+ ORIGINAL LOWERCASE
+ HEADER_NAMES HeadTest1 HeadTest2,HeadTest2Add1,HeadTest2Add2 HeadTest4
+ COMMON_HEADER CommonHeader
+)
+if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
+ message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
+endif()
+check_files(GENERATED ${expfiles}
+ ORIGINALS ${origfiles})
+
+file(READ CommonHeader file_contents)
+string(STRIP "${file_contents}" file_contents)
+file(READ "${CMAKE_CURRENT_BINARY_DIR}/CommonHeader" exp_contents)
+string(STRIP "${exp_contents}" exp_contents)
+if (NOT "${file_contents}" STREQUAL "${exp_contents}")
+ message(FATAL_ERROR "${generated_file} contains '${file_contents}' instead of '${exp_contents}'")
+endif()
+
# vim:ft=cmake