-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeUtils.cmake
74 lines (66 loc) · 2.63 KB
/
CMakeUtils.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
function(doTargetsExists targets result)
set(${result} true PARENT_SCOPE)
foreach(target ${targets})
if(NOT TARGET ${target})
set(${result} false PARENT_SCOPE)
break()
endif()
endforeach()
endfunction()
function(addObjectLibrary name sources targets)
doTargetsExists("${targets}" prereq)
if(${prereq})
#SET(BUILD_LIB_${name} ON CACHE BOOL "should we build lib ${name}?")
option(BUILD_LIB_${name} "should we build lib ${name}?" ON)
if(BUILD_LIB_${name})
add_library(${name} STATIC ${sources})
target_include_directories(${name} PUBLIC $<INSTALL_INTERFACE:include>)
target_include_directories(${name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
target_link_libraries(${name} PUBLIC ${targets})
endif()
endif()
endfunction()
function(addHeaderLibrary name targets)
doTargetsExists("${targets}" prereq)
if(${prereq})
add_library(${name} INTERFACE)
target_include_directories(${name} INTERFACE $<INSTALL_INTERFACE:include>)
target_include_directories(${name} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
target_link_libraries(${name} INTERFACE ${targets})
endif()
endfunction()
function(addApp2 name srcs targets)
doTargetsExists("${targets}" prereq)
if(NOT ${prereq})
return()
endif()
option(BUILD_APP_${name} "should we build app ${name}?" ON)
if(BUILD_APP_${name})
add_executable(${name} ${srcs})
target_include_directories(${name} PUBLIC $<INSTALL_INTERFACE:include>)
target_include_directories(${name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
target_link_libraries(${name} PUBLIC ${targets})
set_target_properties(${name} PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_RPATH ${CMAKE_CURRENT_BINARY_DIR})
endif()
endfunction()
function(addApp3 name srcs targets output)
doTargetsExists("${targets}" prereq)
if(NOT ${prereq})
return()
endif()
option(BUILD_APP_${name} "should we build app ${name}?" ON)
if(BUILD_APP_${name})
add_executable(${name} ${srcs})
target_include_directories(${name} PUBLIC $<INSTALL_INTERFACE:include>)
target_include_directories(${name} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
target_link_libraries(${name} PUBLIC ${targets})
set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${output})
endif()
endfunction()
function(createTargetForBadLibrary name libraries includes)
if(NOT "${libraries}" STREQUAL "")
add_library(${name} INTERFACE)
target_link_libraries(${name} INTERFACE ${libraries})
target_include_directories(${name} INTERFACE $<BUILD_INTERFACE:${includes}>)
endif()
endfunction()