其他分享
首页 > 其他分享> > DirectFB编译环境

DirectFB编译环境

作者:互联网

原文链接:https://my.oschina.net/fuyajun1983cn/blog/263964

DirectFB是用于嵌入式平台的一个2D图形库,主要面向嵌入式平台。不过,也支持在PC平台进行开发,测试相关功能,只要对应的Linux支持FrameBuffer设备。


本文以DirectFB源码自带的例子的编译介绍编译环境的搭建,使用版本为1.2.9

使用CMake作为编译工具。 

由于CMake默认并没有定义查找DirectFB头文件以及库的module,所以我们必须首先定义查找DirectFB的Find模块,该模块名我们设定为:FindDirectFB.cmake.

文件内容如下:

# try to find directfb.h

set(HEADER_SEARCH_PATHS "/usr/include/directfb" "/usr/include/directfb-internal")

find_path(
	DFB_INCLUDE_DIRS directfb.h
	PATHS ${HEADER_SEARCH_PATHS}
	NO_DEFAULT_PATH
)
if(NOT EXISTS ${DFB_INCLUDE_DIRS})
	find_path(DFB_INCLUDE_DIRS directfb.h)
endif()

# try to find the DFB library
find_library(
	DFB_LIBRARIES NAMES directfb
	PATHS ${LIBRARY_SEARCH_PATHS}
	NO_DEFAULT_PATH
)
if(NOT DFB_LIBRARIES)
	find_library(DFB_LIBRARIES directfb)
endif()

if(EXISTS ${DFB_INCLUDE_DIRS})
	set(DFB_FOUND true)
else()
	set(DFB_FOUND false)
endif()

该模块定义了如下变量:${DFB_INCLUDE_DIRS}代表DirectFB对应的头文件路径。 ${DFB_LIBRARIES}代表DirectFB对应的库文件路径。 


这样我们就可以在源码的顶级目录下创建如下的CMakeLists.txt文件了:

cmake_minimum_required(VERSION 2.8)

project(DirectFBTest)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})

set(DATA_DIR "${PROJECT_SOURCE_DIR}/data")
set(FONT_FILE  "${PROJECT_SOURCE_DIR}/data/decker.ttf")
set(DEMO_VERSION "1.4.9")

configure_file(
  "${PROJECT_SOURCE_DIR}/src/config.h.in"
  "${PROJECT_BINARY_DIR}/config.h"
   )

include_directories("${PROJECT_BINARY_DIR}")

find_package(DirectFB)
if (NOT DFB_FOUND)
   message(FATAL_ERROR "failed to find directfb")
   return()
endif()

include_directories(${DFB_INCLUDE_DIRS})

add_subdirectory(src)

 其中config.h.in文件的内容如下:

#define DATADIR "@DATA_DIR@"
#define FONT    "@FONT_FILE@"
#define VERSION  "@DEMO_VERSION@"

这样,src目录下的CMakeLists.txt的内容可以写成如下形式(仅仅示例):

file(GLOB EXAMPLES "${CMAKE_CURRENT_SOURCE_DIR}/df_*.c")
foreach(EXAMPLE_PATH ${EXAMPLES})
    get_filename_component(EXAMPLE_NAME "${EXAMPLE_PATH}" NAME_WE)
    if ("${EXAMPLE_NAME}" STREQUAL "df_texture")
	set(EXTRA_FILE ve.c)
    endif()
    add_executable(${EXAMPLE_NAME} ${EXAMPLE_PATH} ${EXTRA_FILE})
    target_link_libraries(${EXAMPLE_NAME} ${DFB_LIBRARIES} m)
endforeach()

这样,我们就可以通过CMake来编译这些例子了。


Wiki:  CMake Cross Compiling

转载于:https://my.oschina.net/fuyajun1983cn/blog/263964

标签:set,环境,编译,directfb,DirectFB,find,DIR,DFB
来源: https://blog.csdn.net/chijiandao3197/article/details/100930654