CMakeLists.txt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. # Create an imported target for if(TARGET) test below.
  8. add_library(ExeImportedTarget UNKNOWN IMPORTED)
  9. # Test if(TARGET) command.
  10. if(NOT TARGET CMakeTestLibrary)
  11. message(FATAL_ERROR "if(NOT TARGET CMakeTestLibrary) returned true!")
  12. endif()
  13. if(NOT TARGET ExeImportedTarget)
  14. message(FATAL_ERROR "if(NOT TARGET ExeImportedTarget) returned true!")
  15. endif()
  16. if(TARGET LibImportedTarget)
  17. message(FATAL_ERROR "if(TARGET LibImportedTarget) returned true!")
  18. endif()
  19. if(TARGET NotATarget)
  20. message(FATAL_ERROR "if(TARGET NotATarget) returned true!")
  21. endif()
  22. # Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
  23. set(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
  24. link_libraries(${COMPLEX_LIBS})
  25. # Test forcing a .cxx file to not build.
  26. set_source_files_properties(complex_nobuild.cxx PROPERTIES
  27. HEADER_FILE_ONLY 1)
  28. # Test forcing a .c file to not build.
  29. # This makes sure a mixed language library is created
  30. # with header file only sources
  31. set_source_files_properties(complex_nobuild.c PROPERTIES
  32. HEADER_FILE_ONLY 1)
  33. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  34. add_executable(A A.cxx A.hh A.h A.txt)
  35. add_custom_command(OUTPUT Aout.h COMMAND A > Aout.h VERBATIM)
  36. add_executable(complex complex testcflags.c Aout.h)
  37. # Sub1/NameConflictTest.c Sub2/NameConflictTest.c)
  38. add_executable(complex.file complex.file.cxx complex_nobuild.cxx
  39. complex_nobuild.c)
  40. if (UNIX)
  41. target_link_libraries(complex ${CMAKE_DL_LIBS})
  42. else()
  43. if (NOT BORLAND)
  44. if(NOT MINGW)
  45. target_link_libraries(complex rpcrt4.lib)
  46. endif()
  47. endif()
  48. endif ()
  49. # Test linking to static lib when a shared lib has the same name.
  50. if(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
  51. add_definitions(-DCOMPLEX_TEST_LINK_STATIC)
  52. target_link_libraries(complex CMakeTestLinkStatic)
  53. endif()
  54. # can we get the path to a source file
  55. get_source_file_property(A_LOCATION A.cxx LOCATION)
  56. if ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx")
  57. add_definitions(-DCMAKE_FOUND_ACXX)
  58. endif ()
  59. # get the directory parent
  60. get_directory_property(P_VALUE PARENT_DIRECTORY)
  61. if ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}")
  62. add_definitions(-DCMAKE_FOUND_PARENT)
  63. endif ()
  64. # get the stack of listfiles
  65. include(Included.cmake)
  66. if ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")
  67. add_definitions(-DCMAKE_FOUND_LISTFILE_STACK)
  68. endif ()
  69. # Test add/remove definitions.
  70. add_definitions(
  71. -DCOMPLEX_DEFINED_PRE
  72. -DCOMPLEX_DEFINED
  73. -DCOMPLEX_DEFINED_POST
  74. -DCOMPLEX_DEFINED
  75. )
  76. remove_definitions(-DCOMPLEX_DEFINED)
  77. # Test pre-build/pre-link/post-build rules for an executable.
  78. add_custom_command(TARGET complex PRE_BUILD
  79. COMMAND ${CREATE_FILE_EXE}
  80. ARGS "${Complex_BINARY_DIR}/Executable/prebuild.txt")
  81. add_custom_command(TARGET complex PRE_BUILD
  82. COMMAND ${CREATE_FILE_EXE}
  83. ARGS "${Complex_BINARY_DIR}/Executable/prelink.txt")
  84. add_custom_command(TARGET complex POST_BUILD
  85. COMMAND ${CREATE_FILE_EXE}
  86. ARGS "${Complex_BINARY_DIR}/Executable/postbuild.txt")
  87. add_custom_command(TARGET complex POST_BUILD
  88. COMMAND ${CMAKE_COMMAND}
  89. ARGS -E copy
  90. "${Complex_BINARY_DIR}/Executable/postbuild.txt"
  91. "${Complex_BINARY_DIR}/Executable/postbuild2.txt")
  92. set_source_files_properties(complex
  93. COMPILE_FLAGS
  94. "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
  95. #" -DFILE_DEFINE_STRING=\\\"hello\\\""
  96. OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
  97. )
  98. set_target_properties(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
  99. add_custom_command(
  100. TARGET complex
  101. SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
  102. COMMAND ${CMAKE_COMMAND}
  103. ARGS -E copy ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in
  104. ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
  105. OUTPUTS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
  106. DEPENDS ${CMAKE_COMMAND}
  107. )
  108. # Test creating an executable that is not built by default.
  109. add_executable(notInAllExe EXCLUDE_FROM_ALL notInAllExe.cxx)
  110. target_link_libraries(notInAllExe notInAllLib)
  111. # Test user-value flag mapping for the VS IDE.
  112. if(MSVC)
  113. set_target_properties(notInAllExe PROPERTIES
  114. LINK_FLAGS "/NODEFAULTLIB:LIBC;LIBCMT;MSVCRT")
  115. endif()
  116. # Test creating a custom target that builds not-in-all targets.
  117. add_custom_target(notInAllCustom)
  118. add_dependencies(notInAllCustom notInAllExe)
  119. #
  120. # Output the files required by 'complex' to a file.
  121. #
  122. # This test has been moved to the 'required' subdir so that it
  123. # has no side-effects on the current Makefile (duplicated source file
  124. # due to source list expansion done twice).
  125. #
  126. add_subdirectory(Temp)
  127. if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
  128. add_executable(testSystemDir testSystemDir.cxx)
  129. set_target_properties(testSystemDir PROPERTIES COMPILE_FLAGS "-Werror")
  130. endif()
  131. #
  132. # Extra coverage.Not used.
  133. #
  134. install_targets(/tmp complex)
  135. install_programs(/tmp complex)
  136. configure_file(
  137. ${Complex_SOURCE_DIR}/Executable/cmVersion.h.in
  138. ${Complex_BINARY_DIR}/cmVersion.h)
  139. source_group(A_GROUP ".cxx")
  140. source_group(B_GROUP REGULAR_EXPRESSION "cxx")
  141. source_group(C_GROUP FILES complex.cxx)
  142. file(WRITE ${Complex_BINARY_DIR}/A/libA.a "test")
  143. file(WRITE ${Complex_BINARY_DIR}/A/libC.a "test")
  144. file(WRITE ${Complex_BINARY_DIR}/B/libB.a "test")
  145. file(WRITE ${Complex_BINARY_DIR}/B/libA.a "test")
  146. file(WRITE ${Complex_BINARY_DIR}/C/libC.a "test")
  147. file(WRITE ${Complex_BINARY_DIR}/C/libB.a "test")