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