-
Notifications
You must be signed in to change notification settings - Fork 0
/
ETISSCMakeFunctions.cmake
112 lines (104 loc) · 3.88 KB
/
ETISSCMakeFunctions.cmake
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
macro(ETISS_LIST_INSERT _list_)
foreach(_ETISS_MACRO_E ${ARGN})
list(FIND ${_list_} "${_ETISS_MACRO_E}" _ETISS_MACRO_FOUND)
if (${_ETISS_MACRO_FOUND} GREATER -1)
else()
list(APPEND ${_list_} "${_ETISS_MACRO_E}")
endif()
endforeach()
endmacro()
macro(ETISS_GET_GLOBAL_VARS DESTINATION_VARIABLE)
list(APPEND ${DESTINATION_VARIABLE} "ETISS_FILES_SRC")
list(APPEND ${DESTINATION_VARIABLE} "ETISS_FILES_LIB")
list(APPEND ${DESTINATION_VARIABLE} "ETISS_FILES_DLL")
list(APPEND ${DESTINATION_VARIABLE} "ETISS_FILES_LNK")
list(APPEND ${DESTINATION_VARIABLE} "ETISS_LIBRARIES")
list(APPEND ${DESTINATION_VARIABLE} "ETISS_INCLUDE_DIRS")
endmacro()
# copies local variables to the parent scope
macro(ETISS_UPDATE_GLOBAL_VARIABLES)
ETISS_GET_GLOBAL_VARS(_ETISS_MACRO_GVARS)
foreach(_ETISS_MACRO_TMP ${_ETISS_MACRO_GVARS})
set(${_ETISS_MACRO_TMP} ${${_ETISS_MACRO_TMP}} PARENT_SCOPE)
endforeach()
endmacro()
function(ETISS_TO_MAKEFILE_LIST DESTINATION_VARIABLE)
unset(${DESTINATION_VARIABLE})
foreach(arg ${ARGN})
if (arg MATCHES ".* .*")
if (arg MATCHES "\".*\"")
set(${DESTINATION_VARIABLE} "${${DESTINATION_VARIABLE}} ${arg}")
else()
set(${DESTINATION_VARIABLE} "${${DESTINATION_VARIABLE}} \"${arg}\"")
endif()
else()
set(${DESTINATION_VARIABLE} "${${DESTINATION_VARIABLE}} ${arg}")
endif()
endforeach()
set(${DESTINATION_VARIABLE} ${${DESTINATION_VARIABLE}} PARENT_SCOPE)
endfunction()
function(ETISS_TO_MAKEFILE_LIBRARIES DESTINATION_VARIABLE)
unset(${DESTINATION_VARIABLE})
foreach(arg ${ARGN})
if (arg MATCHES "-l.*") # already in the right form for a Makefile
list(APPEND ${DESTINATION_VARIABLE} "${arg}")
elseif (arg MATCHES "-L.*") # already in the right form for a Makefile
list(APPEND ${DESTINATION_VARIABLE} "${arg}")
elseif (arg MATCHES ".*${CMAKE_STATIC_LIBRARY_PREFIX}[^/\\\\]+${CMAKE_STATIC_LIBRARY_SUFFIX}") # static library
list(APPEND ${DESTINATION_VARIABLE} "${arg}")
else() # shared library
get_filename_component(argp "${arg}" PATH)
if (argp)
list(APPEND ${DESTINATION_VARIABLE} "-L${argp}")
endif()
get_filename_component(argf "${arg}" NAME_WE)
STRING(REGEX REPLACE "^${CMAKE_SHARED_LIBRARY_PREFIX}" "" argf ${argf})
list(APPEND ${DESTINATION_VARIABLE} "-l${argf}")
endif()
endforeach()
ETISS_TO_MAKEFILE_LIST(DESTINATION_VARIABLE_TMP ${${DESTINATION_VARIABLE}})
set(${DESTINATION_VARIABLE} ${DESTINATION_VARIABLE_TMP} PARENT_SCOPE)
endfunction()
#don't call this function! use ETISS(ADD_LIBRARY "yourlibrary") instead
function(ETISS_ADD_LIBRARY)
set(options OPTIONAL)
cmake_parse_arguments(TMP "${options}" "" "" ${ARGN} )
foreach(arg ${TMP_UNPARSED_ARGUMENTS})
if (arg MATCHES "^-l.*")
message("Trimmed library name from ${arg} ...")
string(SUBSTRING ${arg} 2 -1 arg)
message(" ... to ${arg}")
endif()
unset(FOUND)
find_library(FOUND ${arg})
if (ETISS_ADD_LIBARY_OPTIONAL)
if (NOT FOUND)
message(INFO "Library ${arg} could not be found. The optinal library will not be added.")
else()
ETISS_LIST_INSERT(ETISS_FILES_LNK ${arg})
ETISS_LIST_INSERT(ETISS_LIBRARIES ${arg})
#list(APPEND ETISS_FILES_LNK ${arg})
#list(APPEND ETISS_LIBRARIES ${arg})
endif()
else()
if (NOT FOUND)
message(ERROR "Library ${arg} could not be found. This may lead to problems.")
endif()
ETISS_LIST_INSERT(ETISS_FILES_LNK ${arg})
ETISS_LIST_INSERT(ETISS_LIBRARIES ${arg})
endif()
endforeach()
ETISS_UPDATE_GLOBAL_VARIABLES()
endfunction()
#NOTE: automatically copies global etiss variables to the parent scope if needed
macro(ETISS CURRENT_COMMAND)
if ("${CURRENT_COMMAND}" STREQUAL "ADD_LIBRARY")
ETISS_ADD_LIBRARY(${ARGN})
else()
message(FATAL_ERROR "Unknown command passed to the ETISS function: " ${CURRENT_COMMAND})
endif()
get_directory_property(_ETISS_MACRO_hasParent PARENT_DIRECTORY)
if(_ETISS_MACRO_hasParent)
ETISS_UPDATE_GLOBAL_VARIABLES()
endif()
endmacro()