@@ -7,6 +7,26 @@ include(GNUInstallDirs)
77
88set (myci_private_output_dir "${CMAKE_BINARY_DIR} /exe" )
99
10+ ####
11+ # @brief Make absolute path from relative path.
12+ # The absolute path is constructed relatively to CMAKE_CURRENT_LIST_DIR.
13+ # @param out - variable name which receives the resulting absolute path.
14+ # @param relative_path - relative path to get absolute path for.
15+ function (myci_abs_path out relative_path )
16+ file (REAL_PATH
17+ # PATH
18+ "${relative_path} "
19+ # OUTPUT
20+ absolute_path
21+ BASE_DIRECTORY
22+ ${CMAKE_CURRENT_LIST_DIR}
23+ EXPAND_TILDE
24+ )
25+
26+ set (${out} ${absolute_path} PARENT_SCOPE )
27+ endfunction ()
28+
29+
1030# try to find package by config first and if it fails try by module
1131function (myci_private_find_package package )
1232 set (options REQUIRED QUIET)
@@ -117,15 +137,7 @@ function(myci_add_source_files out)
117137 list (APPEND patterns "${arg_DIRECTORY} /*${pattern} " )
118138 endforeach ()
119139
120- file (REAL_PATH
121- # PATH
122- "${arg_DIRECTORY} "
123- # OUTPUT
124- abs_path_directory
125- BASE_DIRECTORY
126- ${CMAKE_CURRENT_LIST_DIR}
127- EXPAND_TILDE
128- )
140+ myci_abs_path (abs_path_directory ${arg_DIRECTORY} )
129141
130142 if (arg_RECURSIVE)
131143 set (glob GLOB_RECURSE)
@@ -456,15 +468,7 @@ function(myci_private_copy_resource_file_command out target_name src_dir file)
456468 string (REPLACE "/" "\\ " path "Generated Files/${path} " )
457469 source_group ("${path} " FILES "${outfile} " )
458470
459- file (REAL_PATH
460- # PATH
461- "${src_dir} /${file} "
462- # OUTPUT
463- abs_src_file
464- BASE_DIRECTORY
465- ${CMAKE_CURRENT_LIST_DIR}
466- EXPAND_TILDE
467- )
471+ myci_abs_path (abs_src_file "${src_dir} /${file} " )
468472
469473 add_custom_command (
470474 OUTPUT
@@ -893,29 +897,13 @@ function(myci_declare_library name)
893897
894898 foreach (dir ${arg_PUBLIC_INCLUDE_DIRECTORIES} )
895899 # absolute path is needed by target_include_directories()
896- file (REAL_PATH
897- # PATH
898- "${dir} "
899- # OUTPUT
900- abs_path_directory
901- BASE_DIRECTORY
902- ${CMAKE_CURRENT_LIST_DIR}
903- EXPAND_TILDE
904- )
900+ myci_abs_path (abs_path_directory "${dir} " )
905901 target_include_directories (${name} ${public} $<BUILD_INTERFACE :${abs_path_directory} >)
906902 endforeach ()
907903
908904 foreach (dir ${arg_PRIVATE_INCLUDE_DIRECTORIES} )
909905 # absolute path is needed by target_include_directories()
910- file (REAL_PATH
911- # PATH
912- "${dir} "
913- # OUTPUT
914- abs_path_directory
915- BASE_DIRECTORY
916- ${CMAKE_CURRENT_LIST_DIR}
917- EXPAND_TILDE
918- )
906+ myci_abs_path (abs_path_directory "${dir} " )
919907 target_include_directories (${name} ${private} $<BUILD_INTERFACE :${abs_path_directory} >)
920908 endforeach ()
921909
@@ -933,15 +921,7 @@ function(myci_declare_library name)
933921 )
934922
935923 if (arg_RESOURCE_DIRECTORY)
936- file (REAL_PATH
937- # PATH
938- "${arg_RESOURCE_DIRECTORY} "
939- # OUTPUT
940- abs_path_directory
941- BASE_DIRECTORY
942- ${CMAKE_CURRENT_LIST_DIR}
943- EXPAND_TILDE
944- )
924+ myci_abs_path (abs_path_directory "${arg_RESOURCE_DIRECTORY} " )
945925
946926 get_filename_component (dirname "${arg_RESOURCE_DIRECTORY} " NAME )
947927
@@ -1210,15 +1190,7 @@ function(myci_declare_application name)
12101190 else ()
12111191 set (res_target_name ${name} __copy_resources)
12121192
1213- file (REAL_PATH
1214- # PATH
1215- "${arg_RESOURCE_DIRECTORY} "
1216- # OUTPUT
1217- abs_path_directory
1218- BASE_DIRECTORY
1219- ${CMAKE_CURRENT_LIST_DIR}
1220- EXPAND_TILDE
1221- )
1193+ myci_abs_path (abs_path_directory "${arg_RESOURCE_DIRECTORY} " )
12221194
12231195 myci_private_declare_resource_pack (${res_target_name}
12241196 APP_TARGET
@@ -1298,15 +1270,7 @@ function(myci_add_subdirectory source_dir)
12981270 set (multiple)
12991271 cmake_parse_arguments (arg "${options} " "${single} " "${multiple} " ${ARGN} )
13001272
1301- file (REAL_PATH
1302- # PATH
1303- "${source_dir} "
1304- # OUTPUT
1305- abs_source_dir
1306- BASE_DIRECTORY
1307- ${CMAKE_CURRENT_LIST_DIR}
1308- EXPAND_TILDE
1309- )
1273+ myci_abs_path (abs_source_dir ${source_dir} )
13101274
13111275 get_property (added_dirs GLOBAL PROPERTY myci_added_subdirectories )
13121276
0 commit comments