Development

CMake - 3부 (설치와 테스트)

chbae 2023. 4. 18. 06:05
728x90
반응형

CMake 2부에 이어 3부를 계속 이어 나간다. 필자는 http://www.cmake.org/cmake-tutorial/ 의 내용을 정리하고 있다.

Step 3: 설치와 테스트

MathFunctions 라이브러리와 헤더 파일 설치한다. 아래는 MathFunctions의 CMakeLists 파일에 추가한다. Tutorial 이지만 라이브러린데 설치가 bin 디렉토리일까??? (단순 의문)

1:  install (TARGETS MathFunctions DESTINATION bin)  
2:  install (FILES MathFunctions.h DESTINATION include)

아래는 main application을 위한 설치 경로 지정에 대한 내용을 최상위 CMakeLists 파일에 추가한다. 참고로 CMake 변수인 CMAKE_INSTALL_PREFIX는 설치 경로의 root를 설정할 수 있다. 즉 설치를 위한 prefix이다.

1:  # add the install targets  
2:  install (TARGETS Tutorial DESTINATION bin)  
3:  install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"      
4:       DESTINATION include)

지금부터는 테스트 관련 내용이다. 최상위 CMakeLists 파일 제일 아래 application이 정상적으로 동작하는지 아래와 같은 테스트 할 수 있는 부분을 추가할 수 있다. 아래 예제는 단순 application이 잘 동작하는지, segfault, crash, zero return value에 대한 간단한 테스트에 대한 것이다. 이것은 CTest 의 기본이다. PASS_REGULAR_EXPRESSION는 테스트된 결과값이 맞는지 확인하는 데 사용한다.

1:  # does the application run  
2:  add_test (TutorialRuns Tutorial 25)  
3:  # does it sqrt of 25  
4:  add_test (TutorialComp25 Tutorial 25)  
5:  set_tests_properties (TutorialComp25   
6:   PROPERTIES PASS_REGULAR_EXPRESSION "25 is 5")  
7:  # does it handle negative numbers  
8:  add_test (TutorialNegative Tutorial -25)  
9:  set_tests_properties (TutorialNegative  
10:   PROPERTIES PASS_REGULAR_EXPRESSION "-25 is 0")  
11:  # does it handle small numbers  
12:  add_test (TutorialSmall Tutorial 0.0001)  
13:  set_tests_properties (TutorialSmall  
14:   PROPERTIES PASS_REGULAR_EXPRESSION "0.0001 is 0.01")  
15:  # does the usage message work?  
16:  add_test (TutorialUsage Tutorial)  
17:  set_tests_properties (TutorialUsage  
18:   PROPERTIES   
19:   PASS_REGULAR_EXPRESSION "Usage:.*number")

위는 일부 입력값에 대한 결과 들이고, 다른 입력값에 대한 여러 테스트를 원하면 아래와 같이 macro를 만들어 사용하는 것도 좋다.

1:  #define a macro to simplify adding tests, then use it  
2:  macro (do_test arg result)  
3:   add_test (TutorialComp${arg} Tutorial ${arg})  
4:   set_tests_properties (TutorialComp${arg}  
5:    PROPERTIES PASS_REGULAR_EXPRESSION ${result})  
6:  endmacro (do_test)  
7:  # do a bunch of result based tests  
8:  do_test (25 "25 is 5")  
9:  do_test (-25 "-25 is 0")
728x90

'Development' 카테고리의 다른 글

Jenkins Job Description에서 HTML 사용하기  (0) 2023.04.18
CMake - 4부 (시스템 검사) - 마지막  (0) 2023.04.18
CMake - 2부 (라이브러리 추가)  (0) 2023.04.18
CMake - 1부 (Tutorial 시작)  (0) 2023.04.18
ack (ack-grep)  (0) 2023.04.18