• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# CMakeLists for libyuv
2# Originally created for "roxlu build system" to compile libyuv on windows
3# Run with -DTEST=ON to build unit tests
4
5PROJECT ( YUV C CXX )	# "C" is required even for C++ projects
6CMAKE_MINIMUM_REQUIRED( VERSION 2.8.12 )
7OPTION( TEST "Built unit tests" OFF )
8
9SET ( ly_base_dir	${PROJECT_SOURCE_DIR} )
10SET ( ly_src_dir	${ly_base_dir}/source )
11SET ( ly_inc_dir	${ly_base_dir}/include )
12SET ( ly_tst_dir	${ly_base_dir}/unit_test )
13SET ( ly_lib_name	yuv )
14SET ( ly_lib_static	${ly_lib_name} )
15SET ( ly_lib_shared	${ly_lib_name}_shared )
16
17FILE ( GLOB_RECURSE	ly_source_files ${ly_src_dir}/*.cc )
18LIST ( SORT			ly_source_files )
19
20FILE ( GLOB_RECURSE	ly_unittest_sources ${ly_tst_dir}/*.cc )
21LIST ( SORT			ly_unittest_sources )
22
23INCLUDE_DIRECTORIES( BEFORE ${ly_inc_dir} )
24
25if(MSVC)
26  ADD_DEFINITIONS ( -D_CRT_SECURE_NO_WARNINGS )
27endif()
28
29# this creates the static library (.a)
30ADD_LIBRARY				( ${ly_lib_static} STATIC ${ly_source_files} )
31
32# this creates the shared library (.so)
33ADD_LIBRARY				( ${ly_lib_shared} SHARED ${ly_source_files} )
34SET_TARGET_PROPERTIES	( ${ly_lib_shared} PROPERTIES OUTPUT_NAME "${ly_lib_name}" )
35SET_TARGET_PROPERTIES	( ${ly_lib_shared} PROPERTIES PREFIX "lib" )
36if(WIN32)
37  SET_TARGET_PROPERTIES	( ${ly_lib_shared} PROPERTIES IMPORT_PREFIX "lib" )
38endif()
39
40# this creates the conversion tool
41ADD_EXECUTABLE			( yuvconvert ${ly_base_dir}/util/yuvconvert.cc )
42TARGET_LINK_LIBRARIES	( yuvconvert ${ly_lib_static} )
43
44
45INCLUDE ( FindJPEG )
46if (JPEG_FOUND)
47  include_directories( ${JPEG_INCLUDE_DIR} )
48  target_link_libraries( yuvconvert ${JPEG_LIBRARY} )
49  add_definitions( -DHAVE_JPEG )
50endif()
51
52if(TEST)
53  find_library(GTEST_LIBRARY gtest)
54  if(GTEST_LIBRARY STREQUAL "GTEST_LIBRARY-NOTFOUND")
55    set(GTEST_SRC_DIR /usr/src/gtest CACHE STRING "Location of gtest sources")
56    if(EXISTS ${GTEST_SRC_DIR}/src/gtest-all.cc)
57      message(STATUS "building gtest from sources in ${GTEST_SRC_DIR}")
58      set(gtest_sources ${GTEST_SRC_DIR}/src/gtest-all.cc)
59      add_library(gtest STATIC ${gtest_sources})
60      include_directories(${GTEST_SRC_DIR})
61      include_directories(${GTEST_SRC_DIR}/include)
62      set(GTEST_LIBRARY gtest)
63    else()
64      message(FATAL_ERROR "TEST is set but unable to find gtest library")
65    endif()
66  endif()
67
68  add_executable(libyuv_unittest ${ly_unittest_sources})
69  target_link_libraries(libyuv_unittest ${ly_lib_name} ${GTEST_LIBRARY})
70  find_library(PTHREAD_LIBRARY pthread)
71  if(NOT PTHREAD_LIBRARY STREQUAL "PTHREAD_LIBRARY-NOTFOUND")
72    target_link_libraries(libyuv_unittest pthread)
73  endif()
74  if (JPEG_FOUND)
75    target_link_libraries(libyuv_unittest ${JPEG_LIBRARY})
76  endif()
77
78  if(NACL AND NACL_LIBC STREQUAL "newlib")
79    target_link_libraries(libyuv_unittest glibc-compat)
80  endif()
81endif()
82
83
84# install the conversion tool, .so, .a, and all the header files
85INSTALL ( PROGRAMS ${CMAKE_BINARY_DIR}/yuvconvert			DESTINATION bin )
86INSTALL ( TARGETS ${ly_lib_static}						DESTINATION lib )
87INSTALL ( TARGETS ${ly_lib_shared} LIBRARY				DESTINATION lib RUNTIME DESTINATION bin )
88INSTALL ( DIRECTORY ${PROJECT_SOURCE_DIR}/include/		DESTINATION include )
89
90# create the .deb and .rpm packages using cpack
91INCLUDE ( CM_linux_packages.cmake )
92
93