forked from ARMinARM/stm32flash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libbuilder.cmake
59 lines (55 loc) · 1.81 KB
/
libbuilder.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
#! func for create static lib
# \flag:LOG - [optional] if set func print other data
# \param:LNAME - [optional] static lib name, if not defined set like folder name
# \group:SRCS - [must] source of lib
# \group:INCLUDE - [optional] path to headers
# \group:PRIV_REQ - [optional] private libs req
# \group:PUB_REQ - [optional] public libs req
#
function(SLIB_INIT)
cmake_parse_arguments(
slib
"LOG"
"LNAME"
"SRCS;INCLUDE;PRIV_REQ;PUB_REQ"
${ARGN}
)
# check LNAME and SRCS exist
if(NOT DEFINED slib_LNAME)
get_filename_component(slib_LNAME ${CMAKE_CURRENT_LIST_DIR} NAME)
# message(FATAL_ERROR "lib name must be defined")
endif()
if(NOT DEFINED slib_SRCS)
message(FATAL_ERROR "lib sources must be defined")
endif()
if(slib_LOG)
message("\n")
message("LNAME:\t" ${slib_LNAME})
message("SRCS:\t" ${slib_SRCS})
message("INCLUDE:\t" ${slib_INCLUDE})
message("PRIV_REQ:\t" ${slib_PRIV_REQ})
message("PUB_REQ:\t" ${slib_PUB_REQ})
message("\n")
endif()
add_library(${slib_LNAME} STATIC ${slib_SRCS})# Create static lib
if(DEFINED slib_INCLUDE)
# add public include dir
target_include_directories(${slib_LNAME}
PUBLIC ${slib_INCLUDE}
)
endif()
# link private and public libs
target_link_libraries(${slib_LNAME}
PRIVATE ${slib_PRIV_REQ}
PUBLIC ${slib_PUB_REQ}
)
endfunction(SLIB_INIT)
function(SUBDIRS)
foreach(spath IN ITEMS ${ARGN})
# message(STATUS ${spath})
file(GLOB subsubdirs RELATIVE_PATH ${spath}/*)
foreach(subdirs IN ITEMS ${subsubdirs})
add_subdirectory(${subdirs})
endforeach()
endforeach()
endfunction(SUBDIRS)