diff options
Diffstat (limited to 'Tests')
26 files changed, 246 insertions, 11 deletions
diff --git a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt index 6604208..fc65e58 100644 --- a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt +++ b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt @@ -71,7 +71,7 @@ endmacro(check_version_string) # reported. foreach(VTEST ALSA ARMADILLO BZIP2 CUPS CURL EXPAT FREETYPE GETTEXT GIT HSPELL - JASPER LIBXML2 LIBXSLT PERL PostgreSQL TIFF ZLIB) + JASPER LIBXML2 LIBXSLT PERL PKG_CONFIG PostgreSQL TIFF ZLIB) check_version_string(${VTEST} ${VTEST}_VERSION_STRING) endforeach(VTEST) @@ -82,4 +82,3 @@ endforeach(VTEST) check_version_string(PYTHONINTERP PYTHON_VERSION_STRING) check_version_string(SUBVERSION Subversion_VERSION_SVN) -check_version_string(PKGCONFIG PKG_CONFIG_VERSION_STRING) diff --git a/Tests/Plugin/CMakeLists.txt b/Tests/Plugin/CMakeLists.txt index b0942c0..31ca59c 100644 --- a/Tests/Plugin/CMakeLists.txt +++ b/Tests/Plugin/CMakeLists.txt @@ -39,6 +39,50 @@ TARGET_LINK_LIBRARIES(example_exe kwsys) ADD_LIBRARY(example_mod_1 MODULE src/example_mod_1.c) TARGET_LINK_LIBRARIES(example_mod_1 example_exe) + +IF(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG AND + "${CMAKE_C_CREATE_SHARED_MODULE}" MATCHES "SONAME_FLAG") + # Add a second plugin that should not have any soname. + ADD_LIBRARY(example_mod_2 MODULE src/example_mod_1.c) + TARGET_LINK_LIBRARIES(example_mod_2 example_exe) + SET_PROPERTY(TARGET example_mod_2 PROPERTY NO_SONAME 1) + + # Verify that targets export with proper IMPORTED SONAME properties. + EXPORT(TARGETS example_mod_1 example_mod_2 NAMESPACE exp_ + FILE ${CMAKE_CURRENT_BINARY_DIR}/mods.cmake) + INCLUDE(${CMAKE_CURRENT_BINARY_DIR}/mods.cmake) + GET_PROPERTY(configs TARGET exp_example_mod_1 PROPERTY IMPORTED_CONFIGURATIONS) + FOREACH(c ${configs}) + STRING(TOUPPER "${c}" CONFIG) + GET_PROPERTY(soname1 TARGET exp_example_mod_1 PROPERTY IMPORTED_SONAME_${CONFIG}) + GET_PROPERTY(soname2 TARGET exp_example_mod_2 PROPERTY IMPORTED_NO_SONAME_${CONFIG}) + IF(soname1) + MESSAGE(STATUS "exp_example_mod_1 has IMPORTED_SONAME_${CONFIG} as expected: ${soname1}") + ELSE() + MESSAGE(SEND_ERROR "exp_example_mod_1 does not have IMPORTED_SONAME_${CONFIG} but should") + ENDIF() + IF(soname2) + MESSAGE(STATUS "exp_example_mod_2 has IMPORTED_NO_SONAME_${CONFIG} as expected: ${soname2}") + ELSE() + MESSAGE(SEND_ERROR "exp_example_mod_2 does not have IMPORTED_NO_SONAME_${CONFIG} but should") + ENDIF() + ENDFOREACH() + + # Parse the binary to check for SONAME if possible. + IF("${CMAKE_EXECUTABLE_FORMAT}" MATCHES "ELF") + FIND_PROGRAM(READELF_EXE readelf) + IF(READELF_EXE) + ADD_CUSTOM_TARGET(check_mod_soname ALL COMMAND + ${CMAKE_COMMAND} -Dreadelf=${READELF_EXE} + -Dmod1=$<TARGET_FILE:example_mod_1> + -Dmod2=$<TARGET_FILE:example_mod_2> + -P ${CMAKE_CURRENT_SOURCE_DIR}/check_mod_soname.cmake + ) + ADD_DEPENDENCIES(check_mod_soname example_mod_1 example_mod_2) + ENDIF() + ENDIF() +ENDIF() + # TODO: # - create a plugin that links to a static lib # - create a plugin that links to a shared lib diff --git a/Tests/Plugin/check_mod_soname.cmake b/Tests/Plugin/check_mod_soname.cmake new file mode 100644 index 0000000..3737b45 --- /dev/null +++ b/Tests/Plugin/check_mod_soname.cmake @@ -0,0 +1,14 @@ +execute_process(COMMAND ${readelf} -d ${mod1} OUTPUT_FILE ${mod1}.readelf.txt) +execute_process(COMMAND ${readelf} -d ${mod2} OUTPUT_FILE ${mod2}.readelf.txt) +file(STRINGS ${mod1}.readelf.txt soname1 REGEX "\\(SONAME\\)") +file(STRINGS ${mod2}.readelf.txt soname2 REGEX "\\(SONAME\\)") +if(soname1) + message(STATUS "${mod1} has soname as expected: ${soname1}") +else() + message(FATAL_ERROR "${mod1} has no soname but should:\n ${soname1}") +endif() +if(soname2) + message(FATAL_ERROR "${mod2} has soname but should not:\n ${soname2}") +else() + message(STATUS "${mod2} has no soname as expected") +endif() diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 0b79efa..1c6db39 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -24,11 +24,16 @@ # 4.) Create a <SubTest>.cmake file for each sub-test named above # containing the actual test code. Optionally create files # containing expected test results: -# <SubTest>-result.txt = Process result expected if not "0" -# <SubTest>-stdout.txt = Regex matching expected stdout content -# <SubTest>-stderr.txt = Regex matching expected stderr content +# <SubTest>-result.txt = Process result expected if not "0" +# <SubTest>-stdout.txt = Regex matching expected stdout content +# <SubTest>-stderr.txt = Regex matching expected stderr content +# <SubTest>-check.cmake = Custom result check # Note that trailing newlines will be stripped from actual test # output before matching against the stdout and stderr expressions. +# The code in <SubTest>-check.cmake may use variables +# RunCMake_TEST_SOURCE_DIR = Top of test source tree +# RunCMake_TEST_BINARY_DIR = Top of test binary tree +# and an failure must store a message in RunCMake_TEST_FAILED. macro(add_RunCMake_test test) add_test(RunCMake.${test} ${CMAKE_CMAKE_COMMAND} @@ -44,3 +49,8 @@ add_RunCMake_test(ObjectLibrary) add_RunCMake_test(build_command) add_RunCMake_test(find_package) +add_RunCMake_test(list) + +if("${CMAKE_TEST_GENERATOR}" MATCHES "Visual Studio [^6]") + add_RunCMake_test(include_external_msproject) +endif() diff --git a/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake index 2639463..c3c161a 100644 --- a/Tests/RunCMake/RunCMake.cmake +++ b/Tests/RunCMake/RunCMake.cmake @@ -25,14 +25,14 @@ function(run_cmake test) unset(expect_std${o}) endif() endforeach() - set(source_dir "${top_src}") - set(binary_dir "${top_bin}/${test}-build") - file(REMOVE_RECURSE "${binary_dir}") - file(MAKE_DIRECTORY "${binary_dir}") + set(RunCMake_TEST_SOURCE_DIR "${top_src}") + set(RunCMake_TEST_BINARY_DIR "${top_bin}/${test}-build") + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") execute_process( - COMMAND ${CMAKE_COMMAND} "${source_dir}" + COMMAND ${CMAKE_COMMAND} "${RunCMake_TEST_SOURCE_DIR}" -G "${RunCMake_GENERATOR}" -DRunCMake_TEST=${test} - WORKING_DIRECTORY "${binary_dir}" + WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}" OUTPUT_VARIABLE actual_stdout ERROR_VARIABLE actual_stderr RESULT_VARIABLE actual_result @@ -53,6 +53,11 @@ function(run_cmake test) endif() endif() endforeach() + unset(RunCMake_TEST_FAILED) + include(${top_src}/${test}-check.cmake OPTIONAL) + if(RunCMake_TEST_FAILED) + set(msg "${RunCMake_TEST_FAILED}\n${msg}") + endif() if(msg) string(REGEX REPLACE "\n" "\n actual-out> " actual_out " actual-out> ${actual_stdout}") string(REGEX REPLACE "\n" "\n actual-err> " actual_err " actual-err> ${actual_stderr}") diff --git a/Tests/RunCMake/include_external_msproject/CMakeLists.txt b/Tests/RunCMake/include_external_msproject/CMakeLists.txt new file mode 100644 index 0000000..e8db6b0 --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/include_external_msproject/CustomGuid-check.cmake b/Tests/RunCMake/include_external_msproject/CustomGuid-check.cmake new file mode 100644 index 0000000..68dec4c --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/CustomGuid-check.cmake @@ -0,0 +1 @@ +check_project(CustomGuid external "aaa-bbb-ccc-000" "" "") diff --git a/Tests/RunCMake/include_external_msproject/CustomGuid.cmake b/Tests/RunCMake/include_external_msproject/CustomGuid.cmake new file mode 100644 index 0000000..1dbe7da --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/CustomGuid.cmake @@ -0,0 +1,2 @@ +include_external_msproject(external external.project + GUID aaa-bbb-ccc-000) diff --git a/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform-check.cmake b/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform-check.cmake new file mode 100644 index 0000000..614712e --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform-check.cmake @@ -0,0 +1 @@ +check_project(CustomGuidTypePlatform external "aaa-bbb-ccc-111" "aaa-bbb-ccc-ddd-eee" "Custom Platform") diff --git a/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform.cmake b/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform.cmake new file mode 100644 index 0000000..ee4db65 --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform.cmake @@ -0,0 +1,5 @@ +# Test all optional parameters are set. +include_external_msproject(external external.project + GUID aaa-bbb-ccc-111 + TYPE aaa-bbb-ccc-ddd-eee + PLATFORM "Custom Platform") diff --git a/Tests/RunCMake/include_external_msproject/CustomTypePlatform-check.cmake b/Tests/RunCMake/include_external_msproject/CustomTypePlatform-check.cmake new file mode 100644 index 0000000..054eeb0 --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/CustomTypePlatform-check.cmake @@ -0,0 +1 @@ +check_project(CustomTypePlatform external "" "aaa-bbb-ccc-ddd-eee" "Custom Platform") diff --git a/Tests/RunCMake/include_external_msproject/CustomTypePlatform.cmake b/Tests/RunCMake/include_external_msproject/CustomTypePlatform.cmake new file mode 100644 index 0000000..8c76adb --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/CustomTypePlatform.cmake @@ -0,0 +1,3 @@ +include_external_msproject(external external.project + TYPE aaa-bbb-ccc-ddd-eee + PLATFORM "Custom Platform") diff --git a/Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake b/Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake new file mode 100644 index 0000000..90710f9 --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake @@ -0,0 +1,6 @@ +include(RunCMake) +include(${CMAKE_CURRENT_LIST_DIR}/check_utils.cmake) + +run_cmake(CustomGuid) +run_cmake(CustomTypePlatform) +run_cmake(CustomGuidTypePlatform) diff --git a/Tests/RunCMake/include_external_msproject/check_utils.cmake b/Tests/RunCMake/include_external_msproject/check_utils.cmake new file mode 100644 index 0000000..7d6b8f8 --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/check_utils.cmake @@ -0,0 +1,109 @@ +# Check that file contains line that matches regular expression. +# Sets IS_FOUND variable to TRUE if found and to FALSE otherwise. +macro(check_line_exists TARGET_FILE REG_EXP_REF) + set(IS_FOUND "FALSE") + + file(STRINGS ${TARGET_FILE} FOUND_LINE LIMIT_COUNT 1 REGEX "${${REG_EXP_REF}}") + list(LENGTH FOUND_LINE _VAR_LEN) + + if(_VAR_LEN GREATER 0) + set(IS_FOUND "TRUE") + endif(_VAR_LEN GREATER 0) +endmacro(check_line_exists TARGET_FILE REG_EXP_REF) + +# Search and parse project section line by project name. +# If search was successful stores found type and guid into FOUND_TYPE and FOUND_GUID variables respectively. +# Sets IS_FOUND variable to TRUE if found and to FALSE otherwise. +macro(parse_project_section TARGET_FILE PROJECT_NAME) + set(REG_EXP "^Project\\(\\\"{(.+)}\\\"\\) = \\\"${PROJECT_NAME}\\\", \\\".+\\..+\\\", \\\"{(.+)}\\\"$") + + check_line_exists(${TARGET_FILE} REG_EXP) + if(NOT IS_FOUND) + return() + endif(NOT IS_FOUND) + + string(REGEX REPLACE "${REG_EXP}" "\\1;\\2" _GUIDS "${FOUND_LINE}") + + list(GET _GUIDS 0 FOUND_TYPE) + list(GET _GUIDS 1 FOUND_GUID) +endmacro(parse_project_section TARGET_FILE PROJECT_NAME) + +# Search project section line by project name and type. +# Returns TRUE if found and FALSE otherwise +function(check_project_type TARGET_FILE PROJECT_NAME PROJECT_TYPE RESULT) + set(${RESULT} "FALSE" PARENT_SCOPE) + + parse_project_section(${TARGET_FILE} ${PROJECT_NAME}) + if(IS_FOUND AND FOUND_TYPE STREQUAL PROJECT_TYPE) + set(${RESULT} "TRUE" PARENT_SCOPE) + endif(IS_FOUND AND FOUND_TYPE STREQUAL PROJECT_TYPE) +endfunction(check_project_type TARGET_FILE PROJECT_NAME PROJECT_TYPE RESULT) + + +# Search project section line by project name and id. +# Returns TRUE if found and FALSE otherwise +function(check_project_guid TARGET_FILE PROJECT_NAME PROJECT_GUID RESULT) + set(${RESULT} "FALSE" PARENT_SCOPE) + + parse_project_section(${TARGET_FILE} ${PROJECT_NAME}) + if(IS_FOUND AND FOUND_GUID STREQUAL PROJECT_GUID) + set(${RESULT} "TRUE" PARENT_SCOPE) + endif(IS_FOUND AND FOUND_GUID STREQUAL PROJECT_GUID) +endfunction(check_project_guid TARGET_FILE PROJECT_NAME PROJECT_GUID RESULT) + + +# Search project's build configuration line by project name and target platform name. +# Returns TRUE if found and FALSE otherwise +function(check_custom_platform TARGET_FILE PROJECT_NAME PLATFORM_NAME RESULT) + set(${RESULT} "FALSE" PARENT_SCOPE) + + # extract project guid + parse_project_section(${TARGET_FILE} ${PROJECT_NAME}) + if(NOT IS_FOUND) + return() + endif(NOT IS_FOUND) + + # probably whould be better to use configuration name + # extracted from CMAKE_CONFIGURATION_TYPES than just hardcoded "Debug" instead + set(REG_EXP "^(\t)*\\{${FOUND_GUID}\\}\\.Debug[^ ]*\\.ActiveCfg = Debug\\|${PLATFORM_NAME}$") + check_line_exists(${TARGET_FILE} REG_EXP) + + set(${RESULT} ${IS_FOUND} PARENT_SCOPE) +endfunction(check_custom_platform TARGET_FILE PLATFORM_NAME RESULT) + +# RunCMake test check helper +function(check_project test name guid type platform) + set(sln "${RunCMake_TEST_BINARY_DIR}/${test}.sln") + set(sep "") + set(failed "") + if(NOT type) + set(type 8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942) + endif() + if(NOT platform) + if("${RunCMake_GENERATOR}" MATCHES "Win64") + set(platform "x64") + else() + set(platform "Win32") + endif() + endif() + if(guid) + check_project_guid("${sln}" "${name}" "${guid}" passed_guid) + if(NOT passed_guid) + set(failed "${failed}${sep}${name} solution has no project with expected GUID=${guid}") + set(sep "\n") + endif() + else() + set(passed_guid 1) + endif() + check_project_type("${sln}" "${name}" "${type}" passed_type) + if(NOT passed_type) + set(failed "${failed}${sep}${name} solution has no project with expected TYPE=${type}") + set(sep "\n") + endif() + check_custom_platform("${sln}" "${name}" "${platform}" passed_platform) + if(NOT passed_platform) + set(failed "${failed}${sep}${name} solution has no project with expected PLATFORM=${platform}") + set(sep "\n") + endif() + set(RunCMake_TEST_FAILED "${failed}" PARENT_SCOPE) +endfunction() diff --git a/Tests/RunCMake/include_external_msproject/main.cpp b/Tests/RunCMake/include_external_msproject/main.cpp new file mode 100644 index 0000000..9198103 --- /dev/null +++ b/Tests/RunCMake/include_external_msproject/main.cpp @@ -0,0 +1,3 @@ +void main() +{ +} diff --git a/Tests/RunCMake/list/CMakeLists.txt b/Tests/RunCMake/list/CMakeLists.txt new file mode 100644 index 0000000..e8db6b0 --- /dev/null +++ b/Tests/RunCMake/list/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/list/EmptyGet0-result.txt b/Tests/RunCMake/list/EmptyGet0-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/list/EmptyGet0-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/list/EmptyGet0-stderr.txt b/Tests/RunCMake/list/EmptyGet0-stderr.txt new file mode 100644 index 0000000..0c61b01 --- /dev/null +++ b/Tests/RunCMake/list/EmptyGet0-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at EmptyGet0.cmake:2 \(list\): + list GET given empty list +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/list/EmptyGet0.cmake b/Tests/RunCMake/list/EmptyGet0.cmake new file mode 100644 index 0000000..4947108 --- /dev/null +++ b/Tests/RunCMake/list/EmptyGet0.cmake @@ -0,0 +1,2 @@ +set(mylist "") +list(GET mylist 0 result) diff --git a/Tests/RunCMake/list/EmptyInsert-1-result.txt b/Tests/RunCMake/list/EmptyInsert-1-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/list/EmptyInsert-1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/list/EmptyInsert-1-stderr.txt b/Tests/RunCMake/list/EmptyInsert-1-stderr.txt new file mode 100644 index 0000000..0900ff9 --- /dev/null +++ b/Tests/RunCMake/list/EmptyInsert-1-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at EmptyInsert-1.cmake:2 \(list\): + list index: -1 out of range \(0, 0\) +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/list/EmptyInsert-1.cmake b/Tests/RunCMake/list/EmptyInsert-1.cmake new file mode 100644 index 0000000..140da5d --- /dev/null +++ b/Tests/RunCMake/list/EmptyInsert-1.cmake @@ -0,0 +1,2 @@ +set(mylist "") +list(INSERT mylist -1 x) diff --git a/Tests/RunCMake/list/EmptyRemoveAt0-result.txt b/Tests/RunCMake/list/EmptyRemoveAt0-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/list/EmptyRemoveAt0-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt b/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt new file mode 100644 index 0000000..b24a0ed --- /dev/null +++ b/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at EmptyRemoveAt0.cmake:2 \(list\): + list REMOVE_AT given empty list +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/list/EmptyRemoveAt0.cmake b/Tests/RunCMake/list/EmptyRemoveAt0.cmake new file mode 100644 index 0000000..d6a3e85 --- /dev/null +++ b/Tests/RunCMake/list/EmptyRemoveAt0.cmake @@ -0,0 +1,2 @@ +set(mylist "") +list(REMOVE_AT mylist 0) diff --git a/Tests/RunCMake/list/RunCMakeTest.cmake b/Tests/RunCMake/list/RunCMakeTest.cmake new file mode 100644 index 0000000..555051d --- /dev/null +++ b/Tests/RunCMake/list/RunCMakeTest.cmake @@ -0,0 +1,5 @@ +include(RunCMake) + +run_cmake(EmptyGet0) +run_cmake(EmptyRemoveAt0) +run_cmake(EmptyInsert-1) |