Common configuration tutorials for CmakeList and cmakelist
1. To generate multiple so Libraries
# Set the minimum cbuild required to build the local database. Cmake_minimum_required (VERSION 3.4.1) # create and name a library, set it to static # Or share it, and provide the relative path of its source code. # You can define multiple databases, and cbuild builds them for you. # Gradle automatically packs the shared library and your APK. Add_library (hello-lib # Set the library name. That is, the SO file name, the produced so file is "libhello-lib.so", when loading "System. loadLibrary ("hello-lib"); "SHARED # Set the library to a SHARED library. Src/main/jni/hello. cpp # provide the relative path of a source file src/main/jni/helloJni. cpp # provide the relative path of another source file in the same SO file) # search for the specified pre-build library and store the path as a variable. Because cbuild contains the system library in the search path by default, you only need to specify the name of the public NDK library you want to add. Cbuild verifies the existence of this library before completing the build. Find_library (log-lib # sets the name of the path variable. Log # specifies the name of the NDK library. You want CMake to locate it.) # The database of the specified database should be linked to your target database. You can link Multiple libraries, such as the libraries defined in this build script, pre-built third-party libraries, or system libraries. Target_link_libraries (hello-lib # specifies the target library. The Library name must be the same as that of add_library $ {log-lib} # link the target Library to the logstore and include it in NDK.) # To produce multiple SO files, write the following code: add_library (natave-lib # Set the library name. The name of another so file is SHARED # Set the Library to the SHARED library. Src/main/jni/nataveJni. cpp # provide the relative path of a source file) target_link_libraries (natave-lib # specifies the target library. The Library name must be the same as that of add_library $ {log-lib} # link the target Library to the logstore and include it in NDK.)
Here is the reference from the following blog. I tried the code, but there is still a pitfall in it, that is, if your library name is not xx-lib, compilation is not good. For example, the so library name is test, and the cpp file is test. cpp, which is not compiled. Multiple so libraries are not generated.
2. Generate a so library and multiple cpp files
# Search for all the source files under the cpp directory # Save the name to the DIR_LIB_SRCS variable aux_source_directory (src/main/cpp/DIR_LIB_SRCS) # generate the Link Library add_library (native-lib SHARED $ {DIR_LIB_SRCS}) # import all header files under the cpp directory include_directories (src/main/cpp /)
Use the above Code to replace the original add_library command, which is actually to generate a variable and specify the cpp file path.
I do not know much about the Cmake syntax. You can learn the cmake syntax together.