Make the cmake check_lib macro more versatile. It first tries pkg-config, and if that fails it then check for libraries and required headers. Also cleaned up the output a little bit.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6544 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice
2010-12-10 02:00:05 +00:00
parent c718d2e630
commit 06013d5eec
4 changed files with 83 additions and 61 deletions

View File

@ -29,9 +29,6 @@ if(Subversion_FOUND AND NOT DOLPHIN_WC_REVISION)
Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} DOLPHIN) # defines DOLPHIN_WC_REVISION
endif()
# TODO: Make this optional or even implement our own package detection
include(FindPkgConfig REQUIRED)
# Various compile flags
add_definitions(-msse2 -Wall)
@ -96,6 +93,8 @@ endif(CMAKE_BUILD_TYPE STREQUAL Release)
# be needed by users is optional defaulting to ON, other stuff (like e.g.
# sound backends) is completely optional.
include(CheckLib)
include(FindOpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
@ -108,7 +107,7 @@ else()
message("ALSA NOT found, disabling ALSA sound backend")
endif(ALSA_FOUND)
pkg_search_module(AO ao)
check_lib(AO ao QUIET)
if(AO_FOUND)
add_definitions(-DHAVE_AO=1)
include_directories(${AO_INCLUDE_DIRS})
@ -118,7 +117,7 @@ else()
message("ao NOT found, disabling ao sound backend")
endif(AO_FOUND)
pkg_search_module(BLUEZ bluez)
check_lib(BLUEZ bluez QUIET)
if(BLUEZ_FOUND)
add_definitions(-DHAVE_BLUEZ=1)
include_directories(${BLUEZ_INCLUDE_DIRS})
@ -128,7 +127,7 @@ else()
message("bluez NOT found, disabling bluetooth support")
endif(BLUEZ_FOUND)
pkg_search_module(PULSEAUDIO libpulse)
check_lib(PULSEAUDIO libpulse QUIET)
if(PULSEAUDIO_FOUND)
add_definitions(-DHAVE_PULSEAUDIO=1)
include_directories(${PULSEAUDIO_INCLUDE_DIR})
@ -162,28 +161,16 @@ else()
add_definitions(-DHAVE_X11=0)
endif()
pkg_search_module(XRANDR xrandr)
check_lib(XRANDR Xrandr)
if(XRANDR_FOUND)
add_definitions(-DHAVE_XRANDR=1)
message("Xrandr found")
else()
add_definitions(-DHAVE_XRANDR=0)
message("Xrandr NOT found")
endif(XRANDR_FOUND)
option(ENCODE_FRAMEDUMPS "Encode framedumps in AVI format" ON)
if(ENCODE_FRAMEDUMPS)
pkg_search_module(AVCODEC libavcodec>=52.72.2)
pkg_search_module(AVFORMAT libavformat>=52.64.2)
pkg_search_module(SWSCALE libswscale>=0.11.0)
if(AVCODEC_FOUND AND AVFORMAT_FOUND AND SWSCALE_FOUND)
message("libav found, enabling AVI frame dumps")
set(ENCODE_FRAMEDUMPS ON)
add_definitions(-DHAVE_AVCODEC)
else()
set(ENCODE_FRAMEDUMPS OFF)
message("libav not found, disabling AVI frame dumps")
endif()
check_libav()
endif()
find_program(XDG_SCREENSAVER xdg-screensaver)
@ -251,9 +238,7 @@ include_directories(Externals/Bochs_disasm)
add_subdirectory(Externals/Lua)
include_directories(Externals/Lua)
include(CheckLib)
check_lib_and_header(LZO lzo2 lzo/lzo1x.h OPTIONAL)
check_lib(LZO lzo2 lzo/lzo1x.h QUIET)
if(LZO_FOUND)
message("Using shared lzo")
include_directories(${LZO_INCLUDE})
@ -274,7 +259,7 @@ else(SDL_FOUND)
add_subdirectory(Externals/SDL)
endif(SDL_FOUND)
check_lib_and_header(SFML sfml-network SFML/Network/Ftp.hpp OPTIONAL)
check_lib(SFML sfml-network SFML/Network/Ftp.hpp QUIET)
if(SFML_FOUND)
message("Using shared sfml-network")
include_directories(${SFML_INCLUDE})
@ -284,7 +269,7 @@ else()
include_directories(Externals/SFML/include)
endif()
check_lib_and_header(SOIL SOIL SOIL/SOIL.h OPTIONAL)
check_lib(SOIL SOIL SOIL/SOIL.h QUIET)
if(SOIL_FOUND)
message("Using shared SOIL")
include_directories(${SOIL_INCLUDE})
@ -294,8 +279,13 @@ else()
include_directories(Externals/SOIL)
endif()
include(FindZLIB OPTIONAL)
# If zlib has already been found on a previous run of cmake don't check again
# as the check seems to take a long time.
if(NOT ZLIB_FOUND)
include(FindZLIB OPTIONAL)
endif()
if(ZLIB_FOUND)
set(ZLIB_FOUND 1 CACHE INTERNAL "")
message("Using shared zlib")
include_directories(${ZLIB_INCLUDE_DIRS})
else(ZLIB_FOUND)
@ -308,17 +298,18 @@ if(WIN32)
find_library(GLEW glew32s PATHS Externals/GLew)
include_directories(Externals/GLew/include)
else()
check_lib(GLU glu REQUIRED)
check_lib_and_header(GLEW GLEW GL/glew.h OPTIONAL)
check_lib_and_header(CG Cg Cg/cg.h OPTIONAL)
check_lib_and_header(CGGL CgGL Cg/cgGL.h OPTIONAL)
endif()
check_lib(GLU GLU GL/glu.h REQUIRED)
if(NOT GLEW_FOUND)
message("Shared GLEW not found, falling back to the static library")
add_subdirectory(Externals/GLew)
include_directories(Externals/GLew/include)
endif(NOT GLEW_FOUND)
check_lib(GLEW GLEW GL/glew.h)
if(NOT GLEW_FOUND)
message("Shared GLEW not found, falling back to the static library")
add_subdirectory(Externals/GLew)
include_directories(Externals/GLew/include)
endif(NOT GLEW_FOUND)
check_lib(CG Cg Cg/cg.h)
check_lib(CGGL CgGL Cg/cgGL.h)
endif()
if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
include_directories(Externals/CLRun/include)
@ -328,6 +319,7 @@ endif()
option(DISABLE_WX "Disable wxWidgets (use CLI interface)" OFF)
if(NOT DISABLE_WX)
include(FindwxWidgets OPTIONAL)
FIND_PACKAGE(wxWidgets COMPONENTS aui)
if(wxWidgets_FOUND)
include(${wxWidgets_USE_FILE})