summaryrefslogtreecommitdiffstats
path: root/Tests/Complex/CMakeLists.txt
blob: 720ae1aec646fd510431a0c043f8b78ada3a982f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#
# A more complex test case
#
PROJECT (Complex)

#
# Use the ansi CXX compile flag for building cmake
#
IF (CMAKE_ANSI_CXXFLAGS)
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}")  
ENDIF (CMAKE_ANSI_CXXFLAGS)

ADD_DEFINITIONS(-DCMAKE_IS_FUN)

#
# Include vars from a file and from a cache
#
IF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)
  INCLUDE(${Complex_SOURCE_DIR}/VarTests.cmake)
ENDIF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake)

LOAD_CACHE(${Complex_SOURCE_DIR}/Cache
           EXCLUDE
             CACHE_TEST_VAR_EXCLUDED
           INCLUDE_INTERNALS
             CACHE_TEST_VAR_INTERNAL)

#
# Specify include and lib dirs 
# (BEFORE is for coverage)
#
INCLUDE_DIRECTORIES(
  ${Complex_SOURCE_DIR}/Library
  ${Complex_SOURCE_DIR}/../../Source
)

INCLUDE_DIRECTORIES(BEFORE
  ${Complex_BINARY_DIR}
)

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

LINK_DIRECTORIES(
  ${Complex_BINARY_DIR}/Library
)

#
# Lib and exe path
#
SET (LIBRARY_OUTPUT_PATH 
     ${Complex_BINARY_DIR}/bin/ CACHE PATH 
     "Single output directory for building all libraries.")

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

#
# Exec program (TODO: test a result)
# Increase coverage.
#
MESSAGE("\nIgnore this message")
OPTION(NO_EXEC_PROGRAM "Do not test EXEC_PROGRAM" 0)
IF (NOT NO_EXEC_PROGRAM)
  EXEC_PROGRAM("echo NO_EXEC_PROGRAM" "${Complex_BINARY_DIR}")
  EXEC_PROGRAM(echo ARGS NO_EXEC_PROGRAM "${Complex_BINARY_DIR}")
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)

#
# 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")

#
# Test FIND_LIBARY
# Create a dummy empty lib
#
CONFIGURE_FILE(
  ${Complex_SOURCE_DIR}/Library/dummy
  ${Complex_BINARY_DIR}/Library/dummylib.lib
  COPYONLY IMMEDIATE)
FOREACH (ext "${CMAKE_SHLIB_SUFFIX};.so;.a;.sl")
  CONFIGURE_FILE(
    ${Complex_SOURCE_DIR}/Library/dummy
    ${Complex_BINARY_DIR}/Library/libdummylib${ext}
    COPYONLY IMMEDIATE)
ENDFOREACH (ext)

FIND_LIBRARY(FIND_DUMMY_LIB
             dummylib
             PATHS
             ${Complex_BINARY_DIR}/Library)

#
# Test SET_SOURCE_FILES_PROPERTIES 
#
SET_SOURCE_FILES_PROPERTIES(nonexisting_file2 
	                    GENERATED 
	                    ABSTRACT 
                            WRAP_EXCLUDE 
                            COMPILE_FLAGS "-foo -bar")

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)

#
# 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)
    EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "write_regv \"${hkey}\" \"${dir}\"")
    FIND_PATH(REGISTRY_TEST_PATH
              ${file}
              "[${hkey}]")
    EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "delete_regv \"${hkey}\"")
    EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "remove \"${dir}/${file}\"")
  ENDIF (NOT UNIX)
ENDIF (WIN32)

#
# 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)

#
# Create the libs and the main exe
#
SUBDIRS(Library Executable)
SUBDIR_DEPENDS(Executable Library)