1cmake_minimum_required(VERSION 2.8)
2project(kms++)
3
4include(LTO.cmake)
5
6set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
7set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
8set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
9
10include(CheckCXXCompilerFlag)
11
12IF(NOT CMAKE_BUILD_TYPE)
13    message(STATUS "Setting build type to 'Release' as none was specified.")
14    SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
15    set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
16ENDIF()
17
18string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
19
20option(BUILD_SHARED_LIBS "Build shared libs" FALSE)
21option(TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" FALSE)
22
23set(KMSXX_ENABLE_PYTHON ON CACHE BOOL "Enable Python wrappers")
24set(KMSXX_PYTHON_VERSION "python3;python2" CACHE STRING "Python pkgconfig package")
25
26set(KMSXX_ENABLE_KMSCUBE OFF CACHE BOOL "Enable kmscube")
27
28set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall")
29set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra -Wno-unused-parameter")
30
31set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
32set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wno-unused-parameter")
33
34if (CMAKE_COMPILER_IS_GNUCC)
35    if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
36        # GCC 4.x seems to warn too much
37        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers")
38    endif()
39endif()
40
41# HACK: cmake always adds "-rdynamic", this removes it
42SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
43SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
44
45set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
46
47if (TREAT_WARNINGS_AS_ERRORS)
48    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
49    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
50endif()
51
52# static link libc
53# set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
54
55check_lto()
56
57if (NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
58    if (LTO_WORKS)
59        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
60        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
61        set(CMAKE_AR "${LTO_AR}")
62        set(CMAKE_RANLIB "${LTO_RANLIB}")
63    endif()
64endif()
65
66find_package(PkgConfig REQUIRED)
67pkg_check_modules(LIBDRM libdrm>=2.4.64 REQUIRED)
68
69pkg_check_modules(LIBDRM_OMAP libdrm_omap)
70if(LIBDRM_OMAP_FOUND)
71    add_definitions(-DHAS_LIBDRM_OMAP)
72endif()
73
74enable_testing()
75
76add_subdirectory(kms++)
77add_subdirectory(kms++util)
78add_subdirectory(utils)
79
80if(KMSXX_ENABLE_KMSCUBE)
81	add_subdirectory(kmscube)
82endif()
83
84if(KMSXX_ENABLE_PYTHON)
85        add_subdirectory(py)
86endif()
87
88add_custom_target(docs SOURCES "README.md")
89