ITK cmake 添加多个基于ITK的可执行文件

发布时间 2023-07-13 14:34:38作者: 一杯清酒邀明月

1、CMakeLists.txt

 1 cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
 2 project(testfilter)
 3 set(ITK_DIR D:/ProgramFiles/ITK-5.2/lib/cmake/ITK-5.2)
 4 
 5 FIND_PACKAGE(ITK REQUIRED)
 6 INCLUDE(${ITK_USE_FILE})
 7 
 8 file(GLOB_RECURSE mains ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
 9 message(STATUS ${mains})
10 foreach(mainfile IN LISTS mains)
11     # Get file name without directory
12     get_filename_component(mainname ${mainfile} NAME_WE)
13     add_executable(${mainname} ${mainfile})
14     target_link_libraries (${mainname} ${ITK_LIBRARIES})
15 endforeach()

2、get_filename_component 用法

get_filename_component
1 DIRECTORY = Directory without file name
2 NAME      = File name without directory
3 EXT       = File name longest extension (.b.c from d/a.b.c)
4 NAME_WE   = File name with neither the directory nor the longest extension
5 LAST_EXT  = File name last extension (.c from d/a.b.c)
6 NAME_WLE  = File name with neither the directory nor the last extension
7 PATH      = Legacy alias for DIRECTORY (use for CMake <= 2.8.11)