summaryrefslogtreecommitdiff
path: root/Tests/BuildDepends
diff options
context:
space:
mode:
authorMyungJoo Ham <myungjoo.ham@samsung.com>2017-10-11 15:16:57 +0900
committerMyungJoo Ham <myungjoo.ham@samsung.com>2017-10-11 15:16:57 +0900
commit915c76ded744c0f5f151402b9fa69f3fd8452573 (patch)
treeca6a387466543248890f346847acaa8343989b22 /Tests/BuildDepends
parent317dbdb79761ef65e45c7358cfc7571c6afa54ad (diff)
downloadcmake-915c76ded744c0f5f151402b9fa69f3fd8452573.tar.gz
cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.tar.bz2
cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.zip
Imported Upstream version 3.9.4upstream/3.9.4
Diffstat (limited to 'Tests/BuildDepends')
-rw-r--r--Tests/BuildDepends/CMakeLists.txt158
-rw-r--r--Tests/BuildDepends/Project/CMakeLists.txt55
-rw-r--r--Tests/BuildDepends/Project/External/CMakeLists.txt14
-rw-r--r--Tests/BuildDepends/Project/bar.cxx15
-rw-r--r--Tests/BuildDepends/Project/generator.cxx17
-rw-r--r--Tests/BuildDepends/Project/link_depends_no_shared_exe.c2
-rw-r--r--Tests/BuildDepends/Project/link_depends_no_shared_lib.c2
-rw-r--r--Tests/BuildDepends/Project/ninjadep.cpp5
-rw-r--r--Tests/BuildDepends/Project/object_depends.cxx4
-rw-r--r--Tests/BuildDepends/Project/object_depends_check.cmake7
-rw-r--r--Tests/BuildDepends/Project/zot.cxx6
11 files changed, 244 insertions, 41 deletions
diff --git a/Tests/BuildDepends/CMakeLists.txt b/Tests/BuildDepends/CMakeLists.txt
index 06871543f..11978dbf8 100644
--- a/Tests/BuildDepends/CMakeLists.txt
+++ b/Tests/BuildDepends/CMakeLists.txt
@@ -13,7 +13,7 @@ project(BuildDepends)
set(CMAKE_SUPPRESS_REGENERATION 1)
# Xcode needs some help with the fancy dependencies in this test.
-if("${CMAKE_GENERATOR}" MATCHES "Xcode")
+if(XCODE AND XCODE_VERSION VERSION_LESS 5)
set(HELP_XCODE 1)
endif()
function(help_xcode_depends)
@@ -28,17 +28,13 @@ function(help_xcode_depends)
endif()
endfunction()
-if("${CMAKE_GENERATOR}" MATCHES "Ninja")
- set(HELP_NINJA 1) # TODO Why is this needed?
-endif()
-
# The Intel compiler causes the MSVC linker to crash during
# incremental linking, so avoid the /INCREMENTAL:YES flag.
if(WIN32 AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
set(_cmake_options "-DCMAKE_EXE_LINKER_FLAGS=")
endif()
-if("${CMAKE_GENERATOR}" MATCHES "Make")
+if("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
set(TEST_LINK_DEPENDS ${BuildDepends_BINARY_DIR}/Project/linkdep.txt)
file(WRITE ${TEST_LINK_DEPENDS} "1")
endif()
@@ -46,6 +42,11 @@ list(APPEND _cmake_options "-DTEST_LINK_DEPENDS=${TEST_LINK_DEPENDS}")
list(APPEND _cmake_options "-DCMAKE_FORCE_DEPFILES=1")
+if(NOT CMAKE_GENERATOR MATCHES "Visual Studio ([^89]|[89][0-9])")
+ set(TEST_MULTI3 1)
+ list(APPEND _cmake_options "-DTEST_MULTI3=1")
+endif()
+
file(MAKE_DIRECTORY ${BuildDepends_BINARY_DIR}/Project)
message("Creating Project/foo.cxx")
write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
@@ -68,6 +69,14 @@ file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_exe.h
"#define link_depends_no_shared_exe_value 0\n")
set(link_depends_no_shared_check_txt ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_check.txt)
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/object_depends.txt "0\n")
+set(object_depends_check_txt ${BuildDepends_BINARY_DIR}/Project/object_depends_check.txt)
+
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/external.in "external original\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/multi1-in.txt "multi1-in original\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/multi2-stamp.txt "multi2-stamp original\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/multi3-stamp.txt "multi3-stamp original\n")
+
help_xcode_depends()
message("Building project first time")
@@ -166,9 +175,62 @@ else()
"Targets link_depends_no_shared_lib and link_depends_no_shared_exe not both built.")
endif()
+if(EXISTS ${BuildDepends_BINARY_DIR}/Project/external.out)
+ file(STRINGS ${BuildDepends_BINARY_DIR}/Project/external.out external_out)
+ if("${external_out}" STREQUAL "external original")
+ message(STATUS "external.out contains '${external_out}'")
+ else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "external.out contains '${external_out}'")
+ endif()
+else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "external.out is missing")
+endif()
+
+if(EXISTS ${BuildDepends_BINARY_DIR}/Project/multi1-out2-copy.txt)
+ file(STRINGS ${BuildDepends_BINARY_DIR}/Project/multi1-out2-copy.txt multi1_out)
+ if("${multi1_out}" STREQUAL "multi1-in original")
+ message(STATUS "multi1-out2-copy.txt contains '${multi1_out}'")
+ else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "multi1-out2-copy.txt contains '${multi1_out}'")
+ endif()
+else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "multi1-out2-copy.txt is missing")
+endif()
+
+if(EXISTS ${BuildDepends_BINARY_DIR}/Project/multi2-real.txt)
+ if(${BuildDepends_BINARY_DIR}/Project/multi2-real.txt
+ IS_NEWER_THAN ${BuildDepends_BINARY_DIR}/Project/multi2-stamp.txt)
+ message(STATUS "multi2-real.txt is newer than multi2-stamp.txt")
+ else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "multi2-real.txt is not newer than multi2-stamp.txt")
+ endif()
+else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "multi2-real.txt is missing")
+endif()
+
+if(TEST_MULTI3)
+ if(EXISTS ${BuildDepends_BINARY_DIR}/Project/multi3-real.txt)
+ if(${BuildDepends_BINARY_DIR}/Project/multi3-real.txt
+ IS_NEWER_THAN ${BuildDepends_BINARY_DIR}/Project/multi3-stamp.txt)
+ message(STATUS "multi3-real.txt is newer than multi3-stamp.txt")
+ else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "multi3-real.txt is not newer than multi3-stamp.txt")
+ endif()
+ else()
+ message(SEND_ERROR "Project did not initially build properly: "
+ "multi3-real.txt is missing")
+ endif()
+endif()
+
message("Waiting 3 seconds...")
-# any additional argument will cause ${bar} to wait forever
-execute_process(COMMAND ${bar} -infinite TIMEOUT 3 OUTPUT_VARIABLE out)
+execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 3)
message("Modifying Project/foo.cxx")
write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx
@@ -187,10 +249,17 @@ file(WRITE ${BuildDepends_BINARY_DIR}/Project/zot_macro_tgt.hxx
file(WRITE ${BuildDepends_BINARY_DIR}/Project/link_depends_no_shared_lib.h
"#define link_depends_no_shared_lib_value 0\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/object_depends.txt "1\n")
+
if(TEST_LINK_DEPENDS)
file(WRITE ${TEST_LINK_DEPENDS} "2")
endif()
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/external.in "external changed\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/multi1-in.txt "multi1-in changed\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/multi2-stamp.txt "multi2-stamp changed\n")
+file(WRITE ${BuildDepends_BINARY_DIR}/Project/multi3-stamp.txt "multi3-stamp changed\n")
+
help_xcode_depends()
message("Building project second time")
@@ -202,7 +271,7 @@ try_compile(RESULT
OUTPUT_VARIABLE OUTPUT)
# Xcode is in serious need of help here
-if(HELP_XCODE OR HELP_NINJA)
+if(HELP_XCODE)
try_compile(RESULT
${BuildDepends_BINARY_DIR}/Project
${BuildDepends_SOURCE_DIR}/Project
@@ -235,9 +304,6 @@ message("Run result: ${runResult} Output: \"${out}\"")
if("${out}" STREQUAL "HEADER_STRING: ninja changed ")
message("Worked!")
-elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 6")
- # Tolerate failure because VS 6 does not seem to recompile ninjadep.cpp
- # when the "dir/header.h" it includes changes.
else()
message(SEND_ERROR "Project did not rebuild properly. Output[${out}]\n"
" expected [HEADER_STRING: ninja changed]")
@@ -294,3 +360,71 @@ else()
message(SEND_ERROR "Project did not rebuild properly. "
"Targets link_depends_no_shared_lib and link_depends_no_shared_exe not both built.")
endif()
+
+if(EXISTS "${object_depends_check_txt}")
+ file(STRINGS "${object_depends_check_txt}" object_depends_check LIMIT_COUNT 1)
+ if("${object_depends_check}" STREQUAL "1")
+ message(STATUS "object_depends exe is newer than object_depends.txt as expected.")
+ elseif(CMAKE_GENERATOR MATCHES "Visual Studio|Xcode")
+ message(STATUS "Known limitation: OBJECT_DEPENDS does not work on ${CMAKE_GENERATOR}")
+ else()
+ message(SEND_ERROR "Project did not rebuild properly: object_depends exe is not newer than object_depends.txt.")
+ endif()
+else()
+ message(SEND_ERROR "Project did not rebuild properly. "
+ "object_depends exe and object_depends.txt are not both present.")
+endif()
+
+if(EXISTS ${BuildDepends_BINARY_DIR}/Project/external.out)
+ file(STRINGS ${BuildDepends_BINARY_DIR}/Project/external.out external_out)
+ if("${external_out}" STREQUAL "external changed")
+ message(STATUS "external.out contains '${external_out}'")
+ else()
+ message(SEND_ERROR "Project did not rebuild properly: "
+ "external.out contains '${external_out}'")
+ endif()
+else()
+ message(SEND_ERROR "Project did not rebuild properly: "
+ "external.out is missing")
+endif()
+
+if(EXISTS ${BuildDepends_BINARY_DIR}/Project/multi1-out2-copy.txt)
+ file(STRINGS ${BuildDepends_BINARY_DIR}/Project/multi1-out2-copy.txt multi1_out)
+ if("${multi1_out}" STREQUAL "multi1-in changed")
+ message(STATUS "multi1-out2-copy.txt contains '${multi1_out}'")
+ else()
+ message(SEND_ERROR "Project did not rebuild properly: "
+ "multi1-out2-copy.txt contains '${multi1_out}'")
+ endif()
+else()
+ message(SEND_ERROR "Project did not rebuild properly: "
+ "multi1-out2-copy.txt is missing")
+endif()
+
+if(EXISTS ${BuildDepends_BINARY_DIR}/Project/multi2-real.txt)
+ if(${BuildDepends_BINARY_DIR}/Project/multi2-real.txt
+ IS_NEWER_THAN ${BuildDepends_BINARY_DIR}/Project/multi2-stamp.txt)
+ message(STATUS "multi2-real.txt is newer than multi2-stamp.txt")
+ else()
+ message(SEND_ERROR "Project did not rebuild properly: "
+ "multi2-real.txt is not newer than multi2-stamp.txt")
+ endif()
+else()
+ message(SEND_ERROR "Project did not rebuild properly: "
+ "multi2-real.txt is missing")
+endif()
+
+if(TEST_MULTI3)
+ if(EXISTS ${BuildDepends_BINARY_DIR}/Project/multi3-real.txt)
+ if(${BuildDepends_BINARY_DIR}/Project/multi3-real.txt
+ IS_NEWER_THAN ${BuildDepends_BINARY_DIR}/Project/multi3-stamp.txt)
+ message(STATUS "multi3-real.txt is newer than multi3-stamp.txt")
+ else()
+ message(SEND_ERROR "Project did not rebuild properly: "
+ "multi3-real.txt is not newer than multi3-stamp.txt")
+ endif()
+ else()
+ message(SEND_ERROR "Project did not rebuild properly: "
+ "multi3-real.txt is missing")
+ endif()
+endif()
diff --git a/Tests/BuildDepends/Project/CMakeLists.txt b/Tests/BuildDepends/Project/CMakeLists.txt
index 8806ecdf1..3aa57fc9e 100644
--- a/Tests/BuildDepends/Project/CMakeLists.txt
+++ b/Tests/BuildDepends/Project/CMakeLists.txt
@@ -139,3 +139,58 @@ add_custom_target(header_tgt DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/dir/header.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(ninjadep ninjadep.cpp)
add_dependencies(ninjadep header_tgt)
+
+include(ExternalProject)
+ExternalProject_Add(ExternalBuild
+ SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/External
+ BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/External
+ STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/External/Stamp
+ BUILD_ALWAYS 1
+ CMAKE_ARGS
+ -Dexternal_in=${CMAKE_CURRENT_BINARY_DIR}/external.in
+ -Dexternal_out=${CMAKE_CURRENT_BINARY_DIR}/external.out
+ INSTALL_COMMAND ""
+ )
+
+add_custom_command(
+ OUTPUT multi1-out1.txt multi1-out2.txt
+ COMMAND ${CMAKE_COMMAND} -E copy multi1-in.txt multi1-out1.txt
+ COMMAND ${CMAKE_COMMAND} -E copy multi1-in.txt multi1-out2.txt
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/multi1-in.txt
+ )
+add_custom_command(
+ OUTPUT multi1-out2-copy.txt
+ COMMAND ${CMAKE_COMMAND} -E copy multi1-out2.txt multi1-out2-copy.txt
+ DEPENDS multi1-out2.txt
+ )
+add_custom_target(multi1 ALL DEPENDS multi1-out2-copy.txt)
+
+# Test having the first output never created.
+add_custom_command(
+ OUTPUT multi2-dummy.txt multi2-real.txt
+ COMMAND ${CMAKE_COMMAND} -E touch multi2-real.txt
+ )
+set_property(SOURCE multi2-real.txt multi2-dummy.txt PROPERTY SYMBOLIC 1)
+add_custom_target(multi2 ALL DEPENDS multi2-real.txt)
+
+if(TEST_MULTI3)
+ # Test having the second output never created. Does not work with msbuild.
+ add_custom_command(
+ OUTPUT multi3-real.txt multi3-dummy.txt
+ COMMAND ${CMAKE_COMMAND} -E touch multi3-real.txt
+ )
+ set_property(SOURCE multi3-real.txt multi3-dummy.txt PROPERTY SYMBOLIC 1)
+ add_custom_target(multi3 ALL DEPENDS multi3-real.txt)
+endif()
+
+add_executable(object_depends object_depends.cxx)
+set_property(SOURCE object_depends.cxx PROPERTY OBJECT_DEPENDS
+ ${CMAKE_CURRENT_BINARY_DIR}/object_depends.txt)
+add_custom_target(object_depends_check ALL
+ COMMAND ${CMAKE_COMMAND}
+ -Dexe=$<TARGET_FILE:object_depends>
+ -Dout=${CMAKE_CURRENT_BINARY_DIR}/object_depends_check.txt
+ -Dtxt=${CMAKE_CURRENT_BINARY_DIR}/object_depends.txt
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/object_depends_check.cmake
+ )
+add_dependencies(object_depends_check object_depends)
diff --git a/Tests/BuildDepends/Project/External/CMakeLists.txt b/Tests/BuildDepends/Project/External/CMakeLists.txt
new file mode 100644
index 000000000..c6015b651
--- /dev/null
+++ b/Tests/BuildDepends/Project/External/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.0)
+project(BuildDependsExternal NONE)
+if(NOT DEFINED external_in)
+ message(FATAL_ERROR "Define external_in")
+endif()
+if(NOT DEFINED external_out)
+ message(FATAL_ERROR "Define external_out")
+endif()
+add_custom_command(
+ OUTPUT ${external_out}
+ COMMAND ${CMAKE_COMMAND} -E copy ${external_in} ${external_out}
+ DEPENDS ${external_in}
+ )
+add_custom_target(drive ALL DEPENDS ${external_out})
diff --git a/Tests/BuildDepends/Project/bar.cxx b/Tests/BuildDepends/Project/bar.cxx
index 25d8bd21b..ec7aa65e2 100644
--- a/Tests/BuildDepends/Project/bar.cxx
+++ b/Tests/BuildDepends/Project/bar.cxx
@@ -1,25 +1,18 @@
+#include <noregen.h>
+#include <regen.h>
#include <stdio.h>
#include <string.h>
-#include <regen.h>
-#include <noregen.h>
int main(int argc, char** argv)
{
/* Make sure the noregen header was not regenerated. */
- if(strcmp("foo", noregen_string) != 0)
- {
+ if (strcmp("foo", noregen_string) != 0) {
printf("FAILED: noregen.h was regenerated!\n");
return 1;
- }
+ }
/* Print out the string that should have been regenerated. */
printf("%s\n", regen_string);
fflush(stdout);
- // if any argument is used, wait forever
- if (argc>1)
- {
- // wait that we get killed...
- for(;;);
- }
return 0;
}
diff --git a/Tests/BuildDepends/Project/generator.cxx b/Tests/BuildDepends/Project/generator.cxx
index 92a122de8..5a83a7f88 100644
--- a/Tests/BuildDepends/Project/generator.cxx
+++ b/Tests/BuildDepends/Project/generator.cxx
@@ -4,21 +4,16 @@ extern const char* foo();
int main(int argc, const char* argv[])
{
- if(argc < 3)
- {
+ if (argc < 3) {
fprintf(stderr, "Must specify output file and symbol prefix!");
return 1;
- }
- if(FILE* fout = fopen(argv[1], "w"))
- {
- fprintf(fout, "static const char* %s_string = \"%s\";\n", argv[2],
- foo());
+ }
+ if (FILE* fout = fopen(argv[1], "w")) {
+ fprintf(fout, "static const char* %s_string = \"%s\";\n", argv[2], foo());
fclose(fout);
- }
- else
- {
+ } else {
fprintf(stderr, "Could not open output file \"%s\"", argv[1]);
return 1;
- }
+ }
return 0;
}
diff --git a/Tests/BuildDepends/Project/link_depends_no_shared_exe.c b/Tests/BuildDepends/Project/link_depends_no_shared_exe.c
index e9113a21d..cfaf05135 100644
--- a/Tests/BuildDepends/Project/link_depends_no_shared_exe.c
+++ b/Tests/BuildDepends/Project/link_depends_no_shared_exe.c
@@ -2,7 +2,7 @@
#ifdef _WIN32
__declspec(dllimport)
#endif
-int link_depends_no_shared_lib(void);
+ int link_depends_no_shared_lib(void);
int main()
{
return link_depends_no_shared_lib() + link_depends_no_shared_exe_value;
diff --git a/Tests/BuildDepends/Project/link_depends_no_shared_lib.c b/Tests/BuildDepends/Project/link_depends_no_shared_lib.c
index d2262894b..d66c63694 100644
--- a/Tests/BuildDepends/Project/link_depends_no_shared_lib.c
+++ b/Tests/BuildDepends/Project/link_depends_no_shared_lib.c
@@ -2,7 +2,7 @@
#ifdef _WIN32
__declspec(dllexport)
#endif
-int link_depends_no_shared_lib(void)
+ int link_depends_no_shared_lib(void)
{
return link_depends_no_shared_lib_value;
}
diff --git a/Tests/BuildDepends/Project/ninjadep.cpp b/Tests/BuildDepends/Project/ninjadep.cpp
index 8d6133613..e794448f2 100644
--- a/Tests/BuildDepends/Project/ninjadep.cpp
+++ b/Tests/BuildDepends/Project/ninjadep.cpp
@@ -1,6 +1,7 @@
-#include <stdio.h>
#include "dir/header.h"
+#include <stdio.h>
-int main() {
+int main()
+{
printf("HEADER_STRING: %s\n", HEADER_STRING);
}
diff --git a/Tests/BuildDepends/Project/object_depends.cxx b/Tests/BuildDepends/Project/object_depends.cxx
new file mode 100644
index 000000000..f8b643afb
--- /dev/null
+++ b/Tests/BuildDepends/Project/object_depends.cxx
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
diff --git a/Tests/BuildDepends/Project/object_depends_check.cmake b/Tests/BuildDepends/Project/object_depends_check.cmake
new file mode 100644
index 000000000..e00989288
--- /dev/null
+++ b/Tests/BuildDepends/Project/object_depends_check.cmake
@@ -0,0 +1,7 @@
+if(NOT EXISTS "${txt}" OR NOT EXISTS "${exe}")
+ file(REMOVE "${out}")
+elseif("${exe}" IS_NEWER_THAN "${txt}")
+ file(WRITE "${out}" "1\n")
+else()
+ file(WRITE "${out}" "0\n")
+endif()
diff --git a/Tests/BuildDepends/Project/zot.cxx b/Tests/BuildDepends/Project/zot.cxx
index 775fd3b43..faee7d3ce 100644
--- a/Tests/BuildDepends/Project/zot.cxx
+++ b/Tests/BuildDepends/Project/zot.cxx
@@ -1,14 +1,14 @@
+#include <stdio.h>
#include <zot.hxx>
#include <zot_custom.hxx>
-#include <stdio.h>
const char* zot_macro_dir_f();
const char* zot_macro_tgt_f();
int main()
{
- printf("[%s] [%s] [%s] [%s]\n", zot, zot_custom,
- zot_macro_dir_f(), zot_macro_tgt_f());
+ printf("[%s] [%s] [%s] [%s]\n", zot, zot_custom, zot_macro_dir_f(),
+ zot_macro_tgt_f());
fflush(stdout);
return 0;
}