我们已经介绍过单目录结构与多目录结构的CMakeLists.txt使用方法,下面介绍如何利用CMakeLists实现类似于C++模板的东西。下面的内容与单目录结构以及多目录结构CMakeLists实现密接相关,建议看完前两个再看这一篇。
应用场景
开发某个基于C语言的项目,要求实现单精度与双精度计算版本。
目录结构
|--examples
| |--add_example.c
| |--sub_example.c
| |--CMakeLists.txt
|--CMakeLists.txt
|--include
| |--alg.h
|--alg
| |--add
| | |--add.c
| | |--CMakeLists.txt
| |--sub
| | |--sub.c
| | |--CMakeLists.txt
| |--CMakeLists.txt
| |--utils
| | |--alg_template.h
其中examples/add_example.c
#include "alg.h"
#include<stdio.h>
int main(){
double a = 1.1, b = 2.1;
printf("add:%lf\n", my_add64(a, b));
return 0;