CMakeLists.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. CMAKE_MINIMUM_REQUIRED(VERSION 1.3)
  2. #
  3. # Create exe.
  4. #
  5. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
  6. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
  7. SET(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
  8. IF(COMPLEX_TEST_CMAKELIB)
  9. # Link to CMake lib
  10. LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
  11. LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source/kwsys)
  12. LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmexpat)
  13. LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmzlib)
  14. IF(CMAKE_USE_NEW_CURL)
  15. LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0)
  16. ELSE(CMAKE_USE_NEW_CURL)
  17. LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmcurl)
  18. ENDIF(CMAKE_USE_NEW_CURL)
  19. LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmtar)
  20. ENDIF(COMPLEX_TEST_CMAKELIB)
  21. # Create an imported target for if(TARGET) test below.
  22. ADD_LIBRARY(ExeImportedTarget UNKNOWN IMPORTED)
  23. # Test if(TARGET) command.
  24. IF(NOT TARGET CMakeTestLibrary)
  25. MESSAGE(FATAL_ERROR "IF(NOT TARGET CMakeTestLibrary) returned true!")
  26. ENDIF(NOT TARGET CMakeTestLibrary)
  27. IF(NOT TARGET ExeImportedTarget)
  28. MESSAGE(FATAL_ERROR "IF(NOT TARGET ExeImportedTarget) returned true!")
  29. ENDIF(NOT TARGET ExeImportedTarget)
  30. IF(TARGET LibImportedTarget)
  31. MESSAGE(FATAL_ERROR "IF(TARGET LibImportedTarget) returned true!")
  32. ENDIF(TARGET LibImportedTarget)
  33. IF(TARGET NotATarget)
  34. MESSAGE(FATAL_ERROR "IF(TARGET NotATarget) returned true!")
  35. ENDIF(TARGET NotATarget)
  36. # Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
  37. SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
  38. LINK_LIBRARIES(${COMPLEX_LIBS})
  39. # Test forcing a .cxx file to not build.
  40. SET_SOURCE_FILES_PROPERTIES(complex_nobuild.cxx PROPERTIES
  41. HEADER_FILE_ONLY 1)
  42. ADD_EXECUTABLE(A A.cxx A.hh A.h A.txt)
  43. ADD_EXECUTABLE(complex complex testcflags.c )
  44. # Sub1/NameConflictTest.c Sub2/NameConflictTest.c)
  45. ADD_EXECUTABLE(complex.file complex.file.cxx complex_nobuild.cxx)
  46. IF(COMPLEX_TEST_CMAKELIB)
  47. TARGET_LINK_LIBRARIES(complex CMakeLib cmsys cmexpat cmzlib cmtar cmcurl)
  48. ENDIF(COMPLEX_TEST_CMAKELIB)
  49. IF (UNIX)
  50. TARGET_LINK_LIBRARIES(complex ${CMAKE_DL_LIBS})
  51. ELSE(UNIX)
  52. IF (NOT BORLAND)
  53. IF(NOT MINGW)
  54. TARGET_LINK_LIBRARIES(complex rpcrt4.lib)
  55. ENDIF(NOT MINGW)
  56. ENDIF(NOT BORLAND)
  57. ENDIF (UNIX)
  58. # Test linking to static lib when a shared lib has the same name.
  59. IF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
  60. ADD_DEFINITIONS(-DCOMPLEX_TEST_LINK_STATIC)
  61. TARGET_LINK_LIBRARIES(complex CMakeTestLinkStatic)
  62. ENDIF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
  63. # can we get the path to a source file
  64. GET_SOURCE_FILE_PROPERTY(A_LOCATION A.cxx LOCATION)
  65. IF ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx")
  66. ADD_DEFINITIONS(-DCMAKE_FOUND_ACXX)
  67. ENDIF ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx")
  68. # get the directory parent
  69. GET_DIRECTORY_PROPERTY(P_VALUE PARENT_DIRECTORY)
  70. IF ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}")
  71. ADD_DEFINITIONS(-DCMAKE_FOUND_PARENT)
  72. ENDIF ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}")
  73. # get the stack of listfiles
  74. INCLUDE(Included.cmake)
  75. IF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")
  76. ADD_DEFINITIONS(-DCMAKE_FOUND_LISTFILE_STACK)
  77. ENDIF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")
  78. # Test add/remove definitions.
  79. ADD_DEFINITIONS(
  80. -DCOMPLEX_DEFINED_PRE
  81. -DCOMPLEX_DEFINED
  82. -DCOMPLEX_DEFINED_POST
  83. -DCOMPLEX_DEFINED
  84. )
  85. REMOVE_DEFINITIONS(-DCOMPLEX_DEFINED)
  86. # Test pre-build/pre-link/post-build rules for an executable.
  87. ADD_CUSTOM_COMMAND(TARGET complex PRE_BUILD
  88. COMMAND ${CREATE_FILE_EXE}
  89. ARGS "${Complex_BINARY_DIR}/Executable/prebuild.txt")
  90. ADD_CUSTOM_COMMAND(TARGET complex PRE_BUILD
  91. COMMAND ${CREATE_FILE_EXE}
  92. ARGS "${Complex_BINARY_DIR}/Executable/prelink.txt")
  93. ADD_CUSTOM_COMMAND(TARGET complex POST_BUILD
  94. COMMAND ${CREATE_FILE_EXE}
  95. ARGS "${Complex_BINARY_DIR}/Executable/postbuild.txt")
  96. ADD_CUSTOM_COMMAND(TARGET complex POST_BUILD
  97. COMMAND ${CMAKE_COMMAND}
  98. ARGS -E copy
  99. "${Complex_BINARY_DIR}/Executable/postbuild.txt"
  100. "${Complex_BINARY_DIR}/Executable/postbuild2.txt")
  101. SET_SOURCE_FILES_PROPERTIES(complex
  102. COMPILE_FLAGS
  103. "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
  104. #" -DFILE_DEFINE_STRING=\\\"hello\\\""
  105. OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
  106. )
  107. SET_TARGET_PROPERTIES(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
  108. ADD_CUSTOM_COMMAND(
  109. TARGET complex
  110. SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
  111. COMMAND ${CMAKE_COMMAND}
  112. ARGS -E copy ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
  113. ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
  114. OUTPUTS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
  115. DEPENDS ${CMAKE_COMMAND}
  116. )
  117. # Test creating an executable that is not built by default.
  118. ADD_EXECUTABLE(notInAllExe EXCLUDE_FROM_ALL notInAllExe.cxx)
  119. TARGET_LINK_LIBRARIES(notInAllExe notInAllLib)
  120. # Test user-value flag mapping for the VS IDE.
  121. IF(MSVC)
  122. SET_TARGET_PROPERTIES(notInAllExe PROPERTIES
  123. LINK_FLAGS "/NODEFAULTLIB:LIBC;LIBCMT;MSVCRT")
  124. ENDIF(MSVC)
  125. # Test creating a custom target that builds not-in-all targets.
  126. ADD_CUSTOM_TARGET(notInAllCustom)
  127. ADD_DEPENDENCIES(notInAllCustom notInAllExe)
  128. #
  129. # Output the files required by 'complex' to a file.
  130. #
  131. # This test has been moved to the 'required' subdir so that it
  132. # has no side-effects on the current Makefile (duplicated source file
  133. # due to source list expansion done twice).
  134. #
  135. ADD_SUBDIRECTORY(Temp)
  136. IF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
  137. ADD_EXECUTABLE(testSystemDir testSystemDir.cxx)
  138. SET_TARGET_PROPERTIES(testSystemDir PROPERTIES COMPILE_FLAGS "-Werror")
  139. ENDIF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
  140. #
  141. # Extra coverage.Not used.
  142. #
  143. INSTALL_TARGETS(/tmp complex)
  144. INSTALL_PROGRAMS(/tmp complex)
  145. CONFIGURE_FILE(
  146. ${Complex_SOURCE_DIR}/Executable/cmVersion.h.in
  147. ${Complex_BINARY_DIR}/cmVersion.h)
  148. SOURCE_GROUP(A_GROUP ".cxx")
  149. SOURCE_GROUP(B_GROUP REGULAR_EXPRESSION "cxx")
  150. SOURCE_GROUP(C_GROUP FILES complex.cxx)
  151. FILE(WRITE ${Complex_BINARY_DIR}/A/libA.a "test")
  152. FILE(WRITE ${Complex_BINARY_DIR}/A/libC.a "test")
  153. FILE(WRITE ${Complex_BINARY_DIR}/B/libB.a "test")
  154. FILE(WRITE ${Complex_BINARY_DIR}/B/libA.a "test")
  155. FILE(WRITE ${Complex_BINARY_DIR}/C/libC.a "test")
  156. FILE(WRITE ${Complex_BINARY_DIR}/C/libB.a "test")