CMakeLists.txt 8.62 KB
Newer Older
1
#
2
# A more complex test case
3
#
4
SET(CMAKE_BACKWARDS_COMPATIBILITY 1.4)
5 6
PROJECT (Complex)

Ken Martin's avatar
Ken Martin committed
7 8 9 10 11 12 13 14 15 16 17
#
# Define a macro
#
MACRO(ASSERT value msg)
  IF (NOT ${value})
    MESSAGE ("Assertion failure:" ${msg} )
  ENDIF (NOT ${value})
ENDMACRO(ASSERT)
 
# invoke the macro
ASSERT(Complex_BINARY_DIR "The PROJECT command is broken")
18

19 20 21 22 23 24 25 26 27 28 29 30 31
#
# Define a var args macro, it must take two or four args
#
MACRO(TEST_ARGC value1 value2)
  ADD_DEFINITIONS(${value1} ${value2})
  IF (${ARGC} MATCHES 4)
    ADD_DEFINITIONS(${ARGV2} ${ARGV3})
  ENDIF (${ARGC} MATCHES 4)
ENDMACRO(TEST_ARGC)
 
# invoke the macro
TEST_ARGC(-DCMAKE_ARGV1 -DCMAKE_ARGV2 -DCMAKE_ARGV3 -DCMAKE_ARGV4)

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
MACRO(TEST_VAR_ARG fa)
  IF("${ARGV}" MATCHES "^1;2;3$")
    MESSAGE(STATUS "ARGV works")
  ELSE("${ARGV}" MATCHES "^1;2;3$")
    MESSAGE(FATAL_ERROR "ARGV does not work; got \"${ARGV}\" instead of \"1;2;3\"")
  ENDIF("${ARGV}" MATCHES "^1;2;3$")
  IF("${ARGN}" MATCHES "^2;3$")
    MESSAGE(STATUS "ARGN works")
  ELSE("${ARGN}" MATCHES "^2;3$")
    MESSAGE(FATAL_ERROR "ARGV does not work; got \"${ARGN}\" instead of \"2;3\"")
  ENDIF("${ARGN}" MATCHES "^2;3$")
ENDMACRO(TEST_VAR_ARG)

TEST_VAR_ARG(1 2 3)

47 48 49
#
# Use the ansi CXX compile flag for building cmake
#
Ken Martin's avatar
Ken Martin committed
50 51 52
IF (CMAKE_ANSI_CXXFLAGS)
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}")  
ENDIF (CMAKE_ANSI_CXXFLAGS)
Bill Hoffman's avatar
Bill Hoffman committed
53

54 55
IF(CMAKE_SYSTEM MATCHES "OSF1-V.*")
  IF(NOT CMAKE_COMPILER_IS_GNUCXX)
Bill Hoffman's avatar
Bill Hoffman committed
56
     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -timplicit_local -no_implicit_include ")
57 58 59 60
  ENDIF(NOT CMAKE_COMPILER_IS_GNUCXX)
ENDIF(CMAKE_SYSTEM MATCHES "OSF1-V.*")


61
ADD_DEFINITIONS(-DCMAKE_IS_FUN)
62
ADD_DEFINITIONS(-DCMAKE_IS_REALLY_FUN)
63

64 65 66 67
SET(TEST_SEP "a b c")
SEPARATE_ARGUMENTS(TEST_SEP)


68 69 70
#
# Include vars from a file and from a cache
#
71 72 73
IF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)
  INCLUDE(${Complex_SOURCE_DIR}/VarTests.cmake)
ENDIF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)
Bill Hoffman's avatar
Bill Hoffman committed
74
INCLUDE(fileshouldnotbehere OPTIONAL)
75
LOAD_CACHE(${Complex_SOURCE_DIR}/Cache
Sebastien Barre's avatar
Sebastien Barre committed
76 77 78 79
           EXCLUDE
             CACHE_TEST_VAR_EXCLUDED
           INCLUDE_INTERNALS
             CACHE_TEST_VAR_INTERNAL)
80

Bill Hoffman's avatar
Bill Hoffman committed
81 82 83 84 85 86
LOAD_CACHE(${Complex_SOURCE_DIR}/Cache READ_WITH_PREFIX foo CACHE_TEST_VAR2)
IF(${fooCACHE_TEST_VAR2} MATCHES bar)
  MESSAGE("Load cache worked: ${fooCACHE_TEST_VAR2}")
ELSE(${fooCACHE_TEST_VAR2} MATCHES bar)
  MESSAGE(FATAL_ERROR "Load cache with prefix failed: ${fooCACHE_TEST_VAR2}")
ENDIF(${fooCACHE_TEST_VAR2} MATCHES bar)
Bill Hoffman's avatar
Bill Hoffman committed
87 88 89



90 91
#
# Specify include and lib dirs 
Sebastien Barre's avatar
Sebastien Barre committed
92
# (BEFORE is for coverage)
93
#
94
INCLUDE_DIRECTORIES(
95
  Library
96
  ${Complex_SOURCE_DIR}/../../Source
97
  ${Complex_BINARY_DIR}/../../Source
98
)
99

Sebastien Barre's avatar
Sebastien Barre committed
100 101 102 103
INCLUDE_DIRECTORIES(BEFORE
  ${Complex_BINARY_DIR}
)

104
INCLUDE_REGULAR_EXPRESSION("^(cmTest|file|sharedFile).*$" "^cmMissing")
105

106
LINK_DIRECTORIES(
107
  ${Complex_BINARY_DIR}/Library
108 109
)

110 111 112 113 114 115
#
# check for SET CACHE FORCE
#
SET(FORCE_TEST 1 CACHE STRING "a test")
SET(FORCE_TEST 0 CACHE STRING "a test" FORCE)

116 117 118
#
# Lib and exe path
#
119
SET (LIBRARY_OUTPUT_PATH 
120
     ${Complex_BINARY_DIR}/bin/ CACHE INTERNAL
121 122 123
     "Single output directory for building all libraries.")

SET (EXECUTABLE_OUTPUT_PATH 
124
     ${Complex_BINARY_DIR}/bin/ CACHE INTERNAL
125 126
     "Single output directory for building all executables.")

127
MESSAGE (Test " " escape " " semi-colon " " \; \;)
128
#
129
# Exec program (TODO: test a result)
130 131
# Increase coverage.
#
Sebastien Barre's avatar
Sebastien Barre committed
132
MESSAGE("\nIgnore this message")
133 134
OPTION(NO_EXEC_PROGRAM "Do not test EXEC_PROGRAM" 0)
IF (NOT NO_EXEC_PROGRAM)
Andy Cedilnik's avatar
Andy Cedilnik committed
135
  EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E echo NO_EXEC_PROGRAM "${Complex_BINARY_DIR}")
136 137 138 139 140 141
ELSE (NOT NO_EXEC_PROGRAM) 
  MESSAGE("Set this option ON")
ENDIF (NOT NO_EXEC_PROGRAM) 

MARK_AS_ADVANCED(NO_EXEC_PROGRAM)
MARK_AS_ADVANCED(CLEAR NO_EXEC_PROGRAM)
142

143 144 145 146 147
# Execute a process.  Add coverage for this command.
EXECUTE_PROCESS(
  COMMAND ${CMAKE_COMMAND} -E echo "ABCDEFG"
  OUTPUT_VARIABLE TEST_OUT
  )
148 149 150 151
IF("${TEST_OUT}" MATCHES "^ABCDEFG\n$")
ELSE("${TEST_OUT}" MATCHES "^ABCDEFG\n$")
  MESSAGE(SEND_ERROR "EXECUTE_PROCESS output test failed: [${TEST_OUT}]")
ENDIF("${TEST_OUT}" MATCHES "^ABCDEFG\n$")
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

# This test has some problems on UNIX systems.  Disabling for now.
#
# EXECUTE_PROCESS(
#   COMMAND ${CMAKE_COMMAND} -E echo "ABCDEFG"
#   COMMAND /process/does/not/exist
#   OUTPUT_QUIET
#   ERROR_QUIET
#   RESULT_VARIABLE RESULT
#   )
# IF("${RESULT}" MATCHES "^0$")
#   MESSAGE(SEND_ERROR
#     "EXECUTE_PROCESS result test failed with RESULT=[${RESULT}]")
# ELSE("${RESULT}" MATCHES "^0$")
#   MESSAGE(STATUS "EXECUTE_PROCESS result test passed with RESULT=[${RESULT}]")
# ENDIF("${RESULT}" MATCHES "^0$")
168

169 170 171 172 173 174
#
# Create directory.
# The 'complex' executable will then test if this dir exists,
# sadly it won't be able to remove it.
#
MAKE_DIRECTORY("${Complex_BINARY_DIR}/make_dir")
Sebastien Barre's avatar
Sebastien Barre committed
175 176 177 178 179

#
# Test FIND_LIBARY
# Create a dummy empty lib
#
180 181 182 183
CONFIGURE_FILE(
  ${Complex_SOURCE_DIR}/Library/dummy
  ${Complex_BINARY_DIR}/Library/dummylib.lib
  COPYONLY IMMEDIATE)
184
FOREACH (ext ${CMAKE_SHLIB_SUFFIX};.so;.a;.sl)
Sebastien Barre's avatar
Sebastien Barre committed
185 186
  CONFIGURE_FILE(
    ${Complex_SOURCE_DIR}/Library/dummy
187
    ${Complex_BINARY_DIR}/Library/libdummylib${ext}
Sebastien Barre's avatar
Sebastien Barre committed
188 189 190 191 192 193
    COPYONLY IMMEDIATE)
ENDFOREACH (ext)

FIND_LIBRARY(FIND_DUMMY_LIB
             dummylib
             PATHS
Bill Hoffman's avatar
Bill Hoffman committed
194 195 196 197 198 199
             ${Complex_BINARY_DIR}/Library DOC "find dummy lib")

FIND_LIBRARY(FIND_DUMMY_LIB
             NAMES dummylib dummylib2
             PATHS
             ${Complex_BINARY_DIR}/Library DOC "find dummy lib")
Sebastien Barre's avatar
Sebastien Barre committed
200 201 202 203 204

#
# Test SET_SOURCE_FILES_PROPERTIES 
#
SET_SOURCE_FILES_PROPERTIES(nonexisting_file2 
205 206 207 208
  GENERATED 
  ABSTRACT 
  WRAP_EXCLUDE 
  COMPILE_FLAGS "-foo -bar")
Sebastien Barre's avatar
Sebastien Barre committed
209 210 211 212 213

GET_SOURCE_FILE_PROPERTY(FILE_HAS_ABSTRACT nonexisting_file2 ABSTRACT)
GET_SOURCE_FILE_PROPERTY(FILE_HAS_WRAP_EXCLUDE nonexisting_file2 WRAP_EXCLUDE)
GET_SOURCE_FILE_PROPERTY(FILE_COMPILE_FLAGS nonexisting_file2 COMPILE_FLAGS)

214
SET_SOURCE_FILES_PROPERTIES(nonexisting_file3 PROPERTIES
215 216 217 218
  GENERATED 1
  ABSTRACT 1
  WRAP_EXCLUDE 1
  COMPILE_FLAGS "-foo -bar")
219 220 221 222
GET_SOURCE_FILE_PROPERTY(FILE_HAS_ABSTRACT nonexisting_file3 ABSTRACT)
GET_SOURCE_FILE_PROPERTY(FILE_HAS_WRAP_EXCLUDE nonexisting_file3 WRAP_EXCLUDE)
GET_SOURCE_FILE_PROPERTY(FILE_COMPILE_FLAGS nonexisting_file3 COMPILE_FLAGS)

223 224 225 226 227 228 229 230 231 232 233 234 235 236
#
# Test registry (win32)
# Create a file, put its path in a registry key, try to find the file in that
# path using that registry key, then remove the file and the key
#
IF (WIN32)
  IF (NOT UNIX)
    SET(dir "${Complex_BINARY_DIR}/registry_dir")
    SET(file "registry_test_dummy")
    SET(hkey "HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Tests\\Complex;registry_test")
    CONFIGURE_FILE(
      ${Complex_SOURCE_DIR}/Library/dummy
      "${dir}/${file}"
      COPYONLY IMMEDIATE)
237
    EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E write_regv \"${hkey}\" \"${dir}\"")
238
    FIND_PATH(REGISTRY_TEST_PATH
239 240
      ${file}
      "[${hkey}]" DOC "Registry_Test_Path")
241 242
    EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E delete_regv \"${hkey}\"")
    EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E remove \"${dir}/${file}\"")
243 244 245
  ENDIF (NOT UNIX)
ENDIF (WIN32)

Ken Martin's avatar
Ken Martin committed
246 247 248 249 250 251 252
#
# Test a set and a remove
#
SET(REMOVE_STRING a b c d e f)
SET(removeVar1 c e)
REMOVE(REMOVE_STRING ${removeVar1} f)

253 254 255 256
#
# Test an IF inside a FOREACH.
#
FOREACH(x "a")
257
  IF(${x} MATCHES "a")
258 259
    # Should always execute.
    SET(IF_INSIDE_FOREACH_THEN_EXECUTED 1)
260
  ELSE(${x} MATCHES "a")
261 262
    # Should never execute.
    SET(IF_INSIDE_FOREACH_ELSE_EXECUTED 1)
263
  ENDIF(${x} MATCHES "a")
264 265
ENDFOREACH(x)

266 267 268 269 270
# test WHILE command
SET (while_var 1)
WHILE (while_var LESS 1000)
  SET(while_var ${while_var}0)
ENDWHILE(while_var LESS 1000)
271

272 273
SET(SHOULD_BE_ZERO )
SET(SHOULD_BE_ONE 1)
Sebastien Barre's avatar
Sebastien Barre committed
274 275 276 277 278 279 280 281
#
# Configure file 
# (plug vars to #define so that they can be tested)
#
CONFIGURE_FILE(
  ${Complex_SOURCE_DIR}/cmTestConfigure.h.in
  ${Complex_BINARY_DIR}/cmTestConfigure.h)

282 283 284 285 286 287
SET(STRING_WITH_QUOTES "\"hello world\"")
# test CONFIGURE_FILE with ESCAPE_QUOTES on
CONFIGURE_FILE(
  ${Complex_SOURCE_DIR}/cmTestConfigureEscape.h.in
  ${Complex_BINARY_DIR}/cmTestConfigureEscape.h ESCAPE_QUOTES)

Brad King's avatar
Brad King committed
288 289 290 291 292 293 294 295 296
# Test regular expression commands.
STRING(REGEX MATCH "b" RESULT "abc")
IF(NOT RESULT)
  MESSAGE(SEND_ERROR "STRING(REGEX MATCH ... ) test failed.")
ENDIF(NOT RESULT)
STRING(REGEX MATCHALL "b" RESULT "abcb")
IF(NOT RESULT)
  MESSAGE(SEND_ERROR "STRING(REGEX MATCHALL ... ) test failed.")
ENDIF(NOT RESULT)
297 298
STRING(REGEX REPLACE ".([bd])." "[\\1]" RESULT "a(b)c(d)e")
IF("x${RESULT}" MATCHES "^xa\\[b\\]c\\[d\\]e$")
Brad King's avatar
Brad King committed
299
  SET(STRING_REGEX_PASSED 1)
300
ENDIF("x${RESULT}" MATCHES "^xa\\[b\\]c\\[d\\]e$")
Brad King's avatar
Brad King committed
301
IF(NOT STRING_REGEX_PASSED)
302
  MESSAGE(SEND_ERROR
303
    "STRING(REGEX REPLACE ... ) test failed (\"${RESULT}\" v. \"a[b]c[d]e\")")
Brad King's avatar
Brad King committed
304 305
ENDIF(NOT STRING_REGEX_PASSED)

Sebastien Barre's avatar
Sebastien Barre committed
306 307 308
#
# Create the libs and the main exe
#
309 310
ADD_SUBDIRECTORY(Library)
ADD_SUBDIRECTORY(Executable)
Sebastien Barre's avatar
Sebastien Barre committed
311
SUBDIR_DEPENDS(Executable Library)
312
EXPORT_LIBRARY_DEPENDENCIES(${Complex_BINARY_DIR}/ComplexLibraryDepends.cmake)
313
INCLUDE(${Complex_BINARY_DIR}/ComplexLibraryDepends.cmake OPTIONAL)