CMakeLists.txt 5.24 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
CMAKE_MINIMUM_REQUIRED(VERSION 1.3)
2 3 4
#
# Create exe. 
#
5
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
6
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
Bill Hoffman's avatar
Bill Hoffman committed
7
SET(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
8

Bill Hoffman's avatar
Bill Hoffman committed
9 10 11 12 13 14 15 16 17 18
IF(NOT CMAKE_TEST_DIFFERENT_GENERATOR)
  # Link to CMake lib
  LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
  LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source/kwsys)
  LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmexpat)
  LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmzlib)
  LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmtar)
ENDIF(NOT CMAKE_TEST_DIFFERENT_GENERATOR)

  # Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to 
19
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
Sebastien Barre's avatar
Sebastien Barre committed
20
LINK_LIBRARIES(${COMPLEX_LIBS})
21

22
ADD_EXECUTABLE(A A.cxx A.hh A.h A.txt)
23 24
ADD_EXECUTABLE(complex complex testcflags.c )
#  Sub1/NameConflictTest.c Sub2/NameConflictTest.c)
25
ADD_EXECUTABLE(complex.file complex.file.cxx)
26 27 28 29
IF(NOT CMAKE_TEST_DIFFERENT_GENERATOR)
  TARGET_LINK_LIBRARIES(complex CMakeLib cmsys cmexpat cmzlib cmtar)
ENDIF(NOT CMAKE_TEST_DIFFERENT_GENERATOR)

Ken Martin's avatar
Ken Martin committed
30
IF (UNIX)
Andy Cedilnik's avatar
Andy Cedilnik committed
31
  TARGET_LINK_LIBRARIES(complex ${CMAKE_DL_LIBS})
Ken Martin's avatar
Ken Martin committed
32
ELSE(UNIX)
33
  IF (NOT BORLAND)
34 35 36
    IF(NOT MINGW)
      TARGET_LINK_LIBRARIES(complex rpcrt4.lib)
    ENDIF(NOT MINGW)
37
  ENDIF(NOT BORLAND)
Ken Martin's avatar
Ken Martin committed
38
ENDIF (UNIX)
Ken Martin's avatar
Ken Martin committed
39

40 41 42 43 44 45
# Test linking to static lib when a shared lib has the same name.
IF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
  ADD_DEFINITIONS(-DCOMPLEX_TEST_LINK_STATIC)
  TARGET_LINK_LIBRARIES(complex CMakeTestLinkStatic)
ENDIF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
# can we get the path to a source file
GET_SOURCE_FILE_PROPERTY(A_LOCATION A.cxx LOCATION)
IF ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx")
  ADD_DEFINITIONS(-DCMAKE_FOUND_ACXX)
ENDIF ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx")

# get the directory parent
GET_DIRECTORY_PROPERTY(P_VALUE PARENT_DIRECTORY)
IF ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}")
  ADD_DEFINITIONS(-DCMAKE_FOUND_PARENT)
ENDIF ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}")

# get the stack of listfiles
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)
ENDIF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake")

64 65 66 67 68 69 70 71
# Test add/remove definitions.
ADD_DEFINITIONS(
  -DCOMPLEX_DEFINED_PRE
  -DCOMPLEX_DEFINED
  -DCOMPLEX_DEFINED_POST
  -DCOMPLEX_DEFINED
  )
REMOVE_DEFINITIONS(-DCOMPLEX_DEFINED)
72

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
# Test pre-build/pre-link/post-build rules for an executable.
ADD_CUSTOM_COMMAND(TARGET complex PRE_BUILD
                   COMMAND ${CREATE_FILE_EXE}
                   ARGS "${Complex_BINARY_DIR}/Executable/prebuild.txt")
ADD_CUSTOM_COMMAND(TARGET complex PRE_BUILD
                   COMMAND ${CREATE_FILE_EXE}
                   ARGS "${Complex_BINARY_DIR}/Executable/prelink.txt")
ADD_CUSTOM_COMMAND(TARGET complex POST_BUILD
                   COMMAND ${CREATE_FILE_EXE}
                   ARGS "${Complex_BINARY_DIR}/Executable/postbuild.txt")
ADD_CUSTOM_COMMAND(TARGET complex POST_BUILD
                   COMMAND ${CMAKE_COMMAND}
                   ARGS -E copy
                        "${Complex_BINARY_DIR}/Executable/postbuild.txt"
                        "${Complex_BINARY_DIR}/Executable/postbuild2.txt")

89 90 91 92
SET_SOURCE_FILES_PROPERTIES(complex
  COMPILE_FLAGS "-DFILE_HAS_EXTRA_COMPILE_FLAGS"
  OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h
)
93
SET_TARGET_PROPERTIES(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG")
94 95 96 97 98 99 100 101 102 103
ADD_CUSTOM_COMMAND(
  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}
)

104
# Test creating an executable that is not built by default.
105
ADD_EXECUTABLE(notInAllExe EXCLUDE_FROM_ALL notInAllExe.cxx)
106 107 108 109 110 111
TARGET_LINK_LIBRARIES(notInAllExe notInAllLib)

# Test creating a custom target that builds not-in-all targets.
ADD_CUSTOM_TARGET(notInAllCustom)
ADD_DEPENDENCIES(notInAllCustom notInAllExe)

Sebastien Barre's avatar
Sebastien Barre committed
112 113 114
#
# Output the files required by 'complex' to a file.
#
115 116 117 118
# 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).
#
119
ADD_SUBDIRECTORY(Temp)
Sebastien Barre's avatar
Sebastien Barre committed
120

121 122 123 124 125
IF(CMAKE_COMPILER_IS_GNUCXX)
  ADD_EXECUTABLE(testSystemDir testSystemDir.cxx)
  SET_TARGET_PROPERTIES(testSystemDir PROPERTIES COMPILE_FLAGS "-Werror")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)

126
#
127
# Extra coverage.Not used.
128
#
129 130
INSTALL_TARGETS(/tmp complex)
INSTALL_PROGRAMS(/tmp complex)
131

Ken Martin's avatar
Ken Martin committed
132 133 134 135
CONFIGURE_FILE(
  ${Complex_SOURCE_DIR}/Executable/cmVersion.h.in
  ${Complex_BINARY_DIR}/cmVersion.h)

136
SOURCE_GROUP(A_GROUP ".cxx")
Bill Hoffman's avatar
Bill Hoffman committed
137 138 139
SOURCE_GROUP(B_GROUP REGULAR_EXPRESSION "cxx")
SOURCE_GROUP(C_GROUP FILES complex.cxx)

140 141 142 143 144 145
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")