CMake does not create executable with add_executable

I am new to CMake and I had a problem creating an executable using CMake. I am trying to create an executable and a shared library from a single CMakeLists.txt file. My CMakeLists.txt is as follows:

cmake_minimum_required(VERSION 3.4.1)
project (TestService)

include_directories(
    src/main/cpp/
    libs/zlib/include/
)

add_library(libz SHARED IMPORTED)

set_target_properties(libz PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/libs/zlib/libs/${ANDROID_ABI}/libz.so)

find_library(log-lib log)

add_executable(
    test_utility
    src/main/cpp/test_utility.cpp
    src/main/cpp/storage.cpp
)

target_link_libraries(test_utility ${log-lib} libz)

add_library(
    processor
    SHARED
    src/main/cpp/com_example_testservice.cpp
    src/main/cpp/storage.cpp
)

target_link_libraries(processor libz ${log-lib})

However, when I create my project using android studio / gradlew from the command line, I only see that the created processor.so library is created, the test_utility executable is never created. What is wrong in my CMakeLists.txt?

+4
source share
3 answers

: , apk, , lib*.so. :

add_executable(libnativebinaryname.so ...)
+1

, , .
, , make processor, processor. CMakeLists.txt , processor test_utility target .

, :

  • make,
  • make test_utility,
0

. Android Studio .so , , . ( "" ).

, - build.gradle:

defaultConfig {
    externalNativeBuild {
        cmake {
            targets "executable_target"
        }
    }
}

, :

productFlavors {
    chocolate {
        externalNativeBuild {
            cmake {
                targets "executable_target"
            }
        }
    }
}

If you add any explicit assembly object, it will no longer create all common objects by default, but only those that are dependent on the explicit target. You can specify more than one purpose to create all of your executable files and shared objects. This bug improves it.

0
source

Source: https://habr.com/ru/post/1678916/


All Articles