《cmake调用shell》

2023-05-16

1. CMakeLists.txt

add_custom_target(config ALL
    COMMAND bash x.sh  
)

2. shell

#########################################################################
# File Name: x.sh
# Author: XXDK
# Created Time: Wed 01 Nov 2017 05:08:50 PM CST
#########################################################################

#!/bin/bash

# masking all out put info!
set +x 

#-----------------------------------------------
# function fprint()
#-----------------------------------------------
fprint() 
{
	#if [ 1 ] 
	if [ ! 1 ] 
	then
		echo -n "Func: $FUNCNAME Line: $LINENO " && echo $1;
	fi
}

#-----------------------------------------------
# global variable value
#-----------------------------------------------
exec_path=`pwd`;
fprint "exec_path: $exec_path";

config_file_path=`cd ../config_file; pwd`;
fprint "config_file_path: $config_file_path";

src_root_path=`cd ../; pwd`;
fprint "src_root_path: $src_root_path";

out_directory="$src_root_path/out";
fprint "out_directory: $out_directory";

config_file_list=`cd ../config_file; ls`;
config_file_common='config_file_common.conf';
out_dir_com_prefix='cleanna';
config_file_count=0;

#-----------------------------------------------
# function total_config_file() 
#-----------------------------------------------
clean_out_directory()
{
	if [ -d ../out ]
	then
		rm ../out -rf;
	fi
}
#-----------------------------------------------
# function total_config_file() 
#-----------------------------------------------
total_config_file() 
{
	for file in $config_file_list
	do
		if [ -f $1/$file ]
		then 
			config_file_count=`expr $config_file_count + 1`;
			fprint $file;
		fi
	done 

	return $config_file_count;
}

#-----------------------------------------------
# function check_file_exist() 
#-----------------------------------------------
check_file_exist()  
{
	if [ -f $1 ]
	then
		fprint "get $1";
		return 1;
	else 
		fprint "no $1";
		return 0;
	fi
}

#-----------------------------------------------
# function create_out_directory() 
#-----------------------------------------------
create_out_directory() 
{
	if [ ! -d $1 ]
	then
		mkdir $1;
		fprint "create $1 success!";
		return 1;
	else 
		fprint "$1 already exist!";
		return 0;
	fi
}

#-----------------------------------------------
# function process_config_file()
#-----------------------------------------------
process_config_file() 
{
	local target_dir=$1;
	if [ ! -d "$target_dir/app" ]  # out/cleannaXXXX/app
	then 
		mkdir "$target_dir/app";
		touch "$target_dir/app/config_file.conf"; #out/cleannaXXXX/app/config_file.conf
		cat "$config_file_path/$config_file_common" > "$target_dir/app/config_file.conf";
		cat "$config_file_path/$file" >> "$target_dir/app/config_file.conf";
		return 1;
	else 
		fprint "$target_dir/app already exist!";
		return 0;
	fi
}

#-----------------------------------------------
# function process_bootauto_file()
#-----------------------------------------------
process_bootauto_file() 
{
	local target_dir=$1;
	if [ ! -d "$target_dir/boot" ]  # out/cleannaXXXX/boot
	then 
		mkdir "$target_dir/boot";
		check_file_exist "$config_file_path/boot/BootAuto.sh"
		if [ $? = 1 ] 
		then 
			#out/cleannaXXXX/boot/BootAuto.sh
			cp "$config_file_path/boot/BootAuto.sh" "$target_dir/boot"; 
			return 1;
		else 
			fprint "check $config_file_path/boot/BootAuto.sh error";
			return 0;
		fi
	else 
		fprint "$target_dir/boot/BootAuto.sh already exist!";
		return 0;
	fi
}

#-----------------------------------------------
# function process_small_vex_file()
#-----------------------------------------------
process_small_vex_file() 
{
	local target_dir=$1;
	check_file_exist "$config_file_path/small_voc.txt.compressed"
	if [ $? = 1 ] 
	then 
		#out/cleannaXXXX/app/small_voc.txt.compressed
		cp "$config_file_path/small_voc.txt.compressed" "$target_dir/app"; 
		return 1;
	else 
		fprint "check $config_file_path/small_voc.txt.compressed error";
		return 0;
	fi
}

#-----------------------------------------------
# function process_small_vex_file()
#-----------------------------------------------
process_sta_wifi_file() 
{
	local target_dir=$1
	check_file_exist "$config_file_path/boot/sta_wifi_common.sh"
	if [ $? = 1 ] 
	then 
		#out/cleannaXXXX/boot/sta_wifi.sh
		cp "$config_file_path/boot/sta_wifi_common.sh" "$target_dir/boot/sta_wifi.sh"; 
		return 1;
	else 
		fprint "check $config_file_path/boot/sta_wifi_common.sh error";
		return 0;
	fi
}

#-----------------------------------------------
# function print_out_directory() 
#-----------------------------------------------
print_out_directory() 
{
	out_config_file_dir=`cd ../out; ls`;
	for dir in "$out_config_file_dir"
	do 
		fprint $dir;
	done 
}

#-----------------------------------------------
# function main_task() 
#-----------------------------------------------
main_task() 
{
	for file in $config_file_list
	do
		if [ -f "$config_file_path/$file" ]
		then 
			if [ ${file#*.} = "conf" ] #extract file which has ".conf" suffix
			then
				file_no_conf_suffix=${file%.*}; #discard suffix ".conf"
				fprint ${file_no_conf_suffix};
				file_no_cfc_prefix=${file_no_conf_suffix##*_}; #cfc confile_file_cleanna_
				fprint ${file_no_cfc_prefix};

				if [ ! -d "$out_directory""/""$out_dir_com_prefix""$file_no_cfc_prefix" ]
				then 
					local target_dir="$out_directory""/""$out_dir_com_prefix""$file_no_cfc_prefix";    # out/cleannaXXXX/
					mkdir $target_dir;    # out/cleannaXXXX/
					# 1. config_file 
					process_config_file $target_dir;
					if [ $? = 1 ]; then 
						fprint "process config file success!";
					else 
						fprint "process config file failed!";
					fi
					# 2. boot 
					process_bootauto_file $target_dir;
					if [ $? = 1 ]; then 
						fprint "process bootauto file success!";
					else 
						fprint "process bootauto file failed!";
					fi
					# 3. small_voc
					process_small_vex_file $target_dir;
					if [ $? = 1 ]; then 
						fprint "process small_voc file success!";
					else 
						fprint "process small_voc file failed!";
					fi
					# 4. sta_wifi
					process_sta_wifi_file $target_dir;
					if [ $? = 1 ]; then 
						fprint "process sta_wifi file success!";
					else 
						fprint "process sta_wifi file failed!";
					fi
				else 
					fprint ""$out_directory""/""$out_dir_com_prefix""$file_no_cfc_prefix" already exist!";
					return 0;
				fi
			fi
			config_file_count=`expr $config_file_count + 1`;
			fprint $file;
		fi
	done 
	return 1;
}

#-----------------------------------------------
# function main() 
#-----------------------------------------------
main() 
{
	# 1.---------------------------------------
	clean_out_directory;

	# 2.---------------------------------------
	total_config_file $config_file_path;
	if [ $? = 0 ]; then 
		fprint "no config file to process!";
	else 
		fprint "total config file: $? ";
	fi
	
	# 3.---------------------------------------
	check_file_exist "$config_file_path/$config_file_common" 
	if [ $? = 1 ]; then 
		fprint "config_file_common.sh check pass!";
	else 
		fprint "can't find config_file_common.sh";
	fi

	# 4.---------------------------------------
	create_out_directory "$out_directory";
	if [ $? = 1 ]; then 
		fprint "Create roboserver/out directory ok";
	else 
		fprint "Create roboserver/out directory error";
	fi

	# 5.---------------------------------------
	main_task;
}

#-----------------------------------------------
# running extry main
#-----------------------------------------------
#set +x
while true
do 
	main;
	break;
done 
set -x








本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

《cmake调用shell》 的相关文章

  • bash双括号问题

    我对 bash 脚本非常陌生 在使用双括号时遇到了问题 我似乎无法让它们在 Ubuntu Server 11 10 中工作 我的下面的脚本位于 if test sh 中 bin bash if 14 14 then echo FOO fi
  • 如何拆分一行并重新排列其元素?

    我在一行中有一些数据 如下所示 abc edf xyz rfg yeg udh 我想呈现如下数据 abc xyz yeg edf rfg udh 以便打印备用字段并用换行符分隔 有没有这样的衬里 下列awk脚本可以做到这一点 gt echo
  • 使用 sed 将 old-link-url 替换为 new-link-url

    我正在 bash 中编写一个脚本 将 old link url 替换为 new link url 我的问题是 sed 由于斜杠而无法替换 url 如果我只输入一些文字就可以了 my code sed e s old link new lin
  • MySQL C++ 连接器未解决的依赖关系(VS 2015)

    我正在尝试在 Windows Visual Studio 2015 上编译 MySQL Connector C 我根据以下内容使用CMake生成了项目文件官方说明 https dev mysql com doc connector cpp
  • 让 Emacs ansiterm 和 Zsh 更好地发挥作用

    我一直在尝试在 emacs 会话中使用 Zsh 而无需 emacs 重新映射所有 Zsh 键 我发现 ansi term 对此非常有效 但是我仍然遇到一些问题 我输出了很多垃圾字符 我可以用以下方法修复它 Setup proper term
  • 如何在bash中仅提取两个字符串之间多行的第一个实例?

    我的文件是 abc 123 xyz abc 675 xyz 我想提取 abc 123 xyz 123 可以是任何东西 重点是我想要第一次出现 我尝试使用这个 sed n abc xyz p filename 但这给了我所有的例子 我怎样才能
  • shell脚本“x$VARIABLE”中x的用途[重复]

    这个问题在这里已经有答案了 我正在查看一些 shell 脚本 comarison shcu 中 x 的用途是什么 if x USER x RUN AS USER then su RUN AS USER c CATALINA HOME bin
  • cmake 不会在更改时重建 externalProject

    我有以下 CMakeLists txt cmake minimum required VERSION 3 0 project addProject include ExternalProject set ExternalProjectCMa
  • Bash 脚本 - 迭代 find 的输出

    我有一个 bash 脚本 其中需要迭代 find 命令输出的每一行 但似乎我正在迭代 find 命令中的每个单词 以空格分隔 到目前为止我的脚本看起来像这样 folders find maxdepth 1 type d for i in f
  • 列出破折号中当前定义的函数?

    我想列出当前定义的函数dash 有什么办法可以做到这一点吗 我能想到的最接近的是type它可以用来测试一个函数是否存在 但除此之外我很困惑 附 我说的是dash在这里 不是bash or zsh 看看 exec c 似乎没有 没有 表是静态
  • CMake 中的 FindSDL2 发生了什么?

    我在游戏中使用 SDL2 我一直使用自定义 FindSDL2 cmake 因为标准 CMake 集中没有 然而 前段时间确实出现了有关 FindSDL2 的帖子 例子 红迪网帖子 https www reddit com r opengl
  • 如何调用位于其他目录的Makefile?

    我正在尝试这样做 我想打电话给 make Makefile存在于其他目录中 abc可以使用位于不同目录中的 shell 脚本的路径 我该怎么做呢 由于 shell 脚本不允许我cd进入Makefile目录并执行make 我怎样才能编写she
  • CMake Xcode生成器创建了一个无法构建的项目

    我有一个使用 CMake 构建系统的 C 项目 我使用 MacBook Pro 进行开发 因此当我使用终端时 一切都非常顺利 我可以构建我的项目 然而 今天我发现我可以在使用 CMake 生成器创建相应的项目后使用 Xcode gt cma
  • 如何将命令作为参数传递给 ssh [重复]

    这个问题在这里已经有答案了 我的需要是让这个命令起作用 sshpass p XXXX ssh oStrictHostKeyChecking no email protected cdn cgi l email protection sudo
  • Linux shell 脚本:十六进制数字到二进制字符串

    我正在 shell 脚本中寻找一些简单的方法来将十六进制数字转换为 0 和 1 字符的序列 Example 5F gt 01011111 是否有任何命令或简单的方法来完成它 或者我应该为其编写一些开关 echo ibase 16 obase
  • 给出 5 个参数,但在终端中只得到 3 个参数

    我想将一个文件传递给一个c 程序 如果我在 IDE 中执行此操作 test string string lt test txt return argc 5 但在终端上我刚刚得到argc 3 看来 这是因为 什么是 lt 意思是 我正在使用
  • shell_exec 的输出被截断为 100 个字符

    当在 shell 中运行以下命令时 curl F file filename http 192 168 0 1 产生以下输出 Accuracy 0 0 1 classification Accuracy 0 0 1 classificati
  • xsel -o 对于 OS X 等效项

    是否有一个等效的解决方案可以在 OS X 中抓取选定的文本 就像适用于 Linux 的 xsel o 一样 只需要当前的选择 这样我就可以在 shell 脚本中使用文本 干杯 埃里克 你也许可以安装xsel在 MacOS 上 更新 根据 A
  • 在bash中,是否有相当于“错误消息”的东西

    在 perl 中 您可以使用错误消息退出die some msg bash 中是否有等效的单个命令 现在 我正在使用命令来实现这一点 echo some msg exit 1 你可以很容易地自己推出 die echo 1 gt 2 exit
  • 如何使用我在 github 中发布的 bash 脚本执行 chsh?

    我有一个要点 我总是用它来在新服务器上安装我需要的软件包 http gist github com 4372049 http gist github com 4372049 我需要做的就是通过 ssh 在新服务器中输入以下内容 bash c

随机推荐