๋ฐ์ํ
๐ก ๋ณธ ๋ฌธ์๋ CMake๋ก ํ๊ฒฝ์ buildํ๋ ์ค ์ธ๋ถ์ ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ฐ์ ธ์ค๋ FetchContent๊ณผ์ ์ ๋ํด ์์ธํ ์ค๋ช ํฉ๋๋ค.
1. FetchContent
- FetchContent: 'configure time'์ ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ฐ์ ธ์ต๋๋ค(populating).
- configure time: CMake๋ฅผ ์คํํ๋ ์์
- ExternalProject_Add(): ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ 'build time'์ ๊ฐ์ ธ์ต๋๋ค.
- build time: makefile์ ํ์ฉํ์ฌ make ํ๋ ์์ .
- the FetchContent module makes content available immediately, allowing the configure step to use the content in commands like add_subdirectory(), include() or file() operations.
1.1 FetchContent ์ ์: ์ธ๋ถ ํ๋ก์ ํธ์ ์ ์ฅ์ ์ ์
typical example of declaring content details for some dependencies
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
)
then ensuring they are populated with a separate call: ์ธ๋ถ ํ๋ก์ ํธ ์ค์
- Default Population: performing the population using FetchContent_MakeAvailable()
- Costom Population: the lower level FetchContent_GetProperties() and FetchContent_Populate() commands can be used (ํ๋จ 'FetchContent Custom Population' ์ฐธ์กฐ)
1.1.1 FetchContent Default Population: FetchContent_MakeAvailable
include(FetchContent)
FetchContent_Declare(
<name>
<contentOptions>...
[OVERRIDE_FIND_PACKAGE |
FIND_PACKAGE_ARGS args...]
)
FetchContent_MakeAvilable(<name>)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
)
FetchContent_MakeAvailable(googletest)
- FetchContent_MakeAvailable : () ๋ด๋ถ์ ๋์๋ฌธ์ ํ์ฉ
1.1.2 FetchContent Custom Population: FetchContent_Populate
Content population details should be defined separately from the command that performs the actual population.
# NOTE: Where possible, prefer to use FetchContent_MakeAvailable()
# instead of custom logic like this
# Check if population has already been performed
FetchContent_GetProperties(${PROJECT_NAME})
if(NOT ${PROJECT_NAME}_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(${PROJECT_NAME})
# Set custom variables, policies, etc.
# ...
# Bring the populated content into the build
add_subdirectory(${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
endif()
- FetchContent_GetProperties : () ๋ด๋ถ์ ์๋ฌธ์๋ง ํ์ฉ
- FetchContent_Populate(${PROJECT_NAME})์ ํ๋ฉด PROJECT_SOURCE_DIR, PROJECT_BINARY_DIR๊ณผ ๊ฐ์ ๋ณ์๋ ์์ฑํด์ค๋๋ค. ๋ฐ๋ผ์ ๋ค์๊ณผ ๊ฐ์ ๋ณ์๋ฅผ ์ด์ฉํ๊ธฐ ์ํด์๋ MakeAvailable์ ์ฌ์ฉํ๋ฉด ์๋ฉ๋๋ค.
1.2 Example of FetchContent
message(STATUS "Fetching googletest...")
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0 # GCC 5.0 ๋ฏธ๋ง์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ is_trivially_copy_constructible ์ง์์ด ๋์ง ์์ผ๋ฏ๋ก 1.11.0 ์ดํ๋ ์ฌ์ฉ ๋ถ๊ฐ
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
set(gtest_build_tests OFF CACHE BOOL "Enable gtest tests" FORCE)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
- <name>_SOURCE_DIR: ./build/_deps/<name>-src"
- <name>_BINARY_DIR: ./build/_deps/<name>-build"
- EXCLUDE_FROM_ALL: /build/bin ํด๋์ ํ์ ์๋ binary file ์ปดํ์ผ์ ๋ง๊ธฐ ์ํด์ FetchContent_MakeAvailable ๋์ ์ FetchContent_GetProperties์ FetchContent_Populate๋ฅผ ์ฌ์ฉํด์ EXCLUDE_FROM_ALL ์ค์ ์ ํด์ฃผ๋ฉด ํ์์๋ ํ์ผ์ ์์ฑํ์ง ์๋๋ค.
+ FetchContent๋ฅผ ํตํด ์์ฑ๋ ํด๋ ๊ตฌ์กฐ
- <name>_SOURCE_DIR: ${CMAKE_CURRENT_BINARY_DIR}/<lowercaseName>-src
- ./build/_deps/<name>-src"
- ์ธ๋ถ ํ๋ก์ ํธ์ ์ ์ฅ์์ ์๋ ์ ์ฒด ํ์ผ
- <name>_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}/<lowercaseName>-build
- ./build/_deps/<name>-build"
- ์ธ๋ถ ํ๋ก์ ํธ๋ฅผ ๋น๋ํด์ ์ป์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ฐ *.cpp๋ฅผ ์ปดํ์ผํ *.o, *.o.d ํ์ผ๋ค
- <name>_SUBBUILD_DIR: ${CMAKE_CURRENT_BINARY_DIR}/<lowercaseName>-subbuild
- ./build/_deps/<name>-subbuild"
์ฐธ๊ณ
- [Official CMake] FatchContent: https://cmake.org/cmake/help/latest/module/FetchContent.html#integrating-with-find-package
- cmake source usage #187: https://github.com/open-source-parsers/jsoncpp/issues/187
- [runebook] FetchContent: https://runebook.dev/ko/docs/cmake/module/fetchcontent
- ๊ตฌ๊ธ ํ ์คํธ ํด์ ์ด์ฉํ UnitTest์ฉ CMakefile: https://object-world.tistory.com/25
๋ฐ์ํ
'Study: DeveloperTools(DevTool) > DevTool: CMake' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[CMake] function: ๋ฐ๋ณต๋๋ ์์ ์ ํจ์ํํ์! (0) | 2022.06.28 |
---|---|
[CMake] ํฌ๋ก์ค ํ๋ซํผ ๋น๋ ํ๊ฒฝ ๊ตฌ์ถ (0) | 2022.06.24 |
[CMake] Effective Modern CMake ์ ๋ฆฌ (0) | 2022.06.24 |
[CMake] An Introduction to Modern CMake ์ ๋ฆฌ (0) | 2022.06.24 |
[CMake] CMake ์๊ฐ ๋ฐ ํ์์ฑ: Modern CMake 3.23+ (0) | 2022.06.24 |