Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake does not build an executable with add_executable

I am new to CMake and I have problem creating an executable using CMake. I am trying to build 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 build my project using android studio/gradlew from command line, I only see the processor.so library getting created, test_utility executable is never created. What is incorrect in my CMakeLists.txt?

like image 528
savi Avatar asked Jun 09 '17 22:06

savi


1 Answers

The answer is: it builds, it's just not packaged into apk because only files matching pattern lib*.so will be copied. Therefore the fix is easy:

add_executable(libnativebinaryname.so ...)
like image 59
Mygod Avatar answered Oct 06 '22 00:10

Mygod