xref: /aosp_15_r20/external/libyuv/CMakeLists.txt (revision 4e366538070a3a6c5c163c31b791eab742e1657a)
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( UNIT_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 cpuid tool
41ADD_EXECUTABLE      ( cpuid ${ly_base_dir}/util/cpuid.c )
42TARGET_LINK_LIBRARIES  ( cpuid ${ly_lib_static} )
43
44# this creates the conversion tool
45ADD_EXECUTABLE			( yuvconvert ${ly_base_dir}/util/yuvconvert.cc )
46TARGET_LINK_LIBRARIES	( yuvconvert ${ly_lib_static} )
47
48# this creates the yuvconstants tool
49ADD_EXECUTABLE      ( yuvconstants ${ly_base_dir}/util/yuvconstants.c )
50TARGET_LINK_LIBRARIES  ( yuvconstants ${ly_lib_static} )
51
52find_package ( JPEG )
53if (JPEG_FOUND)
54  include_directories( ${JPEG_INCLUDE_DIR} )
55  target_link_libraries( ${ly_lib_shared} ${JPEG_LIBRARY} )
56  add_definitions( -DHAVE_JPEG )
57endif()
58
59if(UNIT_TEST)
60  find_library(GTEST_LIBRARY gtest)
61  if(GTEST_LIBRARY STREQUAL "GTEST_LIBRARY-NOTFOUND")
62    set(GTEST_SRC_DIR /usr/src/gtest CACHE STRING "Location of gtest sources")
63    if (CMAKE_CROSSCOMPILING)
64      set(GTEST_SRC_DIR third_party/googletest/src/googletest)
65    endif()
66    if(EXISTS ${GTEST_SRC_DIR}/src/gtest-all.cc)
67      message(STATUS "building gtest from sources in ${GTEST_SRC_DIR}")
68      set(gtest_sources ${GTEST_SRC_DIR}/src/gtest-all.cc)
69      add_library(gtest STATIC ${gtest_sources})
70      include_directories(${GTEST_SRC_DIR})
71      include_directories(${GTEST_SRC_DIR}/include)
72      set(GTEST_LIBRARY gtest)
73    else()
74      message(FATAL_ERROR "UNIT_TEST is set but unable to find gtest library")
75    endif()
76  endif()
77
78  add_executable(libyuv_unittest ${ly_unittest_sources})
79  target_link_libraries(libyuv_unittest ${ly_lib_name} ${GTEST_LIBRARY})
80  find_library(PTHREAD_LIBRARY pthread)
81  if(NOT PTHREAD_LIBRARY STREQUAL "PTHREAD_LIBRARY-NOTFOUND")
82    target_link_libraries(libyuv_unittest pthread)
83  endif()
84  if (JPEG_FOUND)
85    target_link_libraries(libyuv_unittest ${JPEG_LIBRARY})
86  endif()
87
88  if(NACL AND NACL_LIBC STREQUAL "newlib")
89    target_link_libraries(libyuv_unittest glibc-compat)
90  endif()
91
92  find_library(GFLAGS_LIBRARY gflags)
93  if(NOT GFLAGS_LIBRARY STREQUAL "GFLAGS_LIBRARY-NOTFOUND")
94    target_link_libraries(libyuv_unittest gflags)
95    add_definitions(-DLIBYUV_USE_GFLAGS)
96  endif()
97endif()
98
99
100# install the conversion tool, .so, .a, and all the header files
101INSTALL ( PROGRAMS ${CMAKE_BINARY_DIR}/yuvconvert			DESTINATION bin )
102INSTALL ( TARGETS ${ly_lib_static}						DESTINATION lib )
103INSTALL ( TARGETS ${ly_lib_shared} LIBRARY				DESTINATION lib RUNTIME DESTINATION bin )
104INSTALL ( DIRECTORY ${PROJECT_SOURCE_DIR}/include/		DESTINATION include )
105
106# create the .deb and .rpm packages using cpack
107INCLUDE ( CM_linux_packages.cmake )
108
109