I have two CMake projects on macOS - the main project and an external library. Both projects are cloned on my machine. I want to add the external library as a dependency to the main project. I also want to make the main project build the external library. Is that possible with CMake?
P.S. All examples that I have found are downloading the external library first.
EDIT:
ExternalProject_Add(<lib_name>
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/<rel_path_to_src>
BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/<rel_path_to_build_dir>
BUILD_ALWAYS ON)
This is my ExternalProject_Add. But I am not sure how to properly link the library so it can be built before the main project.
I tried to link as follows:
find_library( LIB <lib_name> HINTS ${CMAKE_CURRENT_SOURCE_DIR}/<rel_path_to_lib_dir>)
target_link_libraries( ${PROJECT_NAME} PRIVATE ${LIB} )
I receive the following error:
ninja: error: '<path_to_lib>/lib.a', needed by '<executable>', missing and no known rule to make it