• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 3.18)
2
3include(CMake/Version.cmake)
4
5include(GoogleTest)
6enable_testing()
7# Disable test discovery after build.
8# By default, `gtest_discover_tests()` add a post-build step to run test executables in order to
9# discover the test targets. This is problematic in some build environments. (for example: if
10# cross-compiling)
11set(CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE "PRE_TEST")
12
13option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
14
15if (AEMU_COMMON_GEN_PKGCONFIG)
16   set(LOGGING_LIB_NAME aemu-logging)
17   set(SNAPSHOT_LIB_NAME aemu-snapshot)
18else()
19   set(LOGGING_LIB_NAME logging-base)
20   set(SNAPSHOT_LIB_NAME gfxstream-snapshot)
21endif()
22
23project(AEMUCommon
24        DESCRIPTION "Android emulation utilities library"
25        VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
26        LANGUAGES CXX C)
27
28set(AEMU_COMMON_REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
29
30if(NOT ANGLE_REPO_ROOT)
31    set(ANGLE_REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../external/angle)
32endif()
33
34option(AEMU_COMMON_GEN_PKGCONFIG
35       "Generate install files used by pkg-config."
36       OFF)
37option(ENABLE_CLANG_THREAD_SAFETY_CHECKS
38       "Enable clang thread-safety checks (-Wthread-safety)."
39       OFF)
40option(AEMU_COMMON_USE_PERFETTO "Use perfotto for tracing." OFF)
41option(AEMU_BASE_USE_LZ4 "The lz4 dependency is provided, and compile the compressing stream." OFF)
42
43if (WIN32)
44    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
45else()
46    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O3")
47endif()
48set(CMAKE_POSITION_INDEPENDENT_CODE ON)
49set(CMAKE_CXX_STANDARD 17)
50set(CMAKE_C_STANDARD 11)
51
52if (MSVC)
53    # ask msvc not to warn not secure C ISO functions
54    add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
55    # ask msvc not to warn non C ISO POSIX functions
56    add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE)
57endif()
58
59# Set AEMU_BUILD_CONFIG_NAME to use a custom cmake build script located in
60# build-config/$AEMU_BUILD_CONFIG_NAME. If AEMU_BUILD_CONFIG_NAME is unset,
61# it will default to building everything. See build-config/gfxstream/CMakeLists.txt
62# for an example.
63if (NOT ${AEMU_COMMON_BUILD_CONFIG} STREQUAL "")
64    if (NOT EXISTS "${AEMU_COMMON_REPO_ROOT}/build-config/${AEMU_COMMON_BUILD_CONFIG}")
65        message(FATAL_ERROR "build-config/${AEMU_COMMON_BUILD_CONFIG} does not exist")
66    endif()
67    message(STATUS "aemu-common: Using custom build script in \
68${AEMU_COMMON_REPO_ROOT}/build-config/${AEMU_COMMON_BUILD_CONFIG}")
69    add_subdirectory(build-config/${AEMU_COMMON_BUILD_CONFIG})
70endif()
71
72set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-extern-c-compat -Wno-return-type-c-linkage")
73
74add_subdirectory(base)
75add_subdirectory(snapshot)
76add_subdirectory(host-common)
77add_subdirectory(third-party)
78
79add_library(aemu_common INTERFACE)
80target_link_libraries(
81    aemu_common
82    INTERFACE
83    aemu-base
84    aemu-base.headers
85    aemu-host-common
86    aemu-host-common.headers)
87
88if(AEMU_COMMON_GEN_PKGCONFIG)
89    include(GNUInstallDirs)
90    set(INSTALL_PC_FILES
91        aemu_base
92        aemu_logging
93        aemu_host_common
94        aemu_snapshot)
95    if(ENABLE_VKCEREAL_TESTS)
96        list(APPEND INSTALL_PC_FILES aemu_base_testing_support aemu_host_common_testing_support)
97    endif()
98    foreach(PC_FILE IN LISTS INSTALL_PC_FILES)
99        configure_file(CMake/${PC_FILE}.pc.in ${PC_FILE}.pc @ONLY)
100        install(
101            FILES "${CMAKE_CURRENT_BINARY_DIR}/${PC_FILE}.pc"
102            DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
103    endforeach()
104
105    install(DIRECTORY base/include/aemu DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
106    install(DIRECTORY snapshot/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aemu/snapshot)
107    install(DIRECTORY host-common/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aemu/host-common)
108    install(DIRECTORY third-party/cuda/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aemu/host-common)
109    set(INSTALL_TARGETS
110        aemu-base
111        aemu-host-common
112        ${SNAPSHOT_LIB_NAME}
113        ${LOGGING_LIB_NAME})
114    if(ENABLE_VKCEREAL_TESTS)
115        list(APPEND INSTALL_TARGETS aemu-base-testing-support aemu-host-common-testing-support)
116    endif()
117    install(TARGETS ${INSTALL_TARGETS}
118            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
119            INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
120endif()
121