0

I am trying to import an external C/C++ library in my android module in one of the projects. The library is called android-fluidsynth. I am following instructions given at this link to integrate it. Following is how my CMakeLists.txt looks like:

EDIT 2 : The below one works

# Sets the minimum version of CMake required to build your native library.
# This ensures that a certain set of CMake features is available to
# your build.

cmake_minimum_required(VERSION 3.4.1)


######################################################################################
######### Adding fluidsynth library from the external code
######################################################################################
# Sets lib_src_DIR to the path of the target CMake project.
set(fluidsynth-lib-name libfluidsynthsrc)
set( lib_DIR /Users/swapnilgupta/work/musicmuni/fluidsynth-android/android/ )

# Sets lib_build_DIR to the path of the desired output directory.
set( lib_build_DIR ${lib_DIR}/outputs )
file(MAKE_DIRECTORY ${lib_build_DIR})

# Adds the CMakeLists.txt file located in the specified directory
# as a build dependency.
add_subdirectory( # Specifies the directory of the CMakeLists.txt file.
                  ${lib_DIR}

                  # Specifies the directory for the build outputs.
                  ${lib_build_DIR} )

# Adds the output of the additional CMake build as a prebuilt static
# library and names it.
add_library( ${fluidsynth-lib-name}
                SHARED
                IMPORTED )

set_target_properties( ${fluidsynth-lib-name} PROPERTIES IMPORTED_LOCATION
                       ${lib_build_DIR}/${ANDROID_ABI}/lib${fluidsynth-lib-name}.so )

On trying to build this I get the following error:

install TARGETS given no RUNTIME DESTINATION for executable target   "fluidsynth"

I have gone through some SO posts and added following lines in my CMakeLists.txt but I still get this error.

if(WIN32)
  install(TARGETS fluidsynth
    RUNTIME DESTINATION ./)
else()
  install(TARGETS fluidsynth
    LIBRARY DESTINATION ./)
endif()

Can anyone please help?

Swapnil
  • 1,870
  • 2
  • 23
  • 48
  • The error message seems to be clear: `fluidsynth` is an executable target, thus it requires *RUNTIME DESTINATION*. But your code sets *LIBRARY DESTINATION* for non-Windows platforms. BTW, the code you show doesn't contains creation of `fluidsynth` target, it creates only `libfluidsynth` one. – Tsyvarev Apr 09 '18 at 17:40

2 Answers2

1

You don't need to invent your own CMakeLists.txt for libfluidsynth. You can point your externalNativeBuild to fluidsynth-android-1.1.10/android/CMakeLists.txt.

This defines the fluidsynth library that you can use as dependency for other libraries, e.g.

target_link_libraries(<mylibname> fluidsynth log)
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • I tried that but it still shows error in one of the `install` statements. Also, when I try to run `cmake CMakeLists` after going to the directory where I have the source code sitting i.e. `/fluidsynth-android-1.1.10/src`, I get the following error `install TARGETS given no RUNTIME DESTINATION for executable target "fluidsynth".` I have used the following `https://stackoverflow.com/a/35756700/2606411` instructions in being able to build it but don't know how to incorporate in my android library. – Swapnil Apr 10 '18 at 04:15
  • Not /fluidsynth-android-1.1.10/src, but /fluidsynth-android-1.1.10/android – Alex Cohn Apr 10 '18 at 06:46
  • One more question @Alex, if I have mentioned name `libfluidsynthsrc` in my `add_library(...)` method, using `set_target_properties( ${fluidsynth-lib-name} PROPERTIES IMPORTED_LOCATION ${lib_build_DIR}/${ANDROID_ABI}/lib${fluidsynth-lib-name}.so )` is correct or I should not use a prefix `lib` before the librry name? **FYI** I had use a custom CMakeLists.txt because I want to link this library with another library that I am creating internally! – Swapnil Apr 10 '18 at 14:59
  • If you build libfluidsynth with fluidsynth-android-1.1.10/android/CMakeLists.txt, you can use it as a dependency for your library, don't need to declare it as IMPORTED. Chaining CMakeLists.txt files is easy, they have the `add_subdirectory` command for that. – Alex Cohn Apr 10 '18 at 16:39
  • You mean that I don't have to use `add_library()` and `set_target_properties()` for fluidsynth-android-1.1.10? If not, then how would I try to link it to my library. Right now, I was trying to use `target_link_libraries( ${fluidsynth-lib-name} log)` to build my library with fluidsynth. – Swapnil Apr 10 '18 at 17:10
  • Btw... I used the following instructions to do what I am doing right now https://developer.android.com/studio/projects/configure-cmake.html#include-other-cmake-projects – Swapnil Apr 10 '18 at 17:12
  • You will `target_link_libraries( fluidsynth log)` instead – Alex Cohn Apr 10 '18 at 17:23
  • And I don't have to use add_library() and set_target_properties() for fluidsynth-android-1.1.10 ... Right ? – Swapnil Apr 10 '18 at 17:30
  • The project that you use already did add_library(fluidsynth) for you – Alex Cohn Apr 10 '18 at 19:04
  • Ohh okay... Got it ... Thanks ☺ – Swapnil Apr 11 '18 at 01:07
  • For building fluidsynth from the volcanomobiles repo, I tried building it by downloading one of its releases(https://github.com/VolcanoMobile/fluidsynth-android/releases). The release bundle does not seem to have an `android` folder. When I directly check out the entire repo and build it, I have some issues while running it. Can you please give some pointers on how to have it run by using a release bundle? – Swapnil Apr 16 '18 at 08:02
  • the 'release' was not taken from branch, that's why you see the difference. I guess you should [open an Issue](https://github.com/FluidSynth/fluidsynth/issues/new) on GitHub if you something does not work for you. – Alex Cohn Apr 16 '18 at 08:35
  • fast rendering of file is not working for me. I have discussed this on the `fluid-dev` mailing list and it seems that the VolcanoMobile/fluidsynth-android seems to have some components missing from the original fluidsynth code. I did check the CMakeLists.txt and it seems that they have excluded a major portion of code in the fork. Now, VolcanoMobile/fluidsynth-android does not have a page to open an issue so I am kind of stuck. I am unable to contact [Philippe Simons](https://github.com/loki666) who made these changes. – Swapnil Apr 16 '18 at 08:43
  • Btw... @Alex I have been trying fast rendering of MIDI and soundfonts into a raw PCM file. Do you know of any other libraries that can help me with that? – Swapnil Apr 16 '18 at 08:44
0

I see two problems in your CMakeLists.txt:

One minor: the set(runtime_destination) statement has no effect, you can remove it.

The other is likely what trips up your build: DYNAMIC is not a valid CMake library type, AFAIK. You should change it to SHARED.

Then, since it's an imported target, you will need to specify its location, by adding something along the lines of:

set_target_property(TARGET ${fluidsynth-lib-name} PROPERTY IMPORTED_LOCATION path-to-libfluidsynth.so)
  • HEY @Nicolas thank you for your response . Sorry.. I was in middle of editing and that's why that 'runtime_destination' statement and I already have a set_target_properties statement in place. – Swapnil Apr 09 '18 at 16:38