MacroFindOrBuild.cmake 709 Bytes
Newer Older
Pixhawk's avatar
Pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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)