只打印文名

CMakeLists.txt

set(CMAKE_C_FLAGS "-O0 -ggdb -D__NOTDIR_FILE__=$(notdir $<)")
// set(CMAKE_C_FLAGS "-O0 -ggdb -D__NOTDIR_FILE__=$(notdir $<) -D__FILENAME__=$(subst $(dir $<),,$<)")

C文件

#include 

#ifdef __NOTDIR_FILE__
#define M2STR(x) #x
#define M2STR_IMPL(x) M2STR(x)
#define __BFILE__ M2STR_IMPL(__NOTDIR_FILE__)
#else
#define __BFILE__ __FILE__
#endif

void hello()
{
	printf("[%s:%s: %d] hello word\n", "123123", __BFILE__, __LINE__);
}

结果

liuwen@liuwen-VirtualBox:~/test/cmake/02-1-use_static_lib/build$ ./static_use
[123123:hello.c: 18] hello word

你可能感兴趣的:(笔记,c#,开发语言)