상세 컨텐츠

본문 제목

[CMAKE] set_source_files_properties() / get_source_file_property()

cmake

by 빨간눈동자 2021. 11. 3. 20:00

본문

반응형
# first we add the executable that generates the table
add_executable(MakeTable MakeTable.cxx)

# add the command to generate the source code
add_custom_command (
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  DEPENDS MakeTable
  COMMAND MakeTable
  ARGS ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  )

set_source_files_properties (
  mysqrt.cxx PROPERTIES
  OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  )

get_source_file_property(LJH mysqrt1.cxx OBJECT_DEPENDS)
message("-------------------------")
message(${LJH})
message("-------------------------")

# add the binary tree directory to the search path for include files
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )

# add the main library
add_library(MathFunctions mysqrt.cxx)

 

set_source_files_properties()을 사용하면 특정 파일에 속성을 부여할 수 있다. 

위 예제를 살펴보면, 

 

set_source_files_properties (
  mysqrt.cxx PROPERTIES
  OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  )

 

mysqrt.cxx 파일에 "OBJECT_DEPENDS" 라는 속성을 만들고, 그 속성에 "${CMAKE_CURRENT_BINARY_DIR}/Table.h" 라는 값을 할당한다는 의미이다. 

 

이후 필요할 때 이 파일의 속성 값을 읽기 위해서는 

get_source_file_property()를 사용하여 아래와 같이 쓰면 된다. 

 

get_source_file_property(LJH mysqrt1.cxx OBJECT_DEPENDS)
message("-------------------------")
message(${LJH})
message("-------------------------")

 

위 내용은 myhsqrt.cxx 파일의 OBJECT_DEPENDS 라는 속성을 읽어 LJH 변수에 저장하라는 의미이다. 

LJH 변수에 set_source_files_properties()로 설정한 값을 잘 읽었는지 확인해보자. 

 

set_source_files_properties() 에서 ${CMAKE_CURRENT_BINARY_DIR}/Table.h을 할당하였으며, 

get_source_file_property에서 "/home/jaeho/cmake/Tests/Tutorial/Step6/build/MathFunctions/Table.h" 가 잘 출력됨을 확인하였다.

 

 

만약 mysqrt.cxx 파일명을 변경한다면, ( mysqrt.cxx -> test.cxx ) 

 

 17 get_source_file_property(LJH test.cxx OBJECT_DEPENDS)
 18 message("-------------------------")
 19 message(${LJH})
 20 message("-------------------------")

 

해당 파일(test.cxx)에는 그런 속성이 없음을 출력하게 된다. 

 

// Case#1	
set_property(SOURCE mysqrt.cxx PROPERTY TMP ${CMAKE_CURRENT_BINARY_DIR}/a.h)
get_property(LJH SOURCE mysqrt.cxx PROPERTY TMP)

// Case#2
set_source_files_properties (
  mysqrt.cxx PROPERTIES
  OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Table.h
)
get_source_file_property(LJH1 mysqrt.cxx OBJECT_DEPENDS)

message("-------------------------")
message(${LJH})
message(${LJH1})
message("-------------------------")

 

Case#1과 Case#2는 동일한 의미를 가진다. 

즉, set_property()/get_property()의 다양한 option을 세분화 한 것이 set_source_files_properties() / get_source_file_property()로 생각하면 된다.

반응형

'cmake' 카테고리의 다른 글

[CMAKE] include()  (0) 2024.06.26
[CMAKE] set_target_properties() / get_target_property()  (0) 2021.11.03
[CMAKE] find_path() ( 환경변수 참조.. )  (0) 2021.11.03
[CMAKE] file()  (0) 2021.11.03
[CMAKE] add_custom_command()  (0) 2021.11.03

관련글 더보기