1# CMake Build System Overview
2
3[TOC]
4
5This document provides a general layout of the Draco CMake build system.
6
7## Core Build System Files
8
9These files are listed in order of interest to maintainers of the build system.
10
11-   `CMakeLists.txt` is the main driver of the build system. It's responsible
12    for defining targets and source lists, surfacing build system options, and
13    tying the components of the build system together.
14
15-   `cmake/draco_build_definitions.cmake` defines the macro
16    `draco_set_build_definitions()`, which is called from `CMakeLists.txt` to
17    configure include paths, compiler and linker flags, library settings,
18    platform speficic configuration, and other build system settings that
19    depend on optional build configurations.
20
21-   `cmake/draco_targets.cmake` defines the macros `draco_add_library()` and
22    `draco_add_executable()` which are used to create all targets in the CMake
23    build. These macros attempt to behave in a manner that loosely mirrors the
24    blaze `cc_library()` and `cc_binary()` commands. Note that
25    `draco_add_executable()` is also used for tests.
26
27-   `cmake/draco_emscripten.cmake` handles Emscripten SDK integration. It
28    defines several Emscripten specific macros that are required to build the
29    Emscripten specific targets defined in `CMakeLists.txt`.
30
31-   `cmake/draco_flags.cmake` defines macros related to compiler and linker
32    flags. Testing macros, macros for isolating flags to specific source files,
33    and the main flag configuration function for the library are defined here.
34
35-   `cmake/draco_options.cmake` defines macros that control optional features
36    of draco, and help track draco library and build system options.
37
38-   `cmake/draco_install.cmake` defines the draco install target.
39
40-   `cmake/draco_cpu_detection.cmake` determines the optimization types to
41    enable based on target system processor as reported by CMake.
42
43-   `cmake/draco_intrinsics.cmake` manages flags for source files that use
44    intrinsics. It handles detection of whether flags are necessary, and the
45    application of the flags to the sources that need them when they are
46    required.
47
48## Helper and Utility Files
49
50-   `.cmake-format.py` Defines coding style for cmake-format.
51
52-   `cmake/draco_helpers.cmake` defines utility macros.
53
54-   `cmake/draco_sanitizer.cmake` defines the `draco_configure_sanitizer()`
55    macro, which implements support for `DRACO_SANITIZE`. It handles the
56    compiler and linker flags necessary for using sanitizers like asan and msan.
57
58-   `cmake/draco_variables.cmake` defines macros for tracking and control of
59    draco build system variables.
60
61## Toolchain Files
62
63These files help facilitate cross compiling of draco for various targets.
64
65-   `cmake/toolchains/aarch64-linux-gnu.cmake` provides cross compilation
66    support for arm64 targets.
67
68-   `cmake/toolchains/android.cmake` provides cross compilation support for
69    Android targets.
70
71-   `cmake/toolchains/arm-linux-gnueabihf.cmake` provides cross compilation
72    support for armv7 targets.
73
74-   `cmake/toolchains/arm64-ios.cmake`, `cmake/toolchains/armv7-ios.cmake`,
75    and `cmake/toolchains/armv7s-ios.cmake` provide support for iOS.
76
77-   `cmake/toolchains/arm64-linux-gcc.cmake` and
78    `cmake/toolchains/armv7-linux-gcc.cmake` are deprecated, but remain for
79    compatibility. `cmake/toolchains/android.cmake` should be used instead.
80
81-   `cmake/toolchains/arm64-android-ndk-libcpp.cmake`,
82    `cmake/toolchains/armv7-android-ndk-libcpp.cmake`,
83    `cmake/toolchains/x86-android-ndk-libcpp.cmake`, and
84    `cmake/toolchains/x86_64-android-ndk-libcpp.cmake` are deprecated, but
85    remain for compatibility. `cmake/toolchains/android.cmake` should be used
86    instead.
87
88-   `cmake/toolchains/i386-ios.cmake` and `cmake/toolchains/x86_64-ios.cmake`
89    provide support for the iOS simulator.
90
91-   `cmake/toolchains/android-ndk-common.cmake` and
92    `cmake/toolchains/arm-ios-common.cmake` are support files used by other
93    toolchain files.
94
95## Template Files
96
97These files are inputs to the CMake build and are used to generate inputs to the
98build system output by CMake.
99
100-   `cmake/draco-config.cmake.template` is used to produce
101    draco-config.cmake. draco-config.cmake can be used by CMake to find draco
102    when another CMake project depends on draco.
103
104-   `cmake/draco.pc.template` is used to produce draco's pkg-config file.
105    Some build systems use pkg-config to configure include and library paths
106    when they depend upon third party libraries like draco.
107