Created
August 14, 2024 10:18
-
-
Save anderay/d1c724a67bd3e55190db54dbef252ed7 to your computer and use it in GitHub Desktop.
CMake local package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| When project contains several subprojects in subdirectories then problem with common packages might appear. | |
| Common for gtest - structure | |
| > Root | |
| - CMakeLists.txt | |
| > source | |
| > test | |
| - CMakeLists.txt | |
| > gtest | |
| - CMakeLists.txt | |
| > dependencies | |
| > dependency1 (requires gtest) | |
| - CMakeLists.txt | |
| Here 'test' and 'dependency1' both require 'gtest' via 'find_package(GTest REQUIRED)'. | |
| In root CMakeLists.txt gtest is added using 'add_subdirectory(getest EXCLUDE_FROM_ALL)', similarly other dependencies. | |
| During build gtest will not be found in 'dependency1' (since GTestConfig.cmake is created after find_package() is executed). | |
| To overcome: | |
| - add 'set(GTest_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake CACHE PATH "Path to GTest package config file")' | |
| - cerate empty 'GTestConfig.cmake' file in 'cmake' directory under 'Root' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment