macro(MacroFindOrBuild PACKAGE PACKAGE_PATH IS_GIT_SUBMODULE) add_custom_target(${PACKAGE}) if (NOT ${PACKAGE}_BUILD_FROM_SOURCE) find_package(${PACKAGE}) endif() if (NOT ${PACKAGE}_FOUND) set(${PACKAGE}_BUILD_FROM_SOURCE TRUE) message(STATUS "could not find package ${PACKAGE}, building from source") add_custom_target(${PACKAGE}_BUILD DEPENDS ${PACKAGE}_BUILD.stamp) add_dependencies(${PACKAGE} ${PACKAGE}_BUILD) set(${PACKAGE}_FOUND TRUE) if (${IS_GIT_SUBMODULE}) message(STATUS "${PACKAGE} detected as git submodule, will attempt to initialize it") list(APPEND GIT_SUBMODULES ${PACKAGE_PATH}) add_dependencies(${PACKAGE}_BUILD GIT) endif() endif() endmacro(MacroFindOrBuild)