2 # @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
3 # @author Pawel Sikorski (p.sikorski@samsung.com)
4 # @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
10 # Discovers target's INCLUDE_DIRECTORIES and LINK_DIRECTORIES.
11 # This is done by retrieving the directory target was built in and
12 # fetching appropriate properties of that directory.
13 FUNCTION(WRT_INTROSPECT_TARGET PREFIX TARGET_NAME)
14 GET_TARGET_PROPERTY(LOCATION ${TARGET_NAME} LOCATION)
15 IF(${LOCATION} STREQUAL "LOCATION-NOTFOUND")
16 MESSAGE(FATAL_ERROR "Target '${TARGET_NAME}' introspection failed")
17 ELSE(${LOCATION} STREQUAL "LOCATION-NOTFOUND")
18 STRING(FIND ${LOCATION} "/" LAST_SLASH_POSITION REVERSE)
19 STRING(SUBSTRING ${LOCATION} 0 ${LAST_SLASH_POSITION} LOCATION)
21 GET_DIRECTORY_PROPERTY(INCLUDE_DIRS DIRECTORY ${LOCATION} INCLUDE_DIRECTORIES)
22 SET("${PREFIX}_INCLUDE_DIRS" ${INCLUDE_DIRS} PARENT_SCOPE)
24 GET_DIRECTORY_PROPERTY(LIBRARY_DIRS DIRECTORY ${LOCATION} LINK_DIRECTORIES)
25 SET("${PREFIX}_LIBRARY_DIRS" ${LIBRARY_DIRS} PARENT_SCOPE)
26 ENDIF(${LOCATION} STREQUAL "LOCATION-NOTFOUND")
27 ENDFUNCTION(WRT_INTROSPECT_TARGET)
29 FUNCTION(WRT_TEST_LIBRARY)
30 SET_PROPERTY(GLOBAL APPEND PROPERTY COMMON_TESTS_LIBRARY ${ARGV})
31 ENDFUNCTION(WRT_TEST_LIBRARY)
34 # Replacement functions for standard (w/o "WRT_" prefix) CMake functions.
35 # They store supplied arguments in global properties to assign them to tests.
36 # Anything added with this functions is used by all targets that are built with
37 # WRT_TEST_BUILD function.
40 # Appends directories to global property TESTS_INCLUDE_DIRS which is
41 # then read by WRT_TEST_BUILD and its content is forwarded to
42 # command INCLUDE_DIRECTORIES() (for all targets).
43 FUNCTION(WRT_INCLUDE_DIRECTORIES)
44 SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_INCLUDE_DIRS ${ARGV})
45 ENDFUNCTION(WRT_INCLUDE_DIRECTORIES)
48 # Appends directories to global property TESTS_LIBRARY_DIRS which is
49 # then read by WRT_TEST_BUILD and its content is forwarded to
50 # command LINK_DIRECTORIES() (for all targets).
51 FUNCTION(WRT_LINK_DIRECTORIES)
52 SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_LIBRARY_DIRS ${ARGV})
53 ENDFUNCTION(WRT_LINK_DIRECTORIES)
56 # Appends directories to global property TESTS_LIBRARIES which is
57 # then read by WRT_TEST_BUILD and its content is forwarded to
58 # command TARGET_LINK_LIBRARIES() (for all targets).
59 FUNCTION(WRT_TARGET_LINK_LIBRARIES)
60 SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_LIBRARIES ${ARGV})
61 ENDFUNCTION(WRT_TARGET_LINK_LIBRARIES)
64 # Convenience method that fills TESTS_INCLUDE_DIRS, TESTS_LIBRARY_DIRS
65 # and TESTS_LIBRARIES with values discovered from introspecting supplied
67 # Function takes arbitrary number of targets.
68 FUNCTION(WRT_ADD_INTERNAL_DEPENDENCIES)
69 FOREACH(DEPENDENCY ${ARGV})
70 WRT_INTROSPECT_TARGET(prefix ${DEPENDENCY})
71 WRT_INCLUDE_DIRECTORIES(${prefix_INCLUDE_DIRS})
72 WRT_LINK_DIRECTORIES(${prefix_LIBRARY_DIRS})
73 WRT_TARGET_LINK_LIBRARIES(${DEPENDENCY})
74 ENDFOREACH(DEPENDENCY)
75 ENDFUNCTION(WRT_ADD_INTERNAL_DEPENDENCIES)
79 # Replacement functions for standard (w/o "WRT_" prefix) CMake functions.
80 # They store supplied arguments in global properties to assign them to specific
81 # tests. Properties names are based on the test target name.
82 # Anything added with this functions is used only by the specified target that
83 # is built with WRT_TEST_BUILD function.
86 # Appends directories to global property ${TARGET_NAME}_INCLUDE_DIRS
87 # which is then read by WRT_TEST_BUILD and its content is forwarded to
88 # command INCLUDE_DIRECTORIES() (for specified target).
89 FUNCTION(WRT_TEST_INCLUDE_DIRECTORIES TARGET_NAME)
90 SET_PROPERTY(GLOBAL APPEND PROPERTY ${TARGET_NAME}_INCLUDE_DIRS ${ARGN})
91 ENDFUNCTION(WRT_TEST_INCLUDE_DIRECTORIES)
94 # Appends directories to global property ${TARGET_NAME}_LIBRARY_DIRS
95 # which is then read by WRT_TEST_BUILD and its content is forwarded to
96 # command LINK_DIRECTORIES() (for specified target).
97 FUNCTION(WRT_TEST_LINK_DIRECTORIES TARGET_NAME)
98 SET_PROPERTY(GLOBAL APPEND PROPERTY ${TARGET_NAME}_LIBRARY_DIRS ${ARGN})
99 ENDFUNCTION(WRT_TEST_LINK_DIRECTORIES)
102 # Appends directories to global property ${TARGET_NAME}_LIBRARIES
103 # which is then read by WRT_TEST_BUILD and its content is forwarded to
104 # command TARGET_LINK_LIBRARIES() (for specified target).
105 FUNCTION(WRT_TEST_TARGET_LINK_LIBRARIES TARGET_NAME)
106 SET_PROPERTY(GLOBAL APPEND PROPERTY ${TARGET_NAME}_LIBRARIES ${ARGN})
107 ENDFUNCTION(WRT_TEST_TARGET_LINK_LIBRARIES)
110 # Convenience method that fills ${TARGET_NAME}_INCLUDE_DIRS,
111 # ${TARGET_NAME}_LIBRARY_DIRS and ${TARGET_NAME}_LIBRARIES with
112 # values discovered from introspecting supplied targets.
113 # Function takes arbitrary number of targets.
114 FUNCTION(WRT_TEST_ADD_INTERNAL_DEPENDENCIES TARGET_NAME)
115 FOREACH(DEPENDENCY ${ARGN})
116 WRT_INTROSPECT_TARGET(prefix ${DEPENDENCY})
117 WRT_TEST_INCLUDE_DIRECTORIES(${TARGET_NAME} ${prefix_INCLUDE_DIRS})
118 WRT_TEST_LINK_DIRECTORIES(${TARGET_NAME} ${prefix_LIBRARY_DIRS})
119 WRT_TEST_TARGET_LINK_LIBRARIES(${TARGET_NAME} ${DEPENDENCY})
120 ENDFOREACH(DEPENDENCY)
121 ENDFUNCTION(WRT_TEST_ADD_INTERNAL_DEPENDENCIES)
123 # Functions used to build test targets (proper sources, includes, libs are
124 # added automatically)
125 FUNCTION(WRT_TEST_BUILD TARGET_NAME)
126 SET(SOURCES "${ARGN}")
127 ADD_EXECUTABLE("${TARGET_NAME}" ${SOURCES})
129 # get include dirs global property
130 GET_PROPERTY(INCLUDE_DIRS GLOBAL PROPERTY TESTS_INCLUDE_DIRS)
131 GET_PROPERTY(TEST_INCLUDE_DIRS GLOBAL PROPERTY ${TARGET_NAME}_INCLUDE_DIRS)
137 # get library dirs global property
138 GET_PROPERTY(LIBRARY_DIRS GLOBAL PROPERTY TESTS_LIBRARY_DIRS)
139 GET_PROPERTY(TEST_LIBRARY_DIRS GLOBAL PROPERTY ${TARGET_NAME}_LIBRARY_DIRS)
145 # get link libraries global property
146 GET_PROPERTY(LINK_LIBRARIES GLOBAL PROPERTY TESTS_LIBRARIES)
147 GET_PROPERTY(TEST_LIBRARIES GLOBAL PROPERTY ${TARGET_NAME}_LIBRARIES)
148 TARGET_LINK_LIBRARIES("${TARGET_NAME}"
152 ENDFUNCTION(WRT_TEST_BUILD)
154 FUNCTION(WRT_TEST_INSTALL)
155 SET_TARGET_PROPERTIES(${ARGV} PROPERTIES
156 BUILD_WITH_INSTALL_RPATH ON
157 INSTALL_RPATH_USE_LINK_PATH ON
159 INSTALL(TARGETS ${ARGV}
161 PERMISSIONS OWNER_READ
169 ENDFUNCTION(WRT_TEST_INSTALL)
171 # Takes arbitrary number of arguments and concatenates them using ':' character.
173 # CMake list when converted to a string is joined with ';' character. However,
174 # GCC takes strings with multiple elements separated with ':' (e.g. list of
175 # paths). Used typically when generating DB schemas with ORM mechanism.
176 FUNCTION(WRT_CONVERT_TO_GCC_LIST OUTPUT_VARIABLE)
177 FOREACH(ITEM ${ARGN})
178 LIST(APPEND ITEMS ${ITEM})
180 STRING(REPLACE ";" ":" OUTPUT "${ITEMS}")
181 SET("${OUTPUT_VARIABLE}" "${OUTPUT}" PARENT_SCOPE)
182 ENDFUNCTION(WRT_CONVERT_TO_GCC_LIST)