-
Notifications
You must be signed in to change notification settings - Fork 73
/
nice_target_sources.cmake
79 lines (75 loc) · 3.71 KB
/
nice_target_sources.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
# This file is part of Desktop App Toolkit,
# a set of libraries for developing nice desktop applications.
#
# For license and copyright information please follow this link:
# https://github.com/desktop-app/legal/blob/master/LEGAL
function(nice_target_sources target_name src_loc)
set(writing_now "")
set(private_sources "")
set(public_sources "")
set(interface_sources "")
set(not_win_sources "")
set(not_mac_sources "")
set(not_linux_sources "")
foreach (entry ${ARGN})
if (${entry} STREQUAL "PRIVATE" OR ${entry} STREQUAL "PUBLIC" OR ${entry} STREQUAL "INTERFACE")
set(writing_now ${entry})
else()
set(full_name ${src_loc}/${entry})
if (${entry} MATCHES "(^|/)win/" OR ${entry} MATCHES "(^|/)winrc/" OR ${entry} MATCHES "(^|/)windows/" OR ${entry} MATCHES "[_\\/]win\\.")
list(APPEND not_mac_sources ${full_name})
list(APPEND not_linux_sources ${full_name})
elseif (${entry} MATCHES "(^|/)mac/" OR ${entry} MATCHES "(^|/)darwin/" OR ${entry} MATCHES "(^|/)osx/" OR ${entry} MATCHES "[_\\/]mac\\." OR ${entry} MATCHES "[_\\/]darwin\\." OR ${entry} MATCHES "[_\\/]osx\\.")
list(APPEND not_win_sources ${full_name})
list(APPEND not_linux_sources ${full_name})
elseif (${entry} MATCHES "(^|/)linux/" OR ${entry} MATCHES "[_\\/]linux\\.")
list(APPEND not_win_sources ${full_name})
list(APPEND not_mac_sources ${full_name})
elseif (${entry} MATCHES "(^|/)posix/" OR ${entry} MATCHES "[_\\/]posix\\.")
list(APPEND not_win_sources ${full_name})
endif()
if ("${writing_now}" STREQUAL "PRIVATE")
list(APPEND private_sources ${full_name})
elseif ("${writing_now}" STREQUAL "PUBLIC")
list(APPEND public_sources ${full_name})
elseif ("${writing_now}" STREQUAL "INTERFACE")
list(APPEND interface_sources ${full_name})
else()
message(FATAL_ERROR "Unknown sources scope for target ${target_name}")
endif()
if (${src_loc} MATCHES "/Resources$")
source_group(TREE ${src_loc} PREFIX Resources FILES ${full_name})
else()
source_group(TREE ${src_loc} PREFIX Sources FILES ${full_name})
endif()
endif()
endforeach()
if (NOT "${public_sources}" STREQUAL "")
target_sources(${target_name} PUBLIC ${public_sources})
endif()
if (NOT "${private_sources}" STREQUAL "")
target_sources(${target_name} PRIVATE ${private_sources})
endif()
if (NOT "${interface_sources}" STREQUAL "")
target_sources(${target_name} INTERFACE ${interface_sources})
endif()
if (WIN32)
set_source_files_properties(${not_win_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${not_win_sources} PROPERTIES SKIP_AUTOGEN TRUE)
elseif (APPLE)
set_source_files_properties(${not_mac_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${not_mac_sources} PROPERTIES SKIP_AUTOGEN TRUE)
elseif (LINUX)
set_source_files_properties(${not_linux_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${not_linux_sources} PROPERTIES SKIP_AUTOGEN TRUE)
endif()
endfunction()
function(remove_target_sources target_name src_loc)
set(sources "")
foreach (entry ${ARGN})
set(full_name ${src_loc}/${entry})
list(APPEND sources ${full_name})
endforeach()
set_source_files_properties(${sources} PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${sources} PROPERTIES SKIP_AUTOGEN TRUE)
endfunction()