title: How to make ExternalProject_Add acting like ADD_SUBDIRECTORY command with cmake?
body: <p>I'm creating a native library under Android Studio, and I'm hurting the following problem.</p>
  
  <p>In my AndroidStudio project <code>CMakeLists.txt</code>, I have this:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.7.0)    
  
  add_library(native-lib
               SHARED
               src/main/cpp/native-lib.cpp )    
  
  IF(USE_EXTERNAL)
      include(ExternalProject)
      ExternalProject_Add(
          project_mylib
          DOWNLOAD_COMMAND ""
          SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/mylib/"
          CMAKE_ARGS
              -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}
      )
      add_dependencies(native-lib project_mylib)
  ELSE()
      add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/mylib/)
  ENDIF()    
  
  find_library( # Sets the name of the path variable.
                log-lib
  
                # Specifies the name of the NDK library that
                # you want CMake to locate.
                log )   
  
  
  target_link_libraries(native-lib
      ${log-lib}    
      mylib
  )
  </code></pre>
  
  <p>A self-made library is located in <code>src/main/cpp/mylib/</code>, with a <code>CMakeLists.txt</code>: </p>
  
  <pre><code>cmake_minimum_required(VERSION 3.7.0)
  project(lib)    
  add_library(mylib SHARED lib.cpp)
  INSTALL(TARGETS mylib
      RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
      LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
  )
  </code></pre>
  
  <p>When I use the "traditional" <code>add_subdirectory(...)</code> everything goes well. But, if I use the <code>ExternalProject_Add(...)</code> version, linker is skipping the compiled <code>libmylib.so</code> library and so cannot link <code>mylib</code> to <code>native-lib</code>. </p>
  
  <p>I have the following message: <code>skipping incompatible /home/.../app/.externalNativeBuild/cmake/debug/arm64-v8a/lib/libmylib.so when searching for -lmylib</code></p>
  
  <p>My guess is that all the flags set by AndroidStudio for the root <code>CMakeLists.txt</code> are not set when the <code>ExternalProject</code> is compile leading to an incompatible shared library.</p>
  
  <p>So, I wonder if there is a way to compile a cmake <code>ExternalProject</code> like it was part of the root project (sharing the same compile flags etc) ?</p>
  
  <p>Thanks for any advice</p>