1

This is my code structure:

  • main executable(CMakeLists.txt) |
    • base library(CMakeLists.txt)
    • profiler library(CMakeLists.txt)
    • log library(CMakeLists.txt)

Every library is using the base library. The main is using every library.

Actually this is the CMakeLists.txt of the main executable:

cmake_minimum_required(VERSION 3.4.1)

# build native_app_glue as a static lib
add_library(native_app_glue STATIC
    ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wall -fno-exceptions -fno-rtti")

# build the ndk-helper library
set(ndk_helper_dir ../../../../common/ndk_helper)
add_subdirectory(${ndk_helper_dir} ndk_helper)

# build the base library
set(base_dir ../../../../common/base)
add_subdirectory(${base_dir} base)

# build the profile library
set(profile_dir ../../../../common/profile)
add_subdirectory(${profile_dir} profile)

# build the log library
set(log_dir ../../../../common/log)
add_subdirectory(${log_dir} log)

# Export ANativeActivity_onCreate(),

# Refer to: https://github.com/android-ndk/ndk/issues/381.
set(CMAKE_SHARED_LINKER_FLAGS
    "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")

# now build app's shared lib
add_library(MainActivity SHARED
    MainActivity.cpp
    MainRenderer.cpp)

target_include_directories(MainActivity PRIVATE
    ${ANDROID_NDK}/sources/android/cpufeatures
    ${ANDROID_NDK}/sources/android/native_app_glue
    ${ndk_helper_dir}
    ${base_dir}
    ${profile_dir}
    ${log_dir}
    )

# add lib dependencies
target_link_libraries(MainActivity
    android
    native_app_glue
    atomic
    EGL
    GLESv2
    log
    ndk-helper
    base
    profile
    log
    )

I am unable to add include paths on compile time from any of the libraries to the base library. I am tryint to do it in this way:

On the profile library corresponding CMakeLists.txt

include_directories(        ".."
                            "../.."
                            "../base/include"
                            "../../base/include"
                            "../../../base/include"
                            "./include"
                            "include"
                            )

target_include_directories(profile PRIVATE
                            ${base_dir}
                            ".."
                            "../.."
                            "../base/include"
                            "../../base/include"
                            "../../../base/include"
                            "./include"
                            )

And at compile time I am having an error saying that for example "something.h" which is located on the base library isnt found. If I instead change for "../../base/include/something.h" everything works...

I would like to add those default auto paths for include folders. Is there a way to do it? How can i do it?

I have been struggling through this for long time. Any help is appreciated.

user0042
  • 7,917
  • 3
  • 24
  • 39
Iñigo
  • 97
  • 6

1 Answers1

0

Okay I found the answer...

target_include_directories(profile PRIVATE ${base_dir} ".." "../.." "../base/include" "../../base/include" "../../../base/include" "./include" )

Moving from PRIVATE to PUBLIC did the trick so I am now able to access to the include folders. Still cant understand the real use of the PRIVATE word, why define an include directory for afterwards not being able to use it? It has no sense...

Iñigo
  • 97
  • 6