C , C++, C#
[Cmake] add_custom_target / .cmake file
vhxpffltm
2022. 5. 18. 23:00
한번의 명렁어로 여러 target은 cmake -B [build directory] --target all
과 같이 모든 target을 빌드할 것이다.
그런데 내가 좀더 구분짓고 싶은것은 일부 타겟만 빌드할수 없을까 이다.
그래서 Cmake를 조금 찾아보면 custom target을 통해 이를 해결할 수 있다.
그리고 이를 .cmake 파일을 통해 만들었다.
.cmake는 마치 스크립트와 같은 느낌으로 이해하면 되는데 function() 을 사용하여 CmakeLists.txt 에서 해당 function의 이름을 호출하면 실행되는 방식으로 이해할 수 있다.
위와 같이 CmakeLists.txt에 cmake 파일의 경로를 include하고 function의 이름으로 호출하면 .cmake 파일의 내용을 실행한다.
해당 내용은 아래와 같은데 add_custom_target키워드로 원하는 타켓만 빌드할 수 있도록 한다.
코드의 ${all_targets}은 directory property 속성을 list로 저장한 변수이다.
https://dev.to/iblancasa/learning-cmake-3-understanding-addcustomcommand-and-addcustomtarget-43gp
Learning CMake 3: creating custom targets
A different approach to learn CMake.
dev.to