I have an external dependency (headers and shared libraries as well as version.txt
file in a known install location) for my project. This dependency has no built-in support for CMake find_package()
. After reading the find_package()
docs and this SO answer, my understanding is that I should use module mode for find_package()
. In the Find*.cmake
cmake
directory, my guess is that it should:
- Setup and verify paths to the header and shared libraries
- Read in the version file
- Define a project using the version file text
- Add an interface library target (
${PROJECT_NAME}
) - Add an alias to the interface library using a namespace (
${MY_NAMESPACE}
) - Add a library target for each shared library path
- Set the imported path property for each shared library
- Link the shared libraries to the interface library target
- Link the include directory to the interface library target
export(TARGETS ${PROJECT_NAME} NAMESPACE ${MY_NAMESPACE}::)
export(PACKAGE ${PROJECT_NAME})
- Profit?
Am I doing this right and/or taking the right approach?