CMake/Find library

From Sidvind
Jump to: navigation, search
Code: FindFoo.cmake
IF (WIN32)
	FIND_PATH( FOO_INCLUDE_PATH foo/foo.h
		$ENV{PROGRAMFILES}/foo-0.1/include
		DOC "The directory where foo/foo.h resides")
	FIND_LIBRARY( FOO_LIBRARY
		NAMES foo
		PATHS
		$ENV{PROGRAMFILES}/foo-0.1/lib
		DOC "The Foo library")
ELSE (WIN32)
	FIND_PATH( FOO_INCLUDE_PATH foo/foo.h
		/usr/include
		/usr/local/include
		/sw/include
		/opt/local/include
		DOC "The directory where foo/foo.h resides")
	FIND_LIBRARY( FOO_LIBRARY
		NAMES foo
		PATHS
		/usr/lib64
		/usr/lib
		/usr/local/lib64
		/usr/local/lib
		/sw/lib
		/opt/local/lib
		DOC "The Foo library")
ENDIF (WIN32)

IF (FOO_INCLUDE_PATH)
	SET( FOO_FOUND 1 CACHE STRING "Set to 1 if Foo is found, 0 otherwise")
ELSE (FOO_INCLUDE_PATH)
	SET( FOO_FOUND 0 CACHE STRING "Set to 1 if Foo is found, 0 otherwise")
ENDIF (FOO_INCLUDE_PATH)

MARK_AS_ADVANCED( FOO_FOUND )
Code: CMakeLists.txt
MESSAGE(STATUS "Looking for Foo")
INCLUDE(FindFoo.cmake)
IF(FOO_FOUND)
	MESSAGE(STATUS "Looking for Foo - found")
ELSE(FOO_FOUND)
	MESSAGE(FATAL_ERROR "Looking for Foo - not found")
ENDIF(FOO_FOUND)