summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-04-19 12:35:10 (GMT)
committerBrad King <brad.king@kitware.com>2012-04-19 12:35:55 (GMT)
commit4a30258d91818eb1c1d6741b5a47c54cbfab3313 (patch)
treeb0204bd2987752abb364dbf114eebef1ab6c49ef
parentf3191f5bc0db2d6717be20585c97f0f2346b8524 (diff)
downloadCMake-4a30258d91818eb1c1d6741b5a47c54cbfab3313.zip
CMake-4a30258d91818eb1c1d6741b5a47c54cbfab3313.tar.gz
CMake-4a30258d91818eb1c1d6741b5a47c54cbfab3313.tar.bz2
include_external_msproject: Test TYPE, GUID, PLATFORM options (#13120)
Add "RunCMake.include_external_msproject" test to use the TYPE, GUID, and PLATFORM options to include_external_msproject. Since projects with custom types and platforms cannot be loaded without special VS plugins validate the results by directly parsing the generated solution (.sln). Co-Author: Leonid Yurchenko <nocturne@qarea.com>
-rw-r--r--Tests/RunCMake/CMakeLists.txt4
-rw-r--r--Tests/RunCMake/include_external_msproject/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomGuid-check.cmake1
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomGuid.cmake2
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform-check.cmake1
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomGuidTypePlatform.cmake5
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomTypePlatform-check.cmake1
-rw-r--r--Tests/RunCMake/include_external_msproject/CustomTypePlatform.cmake3
-rw-r--r--Tests/RunCMake/include_external_msproject/RunCMakeTest.cmake6
-rw-r--r--Tests/RunCMake/include_external_msproject/check_utils.cmake109
-rw-r--r--Tests/RunCMake/include_external_msproject/main.cpp3
11 files changed, 138 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 488d469..4e1660c 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -49,3 +49,7 @@ add_RunCMake_test(ObjectLibrary)
add_RunCMake_test(build_command)
add_RunCMake_test(find_package)
+
+if("${CMAKE_TEST_GENERATOR}" MATCHES "Visual Studio [^6]")
+ add_RunCMake_test(include_external_msproject)
+endif()
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()
+{
+}