aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Merry <kde@randomguy3.me.uk>2014-02-15 16:42:47 +0000
committerAlex Merry <kde@randomguy3.me.uk>2014-02-16 10:49:12 +0000
commit434c63acd090568147505ff1c31053dcb1b3863f (patch)
tree95ae83b51b2bc658d8eaf7113aed5a9cb0552afe /tests
parent3d931552b72972adb0cefe79cc4d9586671d5224 (diff)
downloadextra-cmake-modules-434c63acd090568147505ff1c31053dcb1b3863f.tar.gz
extra-cmake-modules-434c63acd090568147505ff1c31053dcb1b3863f.tar.bz2
Improve the ECMGenerateHeaders API with a variable for generated files
ecm_generate_headers() now allows/forces the caller to collect the paths of the generated headers, so that they can be passed to the install command. This avoids issues of unexpected files being in the CamelCase includes directory, both from previous builds and because of case-insensitive file systems. MODULE_NAME is removed, as it is no longer desirable or necessary. Instead, the headers are placed directly in the output directory (usually CMAKE_CURRENT_BUILD_DIR). Overall, this makes ecm_generate_headers() behave much more like other file generation macros (like the Qt ones). The old syntax is still supported for now, to make the porting effort easier. REVIEW: 115765
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/ECMGenerateHeadersTest/CMakeLists.txt6
-rw-r--r--tests/ECMGenerateHeadersTest/headsubdir/headtest2.h0
-rw-r--r--tests/ECMGenerateHeadersTest/headsubdir/headtest3.h0
-rw-r--r--tests/ECMGenerateHeadersTest/headtest1.h0
-rw-r--r--tests/ECMGenerateHeadersTest/headtest2.h0
-rw-r--r--tests/ECMGenerateHeadersTest/run_test.cmake.config247
7 files changed, 256 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 4347a92d..e464a030 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,5 +1,8 @@
# a macro for tests that have a simple format where the name matches the
# directory and project
+
+add_subdirectory(ECMGenerateHeadersTest)
+
macro(ADD_TEST_MACRO NAME COMMAND)
string(REPLACE "." "/" dir "${NAME}")
string(REGEX REPLACE "[^.]*\\." "" proj "${NAME}")
diff --git a/tests/ECMGenerateHeadersTest/CMakeLists.txt b/tests/ECMGenerateHeadersTest/CMakeLists.txt
new file mode 100644
index 00000000..9f407cb0
--- /dev/null
+++ b/tests/ECMGenerateHeadersTest/CMakeLists.txt
@@ -0,0 +1,6 @@
+set(MODULES_DIR "${extra-cmake-modules_SOURCE_DIR}/modules")
+configure_file(run_test.cmake.config "${CMAKE_CURRENT_BINARY_DIR}/run_test.cmake" @ONLY)
+
+add_test(
+ NAME ECMGenerateHeaders
+ COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/run_test.cmake")
diff --git a/tests/ECMGenerateHeadersTest/headsubdir/headtest2.h b/tests/ECMGenerateHeadersTest/headsubdir/headtest2.h
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/ECMGenerateHeadersTest/headsubdir/headtest2.h
diff --git a/tests/ECMGenerateHeadersTest/headsubdir/headtest3.h b/tests/ECMGenerateHeadersTest/headsubdir/headtest3.h
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/ECMGenerateHeadersTest/headsubdir/headtest3.h
diff --git a/tests/ECMGenerateHeadersTest/headtest1.h b/tests/ECMGenerateHeadersTest/headtest1.h
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/ECMGenerateHeadersTest/headtest1.h
diff --git a/tests/ECMGenerateHeadersTest/headtest2.h b/tests/ECMGenerateHeadersTest/headtest2.h
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/ECMGenerateHeadersTest/headtest2.h
diff --git a/tests/ECMGenerateHeadersTest/run_test.cmake.config b/tests/ECMGenerateHeadersTest/run_test.cmake.config
new file mode 100644
index 00000000..0a2425fe
--- /dev/null
+++ b/tests/ECMGenerateHeadersTest/run_test.cmake.config
@@ -0,0 +1,247 @@
+set(CMAKE_MODULE_PATH "@MODULES_DIR@")
+set(CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
+set(CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@")
+
+include(ECMGenerateHeaders)
+include(CMakeParseArguments)
+
+function (check_files)
+ set(options)
+ set(oneValueArgs GENERATED ORIGINALS)
+ set(multiValueArgs)
+ cmake_parse_arguments(CF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+ list(LENGTH CF_GENERATED count)
+ foreach(i RANGE ${count})
+ list(GET CF_GENERATED 0 generated_file)
+ list(GET CF_ORIGINALS 0 original_file)
+ if (NOT EXISTS "${generated_file}")
+ message(FATAL_ERROR "${generated_file} was not generated")
+ endif()
+ file(READ "${generated_file}" file_contents)
+ string(STRIP "${file_contents}" file_contents)
+ set (exp_contents "#include \"${original_file}\"")
+ if (NOT "${file_contents}" STREQUAL "${exp_contents}")
+ message(FATAL_ERROR "${generated_file} contains '${file_contents}' instead of '${exp_contents}'")
+ endif()
+ endforeach()
+endfunction()
+
+###########################################################
+
+message(STATUS "Test 1: no optional arguments")
+set(camelcase_headers)
+set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest1"
+ "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2")
+set(origfiles headtest1.h headtest2.h)
+file(REMOVE ${expfiles})
+ecm_generate_headers(
+ camelcase_headers
+ HEADER_NAMES HeadTest1 HeadTest2
+)
+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})
+
+
+###########################################################
+
+message(STATUS "Test 2: RELATIVE")
+set(camelcase_headers)
+set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2"
+ "${CMAKE_CURRENT_BINARY_DIR}/HeadTest3")
+set(origfiles headtest2.h headtest3.h)
+file(REMOVE ${expfiles})
+ecm_generate_headers(
+ camelcase_headers
+ HEADER_NAMES HeadTest2 HeadTest3
+ RELATIVE headsubdir
+)
+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})
+
+
+###########################################################
+
+message(STATUS "Test 3: OUTPUT_DIR")
+set(camelcase_headers)
+set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/testdir/HeadTest1"
+ "${CMAKE_CURRENT_BINARY_DIR}/testdir/HeadTest2")
+set(origfiles headtest1.h headtest2.h)
+file(REMOVE ${expfiles})
+ecm_generate_headers(
+ camelcase_headers
+ HEADER_NAMES HeadTest1 HeadTest2
+ OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/testdir"
+)
+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})
+
+
+###########################################################
+
+message(STATUS "Test 4: PREFIX")
+set(camelcase_headers)
+set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/Module/HeadTest1"
+ "${CMAKE_CURRENT_BINARY_DIR}/Module/HeadTest2")
+set(intermediatefiles module/headtest1.h module/headtest2.h)
+set(origfiles "${CMAKE_CURRENT_SOURCE_DIR}/headtest1.h"
+ "${CMAKE_CURRENT_SOURCE_DIR}/headtest2.h")
+file(REMOVE ${expfiles} ${intermediatefiles})
+ecm_generate_headers(
+ camelcase_headers
+ HEADER_NAMES HeadTest1 HeadTest2
+ PREFIX Module
+)
+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 ${intermediatefiles})
+check_files(GENERATED ${expfiles}
+ ORIGINALS ${intermediatefiles})
+
+
+###########################################################
+
+message(STATUS "Test 5: REQUIRED_HEADERS")
+set(camelcase_headers)
+set(req_headers)
+set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest1"
+ "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2")
+set(origfiles headtest1.h headtest2.h)
+set(origpaths "${CMAKE_CURRENT_SOURCE_DIR}/headtest1.h"
+ "${CMAKE_CURRENT_SOURCE_DIR}/headtest2.h")
+file(REMOVE ${expfiles})
+ecm_generate_headers(
+ camelcase_headers
+ HEADER_NAMES HeadTest1 HeadTest2
+ REQUIRED_HEADERS req_headers
+)
+if (NOT "${origpaths}" STREQUAL "${req_headers}")
+ message(FATAL_ERROR "REQUIRED_HEADERS var was set to \"${req_headers}\" instead of \"${origpaths}\"")
+endif()
+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})
+
+
+###########################################################
+
+message(STATUS "Test 6: RELATIVE and REQUIRED_HEADERS")
+set(camelcase_headers)
+set(req_headers)
+set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2"
+ "${CMAKE_CURRENT_BINARY_DIR}/HeadTest3")
+set(origfiles headtest2.h headtest3.h)
+set(origpaths "${CMAKE_CURRENT_SOURCE_DIR}/headsubdir/headtest2.h"
+ "${CMAKE_CURRENT_SOURCE_DIR}/headsubdir/headtest3.h")
+file(REMOVE ${expfiles})
+ecm_generate_headers(
+ camelcase_headers
+ HEADER_NAMES HeadTest2 HeadTest3
+ RELATIVE headsubdir
+ REQUIRED_HEADERS req_headers
+)
+if (NOT "${origpaths}" STREQUAL "${req_headers}")
+ message(FATAL_ERROR "REQUIRED_HEADERS var was set to \"${req_headers}\" instead of \"${origpaths}\"")
+endif()
+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})
+
+
+###########################################################
+
+message(STATUS "Test 7: OUTPUT_DIR and REQUIRED_HEADERS")
+set(camelcase_headers)
+set(req_headers)
+set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/testdir/HeadTest1"
+ "${CMAKE_CURRENT_BINARY_DIR}/testdir/HeadTest2")
+set(origfiles headtest1.h headtest2.h)
+set(origpaths "${CMAKE_CURRENT_SOURCE_DIR}/headtest1.h"
+ "${CMAKE_CURRENT_SOURCE_DIR}/headtest2.h")
+file(REMOVE ${expfiles})
+ecm_generate_headers(
+ camelcase_headers
+ HEADER_NAMES HeadTest1 HeadTest2
+ OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/testdir"
+ REQUIRED_HEADERS req_headers
+)
+if (NOT "${origpaths}" STREQUAL "${req_headers}")
+ message(FATAL_ERROR "REQUIRED_HEADERS var was set to \"${req_headers}\" instead of \"${origpaths}\"")
+endif()
+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})
+
+
+###########################################################
+
+message(STATUS "Test 8: PREFIX and REQUIRED_HEADERS")
+set(camelcase_headers)
+set(req_headers)
+set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/Module/HeadTest1"
+ "${CMAKE_CURRENT_BINARY_DIR}/Module/HeadTest2")
+set(intermediatefiles module/headtest1.h module/headtest2.h)
+set(origfiles "${CMAKE_CURRENT_SOURCE_DIR}/headtest1.h"
+ "${CMAKE_CURRENT_SOURCE_DIR}/headtest2.h")
+set(origpaths ${origfiles})
+file(REMOVE ${expfiles} ${intermediatefiles})
+ecm_generate_headers(
+ camelcase_headers
+ HEADER_NAMES HeadTest1 HeadTest2
+ PREFIX Module
+ REQUIRED_HEADERS req_headers
+)
+if (NOT "${origpaths}" STREQUAL "${req_headers}")
+ message(FATAL_ERROR "REQUIRED_HEADERS var was set to \"${req_headers}\" instead of \"${origpaths}\"")
+endif()
+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 ${intermediatefiles})
+check_files(GENERATED ${expfiles}
+ ORIGINALS ${intermediatefiles})
+
+
+###########################################################
+
+message(STATUS "Test 9: REQUIRED_HEADERS (duplicate var)")
+set(all_headers)
+set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest1"
+ "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2")
+set(origfiles headtest1.h headtest2.h)
+set(origpaths "${CMAKE_CURRENT_SOURCE_DIR}/headtest1.h"
+ "${CMAKE_CURRENT_SOURCE_DIR}/headtest2.h")
+file(REMOVE ${expfiles})
+ecm_generate_headers(
+ all_headers
+ HEADER_NAMES HeadTest1 HeadTest2
+ REQUIRED_HEADERS all_headers
+)
+list(SORT all_headers)
+set(exp_headers ${expfiles} ${origpaths})
+list(SORT exp_headers)
+if (NOT "${exp_headers}" STREQUAL "${all_headers}")
+ message(FATAL_ERROR "combined headers var was set to \"${all_headers}\" instead of \"${exp_headers}\"")
+endif()
+check_files(GENERATED ${expfiles}
+ ORIGINALS ${origfiles})
+
+
+# vim:ft=cmake