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)
30 # Replacement functions for standard (w/o "WRT_" prefix) CMake functions.
31 # They store supplied arguments in global properties to assign them to tests.
32 # Anything added with this functions is used by all targets that are built with
33 # WRT_TEST_BUILD function.
36 # Appends directories to global property TESTS_INCLUDE_DIRS which is
37 # then read by WRT_TEST_BUILD and its content is forwarded to
38 # command INCLUDE_DIRECTORIES() (for all targets).
39 FUNCTION(WRT_INCLUDE_DIRECTORIES)
40 SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_INCLUDE_DIRS ${ARGV})
41 ENDFUNCTION(WRT_INCLUDE_DIRECTORIES)
44 # Appends directories to global property TESTS_LIBRARY_DIRS which is
45 # then read by WRT_TEST_BUILD and its content is forwarded to
46 # command LINK_DIRECTORIES() (for all targets).
47 FUNCTION(WRT_LINK_DIRECTORIES)
48 SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_LIBRARY_DIRS ${ARGV})
49 ENDFUNCTION(WRT_LINK_DIRECTORIES)
52 # Appends directories to global property TESTS_LIBRARIES which is
53 # then read by WRT_TEST_BUILD and its content is forwarded to
54 # command TARGET_LINK_LIBRARIES() (for all targets).
55 FUNCTION(WRT_TARGET_LINK_LIBRARIES)
56 SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_LIBRARIES ${ARGV})
57 ENDFUNCTION(WRT_TARGET_LINK_LIBRARIES)
60 # Convenience method that fills TESTS_INCLUDE_DIRS, TESTS_LIBRARY_DIRS
61 # and TESTS_LIBRARIES with values discovered from introspecting supplied
63 # Function takes arbitrary number of targets.
64 FUNCTION(WRT_ADD_INTERNAL_DEPENDENCIES)
65 FOREACH(DEPENDENCY ${ARGV})
66 WRT_INTROSPECT_TARGET(prefix ${DEPENDENCY})
67 WRT_INCLUDE_DIRECTORIES(${prefix_INCLUDE_DIRS})
68 WRT_LINK_DIRECTORIES(${prefix_LIBRARY_DIRS})
69 WRT_TARGET_LINK_LIBRARIES(${DEPENDENCY})
70 ENDFOREACH(DEPENDENCY)
71 ENDFUNCTION(WRT_ADD_INTERNAL_DEPENDENCIES)
75 # Replacement functions for standard (w/o "WRT_" prefix) CMake functions.
76 # They store supplied arguments in global properties to assign them to specific
77 # tests. Properties names are based on the test target name.
78 # Anything added with this functions is used only by the specified target that
79 # is built with WRT_TEST_BUILD function.
82 # Appends directories to global property ${TARGET_NAME}_INCLUDE_DIRS
83 # which is then read by WRT_TEST_BUILD and its content is forwarded to
84 # command INCLUDE_DIRECTORIES() (for specified target).
85 FUNCTION(WRT_TEST_INCLUDE_DIRECTORIES TARGET_NAME)
86 SET_PROPERTY(GLOBAL APPEND PROPERTY ${TARGET_NAME}_INCLUDE_DIRS ${ARGN})
87 ENDFUNCTION(WRT_TEST_INCLUDE_DIRECTORIES)
90 # Appends directories to global property ${TARGET_NAME}_LIBRARY_DIRS
91 # which is then read by WRT_TEST_BUILD and its content is forwarded to
92 # command LINK_DIRECTORIES() (for specified target).
93 FUNCTION(WRT_TEST_LINK_DIRECTORIES TARGET_NAME)
94 SET_PROPERTY(GLOBAL APPEND PROPERTY ${TARGET_NAME}_LIBRARY_DIRS ${ARGN})
95 ENDFUNCTION(WRT_TEST_LINK_DIRECTORIES)
98 # Appends directories to global property ${TARGET_NAME}_LIBRARIES
99 # which is then read by WRT_TEST_BUILD and its content is forwarded to
100 # command TARGET_LINK_LIBRARIES() (for specified target).
101 FUNCTION(WRT_TEST_TARGET_LINK_LIBRARIES TARGET_NAME)
102 SET_PROPERTY(GLOBAL APPEND PROPERTY ${TARGET_NAME}_LIBRARIES ${ARGN})
103 ENDFUNCTION(WRT_TEST_TARGET_LINK_LIBRARIES)
106 # Convenience method that fills ${TARGET_NAME}_INCLUDE_DIRS,
107 # ${TARGET_NAME}_LIBRARY_DIRS and ${TARGET_NAME}_LIBRARIES with
108 # values discovered from introspecting supplied targets.
109 # Function takes arbitrary number of targets.
110 FUNCTION(WRT_TEST_ADD_INTERNAL_DEPENDENCIES TARGET_NAME)
111 FOREACH(DEPENDENCY ${ARGN})
112 WRT_INTROSPECT_TARGET(prefix ${DEPENDENCY})
113 WRT_TEST_INCLUDE_DIRECTORIES(${TARGET_NAME} ${prefix_INCLUDE_DIRS})
114 WRT_TEST_LINK_DIRECTORIES(${TARGET_NAME} ${prefix_LIBRARY_DIRS})
115 WRT_TEST_TARGET_LINK_LIBRARIES(${TARGET_NAME} ${DEPENDENCY})
116 ENDFOREACH(DEPENDENCY)
117 ENDFUNCTION(WRT_TEST_ADD_INTERNAL_DEPENDENCIES)
119 # Functions used to build test targets (proper sources, includes, libs are
120 # added automatically)
121 FUNCTION(WRT_TEST_BUILD TARGET_NAME)
122 SET(SOURCES "${ARGN}")
123 ADD_EXECUTABLE("${TARGET_NAME}" ${SOURCES})
125 # get include dirs global property
126 GET_PROPERTY(INCLUDE_DIRS GLOBAL PROPERTY TESTS_INCLUDE_DIRS)
127 GET_PROPERTY(TEST_INCLUDE_DIRS GLOBAL PROPERTY ${TARGET_NAME}_INCLUDE_DIRS)
133 # get library dirs global property
134 GET_PROPERTY(LIBRARY_DIRS GLOBAL PROPERTY TESTS_LIBRARY_DIRS)
135 GET_PROPERTY(TEST_LIBRARY_DIRS GLOBAL PROPERTY ${TARGET_NAME}_LIBRARY_DIRS)
141 # get link libraries global property
142 GET_PROPERTY(LINK_LIBRARIES GLOBAL PROPERTY TESTS_LIBRARIES)
143 GET_PROPERTY(TEST_LIBRARIES GLOBAL PROPERTY ${TARGET_NAME}_LIBRARIES)
144 TARGET_LINK_LIBRARIES("${TARGET_NAME}"
148 ENDFUNCTION(WRT_TEST_BUILD)
150 FUNCTION(WRT_TEST_INSTALL)
151 SET_TARGET_PROPERTIES(${ARGV} PROPERTIES
152 BUILD_WITH_INSTALL_RPATH ON
153 INSTALL_RPATH_USE_LINK_PATH ON
155 INSTALL(TARGETS ${ARGV}
157 PERMISSIONS OWNER_READ
165 ENDFUNCTION(WRT_TEST_INSTALL)
167 # Takes arbitrary number of arguments and concatenates them using ':' character.
169 # CMake list when converted to a string is joined with ';' character. However,
170 # GCC takes strings with multiple elements separated with ':' (e.g. list of
171 # paths). Used typically when generating DB schemas with ORM mechanism.
172 FUNCTION(WRT_CONVERT_TO_GCC_LIST OUTPUT_VARIABLE)
173 FOREACH(ITEM ${ARGN})
174 LIST(APPEND ITEMS ${ITEM})
176 STRING(REPLACE ";" ":" OUTPUT "${ITEMS}")
177 SET("${OUTPUT_VARIABLE}" "${OUTPUT}" PARENT_SCOPE)
178 ENDFUNCTION(WRT_CONVERT_TO_GCC_LIST)