-
Notifications
You must be signed in to change notification settings - Fork 0
/
reason.add_executable.cmake
81 lines (71 loc) · 3.11 KB
/
reason.add_executable.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
function(reason__add_executable__tinclude_dirs TARGET_NAME INC_DIRS)
reason_verbose(" target_include_directories:")
# Handle include directories
foreach(INC_DIR IN LISTS INC_DIRS)
set(build_interface "${CMAKE_CURRENT_LIST_DIR}/${INC_DIR}")
target_include_directories("${TARGET_NAME}" PRIVATE "$<BUILD_INTERFACE:${build_interface}>")
reason_verbose(" [private-include=${build_interface}]")
endforeach()
target_include_directories("${TARGET_NAME}" PRIVATE "$<INSTALL_INTERFACE:include>")
reason_verbose(" [private-include=\"$<INSTALL_INTERFACE:include>\"]")
endfunction()
function(reason__add_executable__tlink_libs TARGET_NAME LINKS)
foreach(LINK IN LISTS LINKS)
# Handle Dependencies' include dirs
reason_extract_dependency_properties_to_target("${TARGET_NAME}" "${LINK}")
# Link it finally
target_link_libraries("${TARGET_NAME}" PRIVATE "${LINK}")
reason_verbose(" target_link_libraries:")
reason_verbose(" [private-link=${LINK}]")
endforeach()
endfunction()
function(reason__add_executable__compile_define TARGET_NAME DEFINES)
target_compile_definitions("${TARGET_NAME}" PRIVATE "${DEFINES}")
foreach(DEFINE IN LISTS DEFINES)
reason_verbose(" target_compile_definitions: [private-define=${DEFINE}]")
endforeach()
endfunction()
function(reason__add_executable__set_rpath TARGET_NAME)
# Handle RPATH
set_target_properties("${TARGET_NAME}" PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")
set_target_properties("${TARGET_NAME}" PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
reason_verbose("${TARGET_NAME} set rpath: [rpath='$ORIGIN/../lib']")
endfunction()
function(reason__add_executable__use_cotire TARGET_NAME)
# Use cotire if available
if(COMMAND cotire AND REASON_USE_COTIRE)
cotire("${TARGET_NAME}")
reason_verbose("${TARGET_NAME} cotire applied")
endif()
endfunction()
function(reason_add_executable)
set(options HELP)
set(one_value_args TARGET FN MODE)
set(mlt_value_args INC_DIRS SRCS LINKS DEFINES)
cmake_parse_arguments(reason "${options}" "${one_value_args}" "${mlt_value_args}" "${ARGN}")
if(reason_HELP)
reason_print_help_file("${REASON_MODULE_DIR}/reason.add_executable.help")
endif()
reason_set_check(reason_TARGET "You must specify a TARGET when using 'reason_add_executable'")
reason_set_check(reason_SRCS "You probably forgot to list the sources when using 'reason_add_executable'")
reason_check_incompatible(reason_FN reason_MODE)
if(reason_MODE)
set(REASON_MODE_FILE "${REASON_MODULE_DIR}/reason.add_executable.${reason_MODE}.cmake")
if(NOT EXISTS "${REASON_MODE_FILE}")
reason_message(FATAL_ERROR "reason mode '${reason_MODE}' for 'reason_add_executable' does not exist!")
endif()
reason_verbose("Use MODE=${reason_MODE}")
include("${REASON_MODE_FILE}")
reason__add_executable__impl()
return()
endif()
if(reason_FN)
set(FN_ADD_EXECUTABLE "${reason_FN}")
else()
set(FN_ADD_EXECUTABLE "add_executable")
endif()
reason_util_configure_and_include(
"reason.add_executable.in.cmake"
"reason.add_executable.${FN_ADD_EXECUTABLE}.out.cmake")
reason__add_executable__impl()
endfunction()