-
Notifications
You must be signed in to change notification settings - Fork 0
/
targoman.cmake
72 lines (64 loc) · 2.66 KB
/
targoman.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
# Targoman CMake module: functions facilitating a clean building structure
#
# @author Behrooz Vedadian <vedadian@gmail.com>
function(tg_setup_buildsystem_paths)
get_directory_property(has_parent_directory PARENT_DIRECTORY)
if(has_parent_directory)
return()
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/bin" PARENT_SCOPE)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/lib" PARENT_SCOPE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/lib/static" PARENT_SCOPE)
set(CMAKE_INCLUDE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/include" PARENT_SCOPE)
include_directories(./out/include)
link_directories(./out/lib/static ./out/lib)
message("Setting up build system done :)")
endfunction()
function(tg_add_library)
add_library(${ARGN})
endfunction()
function(tg_add_library_headers target_name type)
list(TRANSFORM ARGN STRIP OUTPUT_VARIABLE headers)
list(JOIN headers ";" headers)
set_target_properties(${target_name} PROPERTIES ${type} "${headers}")
endfunction()
function(tg_export_public_headers target_name)
get_target_property(public_headers ${target_name} PUBLIC_HEADER)
foreach(public_header ${public_headers})
get_filename_component(basename ${public_header} NAME)
configure_file(${public_header} ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}/${target_name}/${basename} COPYONLY)
endforeach(public_header)
endfunction()
function(tg_get_all_targets var)
set(targets)
tg_get_all_targets_recursive(targets ${CMAKE_SOURCE_DIR})
set(${var} ${targets} PARENT_SCOPE)
endfunction()
macro(tg_get_all_targets_recursive targets dir)
get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
foreach(subdir ${subdirectories})
tg_get_all_targets_recursive(${targets} ${subdir})
endforeach()
get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
list(APPEND ${targets} ${current_targets})
endmacro()
function(tg_set_cxx_flags_for_current_targets)
get_property(current_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS)
foreach(target_name ${current_targets})
target_compile_options(${target_name} PRIVATE ${ARGN})
endforeach()
endfunction()
function(tg_process_all_targets)
get_directory_property(has_parent_directory PARENT_DIRECTORY)
if(has_parent_directory)
return()
endif()
set(all_targets)
tg_get_all_targets(all_targets)
foreach(target ${all_targets})
get_target_property(target_type ${target} TYPE)
if(target_type MATCHES "_LIBRARY$")
tg_export_public_headers(${target})
endif()
endforeach()
endfunction()