CMake 从文件路径中提取文件名
FILE(GLOB_RECURSE SRC_FILES "*.c" "*.cc" "*.cpp" "*.h" "*.hpp") FOREACH(FILE_PATH ${SRC_FILES}) MESSAGE(${FILE_PATH}) STRING(REGEX REPLACE ".+/(.+)\\..*" "\\1" FILE_NAME ${FILE_PATH}) MESSAGE(${FILE_NAME}) ENDFOREACH(FILE_PATH)
示例:
E:/develop/glut_canvas/src/gl_graphic_base.cpp gl_graphic_base E:/develop/glut_canvas/src/glut_window.cpp glut_window E:/develop/glut_canvas/src/main.cpp main E:/develop/glut_canvas/src/gl_graphic_base.h gl_graphic_base E:/develop/glut_canvas/src/glut_window.h glut_window E:/develop/glut_canvas/src/point2d.h point2d E:/develop/glut_canvas/src/point2df.h point2df