Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello-libs sample doesn't seem to take into account build types #576

Open
Zingam opened this issue Sep 21, 2018 · 10 comments
Open

hello-libs sample doesn't seem to take into account build types #576

Zingam opened this issue Sep 21, 2018 · 10 comments

Comments

@Zingam
Copy link

Zingam commented Sep 21, 2018

The sample doesn't seem to take into account the various build types (debug, release)
set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../../distribution)
That doesn't seem right to me.

@ggfan
Copy link
Contributor

ggfan commented Sep 21, 2018

No the debug types. the build lib is debug build ( not the release build ). The thought behind that is:

  • if needing to debug the lib, probably best way is to compile it locally together with your app
  • when using 3rd party libs, the library providers mostly likely provide for release version of libs ( not the debug versions, for IP or whatever reasons )

@Zingam
Copy link
Author

Zingam commented Sep 21, 2018

I am not sure that I see your point. Gradle produces "debug" and "release" folders for each library, doesn't it? But then they are smashed into the same output directory which may or may not be an issue. But for demonstration purposes I think that it makes sense to put the binaries into separate directories e.g. debug, release... etc.

@ggfan
Copy link
Contributor

ggfan commented Sep 21, 2018

that line is for application to use lib, NOT to produce the lib. The purpose of the application to show that even when building debug version of application, it still use the "release" version of 3rd party lib. The assumption is that 3rd party lib providers will just provide one version of lib, NOT mixing them into the same dir.

@Zingam
Copy link
Author

Zingam commented Sep 21, 2018

Well, then it may be reasonable to explain that explicitly why and how in the documentation.

@Zingam
Copy link
Author

Zingam commented Sep 22, 2018

Just a suggestion: another valuable sample would be to show how to do all of this in the gradle script:

# copy out the lib binary... need to leave the static lib around to pass gradle check
set(distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../distribution)
set_target_properties(gmath
                      PROPERTIES
                      ARCHIVE_OUTPUT_DIRECTORY
                      "${distribution_DIR}/gmath/lib/${ANDROID_ABI}")

# copy out lib header file...
add_custom_command(TARGET gmath POST_BUILD
                   COMMAND "${CMAKE_COMMAND}" -E
                   copy "${CMAKE_CURRENT_SOURCE_DIR}/src/gmath.h"
                   "${distribution_DIR}/gmath/include/gmath.h"
#                   **** the following 2 lines are for potential future debug purpose ****
#                   COMMAND "${CMAKE_COMMAND}" -E
#                   remove_directory "${CMAKE_CURRENT_BINARY_DIR}"
                   COMMENT "Copying gmath to output directory")7

so that the user could just drop in a library source and use it without modifying the library's CMakeLists.txt

@ggfan
Copy link
Contributor

ggfan commented Sep 25, 2018

yeah, it is good point. The original thought is:

  • native related processing should be inside the native side; same for java side.
  • the opposite may causing long time maintenance overhead: when a project is done, the team would already move forwarded; when bug happened, it could be another team of engineers that fixing those bugs. Forcing two build systems into new people may not be the best industry standard to go after from any standing point of view. The less tanging between 2 build system, the better.

Gradle's copy function is pretty easy and flexible; the potential though is that it needs to know where the files to copy from -- this directory info is from CMake. So here logic crosses the boundaries again...

From the build script standing point of view, the minimum crosses between gradle and cmake ( or other native build systems ) would be the best.

CMake installation step might do a better work to copy: basically this is similar to install the header & libs into certain place. There is discussion about that approach, probably should explore that path too.

@Zingam
Copy link
Author

Zingam commented Sep 30, 2018

set_target_properties(gmath
                      PROPERTIES
                      ARCHIVE_OUTPUT_DIRECTORY
                      "${distribution_DIR}/gmath/lib/${ANDROID_ABI}")
set_target_properties(gperf
                      PROPERTIES
                      LIBRARY_OUTPUT_DIRECTORY
                      "${distribution_DIR}/gperf/lib/${ANDROID_ABI}")

How can this be done from Gradle? The idea is if you have libraries' source code, which you can include in your project for example as a library modules, which then you can add as dependencies of the app module. You also don't want to touch the libraries original CMakeLists.txt. So I want to set ARCHIVE_OUTPUT_DIRECTORY and LIBRARY_OUTPUT_DIRECTORY from Gradle.
So I want to pass the corresponding values of CMAKE_BUILD_TYPE and ANDROID_ABI as part of the path -DCMAKE_LIBRARY_OUTPUT_DIRECTORY and -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY via externalNativeBuild { cmake { arguments "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY:STRING=........$projectName/$buildType/$androidAbi", "-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY:STRING=....$projectName/$buildType/$androidAbi"} }

@ggfan
Copy link
Contributor

ggfan commented Oct 2, 2018

asking the equivalent variables in gradle for them as I do not think Gradle could access CMake variables.

@Zingam
Copy link
Author

Zingam commented Oct 3, 2018

I think you misunderstand me. I don't want to access CMake variables from gradle. What I want is to pass the values set in ANDROID_ABI and CMAKE_BUILD_TYPE myself in the gradle script and pass them to CMake which I guess are passed to CMake by gradle somehow.
I need this if I don't want to change the original CMake of the external libraries as in the hello-libs sample. In that sample the CMakeList.txt is aware of the distributionDir.
As a workaround I could create my own CMakeList.txt that add the library source as a subdirectory and set the properties like that:

cmake_minimum_required (VERSION 3.10)

add_subdirectory ("FreeType2")
set_target_properties (freetype
  PROPERTIES
    ARCHIVE_OUTPUT_DIRECTORY
      "${.LibraryArtifactsOutputDirectory}/${CMAKE_BUILD_TYPE}/${ANDROID_ABI}"
    LIBRARY_OUTPUT_DIRECTORY
      "${.LibraryArtifactsOutputDirectory}/${CMAKE_BUILD_TYPE}/${ANDROID_ABI}"
)

I think it would be best if I can set ARCHIVE_OUTPUT_DIRECTORY, LIBRARY_OUTPUT_DIRECTORY from gradle itself but I cannot figure out how to get the build type, and the abi and to pass them to externalBuild { cmake {} }. Maybe that's a limitation of the android plugin?

@ggfan
Copy link
Contributor

ggfan commented Oct 3, 2018

understood, @jomof might know those variables in gradle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants