3

I am trying to build OpenAL with the Android NDK. The license requires that the library be dynamically loaded. I receive the following message when attempting to build:

CMake Warning (dev) at CMakeLists.txt:1032 (ADD_LIBRARY):
  ADD_LIBRARY called with SHARED option but the target platform does not
  support dynamic linking.  Building a STATIC library instead.  This may lead
  to problems.

My toolchain file includes SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS true) and looks like this:

SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_C_COMPILER "${HOST}-gcc")
SET(CMAKE_CXX_COMPILER "${HOST}-g++")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
set(ENV{PKG_CONFIG_PATH} "")

SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS true)

I create a build directory in the source and invoke cmake with the following:

cmake .. -DALSOFT_BACKEND_WAVE=0 -DALSOFT_REQUIRE_OPENSL=1 -DALSOFT_NO_CONFIG_UTIL=1 -DALSOFT_EXAMPLES=0 -DALSOFT_UTILS=0 -DALSOFT_CONFIG=0 -DCMAKE_INSTALL_PREFIX=$ANDROID_DEV/opt -DCMAKE_INSTALL_RPATH=$ANDROID_DEV/opt -DHOST= -DCMAKE_TOOLCHAIN_FILE=../../android-toolchain.cmake

I have verified that the toolchain file is loaded by adding garbage to it and seeing the cmake command result in an error.

The CMakeLists.txt file starts like this:

# CMake build file list for OpenAL

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

PROJECT(OpenAL)

IF(COMMAND CMAKE_POLICY)
  CMAKE_POLICY(SET CMP0003 NEW)
  CMAKE_POLICY(SET CMP0005 NEW)
ENDIF(COMMAND CMAKE_POLICY)

SET(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")

I have successfully built the library as a dynamic module by placing SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS true) in CMakeList.txt immediately after the PROJECT(OpenAL). If I place it before this the build results in a static library with the previously mentioned warning.

It seems as though the property TARGET_SUPPORTS_SHARED_LIBS is being reset after PROJECT(OpenAL). I have read the documetnation for PROJECT, TARGET_SUPPORTS_SHARED_LIBS and including a toolchain file but have not found anything that explicitly mentions resetting of target toolchain variables.

Does CMake have some rules that causes this variable to be reset between the toolchain file and the CMakeLists.txt processing, or perhaps before and after the PROJECT command?

I am using CMake 2.8.12.2. Each time I issue the CMake command, I do so with a fresh copy of the source directory to be sure that there isn't a caching issue.

Sean Tasker
  • 69
  • 1
  • 5

1 Answers1

0

The problem is with the line "SET(CMAKE_SYSTEM_NAME Generic)"

The Generic platform overrides the TARGET_SUPPORTS_SHARED_LIBS property to false. If you replace Generic with Android in this case it should work, though it will give you warnings. In this case, simply using Linux as the system name is probably a better choice though (Android is technically a variant of the Linux kernel).

I just encountered the same issue myself attempting to cross-compile for a VxWorks platform. In my case, I'm now setting the name to VxWorks and living with the annoying warnings for now.

Digicrat
  • 581
  • 5
  • 13
  • I would recommend to use the cmake toolchain file from Android NDK and not choose Linux as system name: there are quite a few differences that cmake must account for. – Alex Cohn Apr 10 '18 at 17:04