2002-01-20 05:24:55 +03:00
|
|
|
#
|
2012-08-13 21:42:58 +04:00
|
|
|
# Create exe.
|
2002-01-20 05:24:55 +03:00
|
|
|
#
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
|
2002-12-14 01:35:00 +03:00
|
|
|
|
2008-08-20 19:45:16 +04:00
|
|
|
# Create an imported target for if(TARGET) test below.
|
2012-08-13 21:47:32 +04:00
|
|
|
add_library(ExeImportedTarget UNKNOWN IMPORTED)
|
2008-08-20 19:45:16 +04:00
|
|
|
|
|
|
|
# Test if(TARGET) command.
|
2012-08-13 21:47:32 +04:00
|
|
|
if(NOT TARGET CMakeTestLibrary)
|
|
|
|
message(FATAL_ERROR "if(NOT TARGET CMakeTestLibrary) returned true!")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
if(NOT TARGET ExeImportedTarget)
|
|
|
|
message(FATAL_ERROR "if(NOT TARGET ExeImportedTarget) returned true!")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
if(TARGET LibImportedTarget)
|
|
|
|
message(FATAL_ERROR "if(TARGET LibImportedTarget) returned true!")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
if(TARGET NotATarget)
|
|
|
|
message(FATAL_ERROR "if(TARGET NotATarget) returned true!")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-08-20 19:45:16 +04:00
|
|
|
|
2015-01-22 22:11:46 +03:00
|
|
|
# Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
|
2012-08-13 21:47:32 +04:00
|
|
|
set(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
|
|
|
|
link_libraries(${COMPLEX_LIBS})
|
2001-08-23 21:57:45 +04:00
|
|
|
|
2007-11-19 22:27:43 +03:00
|
|
|
# Test forcing a .cxx file to not build.
|
2012-08-13 21:47:32 +04:00
|
|
|
set_source_files_properties(complex_nobuild.cxx PROPERTIES
|
2007-11-19 22:27:43 +03:00
|
|
|
HEADER_FILE_ONLY 1)
|
|
|
|
|
2010-12-20 23:25:16 +03:00
|
|
|
# Test forcing a .c file to not build.
|
|
|
|
# This makes sure a mixed language library is created
|
|
|
|
# with header file only sources
|
2012-08-13 21:47:32 +04:00
|
|
|
set_source_files_properties(complex_nobuild.c PROPERTIES
|
2010-12-20 23:25:16 +03:00
|
|
|
HEADER_FILE_ONLY 1)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
add_executable(A A.cxx A.hh A.h A.txt)
|
|
|
|
add_custom_command(OUTPUT Aout.h COMMAND A > Aout.h VERBATIM)
|
|
|
|
add_executable(complex complex testcflags.c Aout.h)
|
2006-04-18 02:10:16 +04:00
|
|
|
# Sub1/NameConflictTest.c Sub2/NameConflictTest.c)
|
2012-08-13 21:47:32 +04:00
|
|
|
add_executable(complex.file complex.file.cxx complex_nobuild.cxx
|
2010-12-20 23:25:16 +03:00
|
|
|
complex_nobuild.c)
|
2006-01-17 18:21:45 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if (UNIX)
|
|
|
|
target_link_libraries(complex ${CMAKE_DL_LIBS})
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
if (NOT BORLAND)
|
|
|
|
if(NOT MINGW)
|
|
|
|
target_link_libraries(complex rpcrt4.lib)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif ()
|
2002-08-22 23:58:22 +04:00
|
|
|
|
2006-09-15 22:31:24 +04:00
|
|
|
# Test linking to static lib when a shared lib has the same name.
|
2012-08-13 21:47:32 +04:00
|
|
|
if(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
|
|
|
|
add_definitions(-DCOMPLEX_TEST_LINK_STATIC)
|
|
|
|
target_link_libraries(complex CMakeTestLinkStatic)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2006-09-15 22:31:24 +04:00
|
|
|
|
2006-03-22 23:01:22 +03:00
|
|
|
# can we get the path to a source file
|
2012-08-13 21:47:32 +04:00
|
|
|
get_source_file_property(A_LOCATION A.cxx LOCATION)
|
|
|
|
if ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx")
|
|
|
|
add_definitions(-DCMAKE_FOUND_ACXX)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif ()
|
2006-03-22 23:01:22 +03:00
|
|
|
|
|
|
|
# get the directory parent
|
2012-08-13 21:47:32 +04:00
|
|
|
get_directory_property(P_VALUE PARENT_DIRECTORY)
|
|
|
|
if ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}")
|
|
|
|
add_definitions(-DCMAKE_FOUND_PARENT)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif ()
|
2006-03-22 23:01:22 +03:00
|
|
|
|
|
|
|
# get the stack of listfiles
|
2012-08-13 21:47:32 +04:00
|
|
|
include(Included.cmake)
|
|
|
|
if ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")
|
|
|
|
add_definitions(-DCMAKE_FOUND_LISTFILE_STACK)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif ()
|
2006-03-22 23:01:22 +03:00
|
|
|
|
2006-05-23 20:51:26 +04:00
|
|
|
# Test add/remove definitions.
|
2012-08-13 21:47:32 +04:00
|
|
|
add_definitions(
|
2006-05-23 20:51:26 +04:00
|
|
|
-DCOMPLEX_DEFINED_PRE
|
|
|
|
-DCOMPLEX_DEFINED
|
|
|
|
-DCOMPLEX_DEFINED_POST
|
|
|
|
-DCOMPLEX_DEFINED
|
|
|
|
)
|
2012-08-13 21:47:32 +04:00
|
|
|
remove_definitions(-DCOMPLEX_DEFINED)
|
2006-03-22 23:01:22 +03:00
|
|
|
|
2005-02-25 17:31:55 +03:00
|
|
|
# Test pre-build/pre-link/post-build rules for an executable.
|
2012-08-13 21:47:32 +04:00
|
|
|
add_custom_command(TARGET complex PRE_BUILD
|
2005-02-25 17:31:55 +03:00
|
|
|
COMMAND ${CREATE_FILE_EXE}
|
2014-12-27 07:19:14 +03:00
|
|
|
ARGS "Executable/prebuild.txt"
|
|
|
|
WORKING_DIRECTORY "${Complex_BINARY_DIR}")
|
2013-03-05 00:21:41 +04:00
|
|
|
add_custom_command(TARGET complex PRE_LINK
|
2005-02-25 17:31:55 +03:00
|
|
|
COMMAND ${CREATE_FILE_EXE}
|
2014-12-27 07:19:14 +03:00
|
|
|
ARGS "Executable/prelink.txt"
|
|
|
|
WORKING_DIRECTORY "${Complex_BINARY_DIR}")
|
2012-08-13 21:47:32 +04:00
|
|
|
add_custom_command(TARGET complex POST_BUILD
|
2005-02-25 17:31:55 +03:00
|
|
|
COMMAND ${CREATE_FILE_EXE}
|
2014-12-27 07:19:14 +03:00
|
|
|
ARGS "Executable/postbuild.txt"
|
|
|
|
WORKING_DIRECTORY "${Complex_BINARY_DIR}")
|
2012-08-13 21:47:32 +04:00
|
|
|
add_custom_command(TARGET complex POST_BUILD
|
2005-02-25 17:31:55 +03:00
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
ARGS -E copy
|
2014-12-27 07:19:14 +03:00
|
|
|
"Executable/postbuild.txt"
|
|
|
|
"Executable/postbuild2.txt"
|
|
|
|
WORKING_DIRECTORY "${Complex_BINARY_DIR}")
|
2005-02-25 17:31:55 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
set_source_files_properties(complex
|
2007-05-09 18:18:31 +04:00
|
|
|
COMPILE_FLAGS
|
2007-05-16 19:40:53 +04:00
|
|
|
"-DFILE_HAS_EXTRA_COMPILE_FLAGS"
|
|
|
|
#" -DFILE_DEFINE_STRING=\\\"hello\\\""
|
2002-12-14 01:35:00 +03:00
|
|
|
OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
|
|
|
|
)
|
2012-08-13 21:47:32 +04:00
|
|
|
set_target_properties(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
|
|
|
|
add_custom_command(
|
2002-12-14 01:35:00 +03:00
|
|
|
TARGET complex
|
|
|
|
SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
|
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
ARGS -E copy ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
|
|
|
|
${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
|
|
|
|
OUTPUTS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
|
|
|
|
DEPENDS ${CMAKE_COMMAND}
|
|
|
|
)
|
|
|
|
|
2006-10-02 19:14:00 +04:00
|
|
|
# Test creating an executable that is not built by default.
|
2012-08-13 21:47:32 +04:00
|
|
|
add_executable(notInAllExe EXCLUDE_FROM_ALL notInAllExe.cxx)
|
|
|
|
target_link_libraries(notInAllExe notInAllLib)
|
2006-10-02 19:14:00 +04:00
|
|
|
|
2007-02-01 20:02:24 +03:00
|
|
|
# Test user-value flag mapping for the VS IDE.
|
2012-08-13 21:47:32 +04:00
|
|
|
if(MSVC)
|
|
|
|
set_target_properties(notInAllExe PROPERTIES
|
2007-02-01 20:02:24 +03:00
|
|
|
LINK_FLAGS "/NODEFAULTLIB:LIBC;LIBCMT;MSVCRT")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2007-02-01 20:02:24 +03:00
|
|
|
|
2006-10-02 19:14:00 +04:00
|
|
|
# Test creating a custom target that builds not-in-all targets.
|
2012-08-13 21:47:32 +04:00
|
|
|
add_custom_target(notInAllCustom)
|
|
|
|
add_dependencies(notInAllCustom notInAllExe)
|
2006-10-02 19:14:00 +04:00
|
|
|
|
2002-01-20 08:12:27 +03:00
|
|
|
#
|
|
|
|
# Output the files required by 'complex' to a file.
|
|
|
|
#
|
2002-01-22 21:30:06 +03:00
|
|
|
# This test has been moved to the 'required' subdir so that it
|
|
|
|
# has no side-effects on the current Makefile (duplicated source file
|
|
|
|
# due to source list expansion done twice).
|
|
|
|
#
|
2012-08-13 21:47:32 +04:00
|
|
|
add_subdirectory(Temp)
|
2002-01-20 08:12:27 +03:00
|
|
|
|
2016-02-08 14:48:35 +03:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_INCLUDE_SYSTEM_FLAG_CXX
|
|
|
|
AND NOT XCODE) # XCODE is excluded due to #15687
|
2012-08-13 21:47:32 +04:00
|
|
|
add_executable(testSystemDir testSystemDir.cxx)
|
|
|
|
set_target_properties(testSystemDir PROPERTIES COMPILE_FLAGS "-Werror")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2006-10-05 16:55:59 +04:00
|
|
|
|
2002-01-19 04:32:06 +03:00
|
|
|
#
|
2002-01-20 05:24:55 +03:00
|
|
|
# Extra coverage.Not used.
|
2002-01-19 04:32:06 +03:00
|
|
|
#
|
2012-08-13 21:47:32 +04:00
|
|
|
install_targets(/tmp complex)
|
|
|
|
install_programs(/tmp complex)
|
2002-01-20 05:24:55 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
configure_file(
|
2002-04-22 19:51:26 +04:00
|
|
|
${Complex_SOURCE_DIR}/Executable/cmVersion.h.in
|
|
|
|
${Complex_BINARY_DIR}/cmVersion.h)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
source_group(A_GROUP ".cxx")
|
|
|
|
source_group(B_GROUP REGULAR_EXPRESSION "cxx")
|
|
|
|
source_group(C_GROUP FILES complex.cxx)
|
2003-08-08 00:07:23 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
file(WRITE ${Complex_BINARY_DIR}/A/libA.a "test")
|
|
|
|
file(WRITE ${Complex_BINARY_DIR}/A/libC.a "test")
|
|
|
|
file(WRITE ${Complex_BINARY_DIR}/B/libB.a "test")
|
|
|
|
file(WRITE ${Complex_BINARY_DIR}/B/libA.a "test")
|
|
|
|
file(WRITE ${Complex_BINARY_DIR}/C/libC.a "test")
|
|
|
|
file(WRITE ${Complex_BINARY_DIR}/C/libB.a "test")
|