Phil Burk | 40283a7 | 2019-10-21 09:43:16 -0700 | [diff] [blame] | 1 | # For more information about using CMake with Android Studio, read the |
| 2 | # documentation: https://d.android.com/studio/projects/add-native-code.html |
| 3 | |
| 4 | # Sets the minimum version of CMake required to build the native library. |
| 5 | |
| 6 | cmake_minimum_required(VERSION 3.4.1) |
| 7 | |
| 8 | # Require C++17 compiler with no extensions |
| 9 | set(CMAKE_CXX_STANDARD 17) |
| 10 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 11 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 12 | |
Phil Burk | 1478301 | 2019-10-21 17:16:05 -0700 | [diff] [blame] | 13 | link_directories(${CMAKE_CURRENT_LIST_DIR}/..) |
Phil Burk | 57f9cd3 | 2019-10-21 16:39:26 -0700 | [diff] [blame] | 14 | |
Phil Burk | 40283a7 | 2019-10-21 09:43:16 -0700 | [diff] [blame] | 15 | # Creates and names a library, sets it as either STATIC |
| 16 | # or SHARED, and provides the relative paths to its source code. |
| 17 | # You can define multiple libraries, and CMake builds them for you. |
| 18 | # Gradle automatically packages shared libraries with your APK. |
| 19 | |
| 20 | add_library( # Sets the name of the library. |
| 21 | native-lib |
| 22 | # Sets the library as a shared library. |
| 23 | SHARED |
| 24 | # Provides a relative path to your source file(s). |
Phil Burk | 1478301 | 2019-10-21 17:16:05 -0700 | [diff] [blame] | 25 | src/main/cpp/native-lib.cpp |
| 26 | src/main/cpp/DuplexEngine.cpp |
Phil Burk | 40283a7 | 2019-10-21 09:43:16 -0700 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | # Compile with warnings for safety |
| 30 | if(MSVC) |
| 31 | target_compile_options(native-lib PRIVATE /W4 /WX) |
| 32 | else() |
| 33 | target_compile_options(native-lib PRIVATE -Wall -Wextra -pedantic) |
| 34 | endif() |
| 35 | |
| 36 | target_compile_options(native-lib PRIVATE -Ofast) |
| 37 | |
| 38 | # Searches for a specified prebuilt library and stores the path as a |
| 39 | # variable. Because CMake includes system libraries in the search path by |
| 40 | # default, you only need to specify the name of the public NDK library |
| 41 | # you want to add. CMake verifies that the library exists before |
| 42 | # completing its build. |
| 43 | |
| 44 | find_library( # Sets the name of the path variable. |
| 45 | log-lib |
| 46 | # Specifies the name of the NDK library that |
| 47 | # you want CMake to locate. |
| 48 | log) |
| 49 | |
Phil Burk | 57f9cd3 | 2019-10-21 16:39:26 -0700 | [diff] [blame] | 50 | |
| 51 | ### INCLUDE OBOE LIBRARY ### |
| 52 | |
| 53 | # Set the path to the Oboe library directory |
| 54 | set (OBOE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) |
| 55 | |
| 56 | # Add the Oboe library as a subproject. Since Oboe is an out-of-tree source library we must also |
| 57 | # specify a binary directory |
| 58 | add_subdirectory(${OBOE_DIR} ./oboe-bin) |
| 59 | |
| 60 | # Specify the path to the Oboe header files and the source. |
| 61 | include_directories( |
| 62 | ${OBOE_DIR}/include |
| 63 | ${OBOE_DIR}/src |
Phil Burk | 40283a7 | 2019-10-21 09:43:16 -0700 | [diff] [blame] | 64 | ) |
| 65 | |
Phil Burk | 57f9cd3 | 2019-10-21 16:39:26 -0700 | [diff] [blame] | 66 | ### END OBOE INCLUDE SECTION ### |
| 67 | |
| 68 | |
Phil Burk | 40283a7 | 2019-10-21 09:43:16 -0700 | [diff] [blame] | 69 | # Specifies libraries CMake should link to your target library. You |
| 70 | # can link multiple libraries, such as libraries you define in this |
| 71 | # build script, prebuilt third-party libraries, or system libraries. |
| 72 | |
| 73 | target_link_libraries( # Specifies the target library. |
| 74 | native-lib |
| 75 | oboe |
| 76 | # Links the target library to the log library |
| 77 | # included in the NDK. |
| 78 | ${log-lib}) |
| 79 | |