CMakeLists.txt
c
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文件
c
#include <stdio.h>
#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__);
}
结果
c
liuwen@liuwen-VirtualBox:~/test/cmake/02-1-use_static_lib/build$ ./static_use
[123123:hello.c: 18] hello word