[CMake] cross-compile and find_library

Davis Ford davisford at gmail.com
Mon Sep 24 17:38:02 EDT 2012


I have a build that needs to cross-compile.  The directory structure
looks something like this:

/src
/lib
 |
 -- linux
    |
    -- libFoo.so
 |
 -- embedded
    |
    -- libFoo.so

libFoo.so under embedded was cross-compiled, and I have a Toolchain
file to cross-compile my project's source and I want to link with the
correct libFoo.so depending on what build I'm doing.

For standard linux build, I am pulling in libFoo.so like this:

find_library(FOO_LIB Foo ${PROJECT_SOURCE_DIR}/../lib/linux)

This works fine.  I setup some alternative logic like this:

if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")

  if (${CMAKE_CROSSCOMPILING})
    find_library(FOO_LIB Foo ${PROJECT_SOURCE_DIR}/../lib/embedded)
  else()
    find_library(FOO_LIB Foo ${PROJECT_SOURCE_DIR/../lib/linux)
  endif()

endif()

Unfortunately, this does not work.  The If/Else logic works --
verified by putting message("") statements in there.  If I'm
cross-compiling I do navigate and try to set FOO_LIB from the embedded
directory, but unfortunately, it seems to still fail with:

CMake Error: The following variables are used in this project, but
they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the
CMake files:
FOO_LIB

It seems like find_library maybe does not set the library if it is a
different architecture?  What is the recommended way to do this?


More information about the CMake mailing list