Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to place libraries for emscripten and CMake

When I want to use a libraries in "normal" programs I install them with apt

apt-get install libjsoncpp-dev
apt-get install libassimp-dev

And then FIND_LIBRARY in CMakeLists.txt

FIND_LIBRARY(JSONCPP_LIBRARY NAMES jsoncpp)
TARGET_LINK_LIBRARIES(hello ${JSONCPP_LIBRARY})

FIND_LIBRARY(ASSIMP_LIBRARY NAMES assimp)
TARGET_LINK_LIBRARIES(hello ${ASSIMP_LIBRARY})

When compiling with emscripten I obviously have to install the libraries another way. I created a directory $HOME/emscripten-prefix and compiled them manually as static libraries with --prefix=$HOME/emscripten-prefix , and tried to CMAKE_INSTALL_PREFIX to look in that directory like this (and similarly for CMAKE_PREFIX_PATH):

cmake \
    -DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Platform/Emscripten.cmake \
    -DCMAKE_BUILD_TYPE=Debug \
    -G "Unix Makefiles" \
    -DCMAKE_INSTALL_PREFIX=$HOME/emscripten-prefix

Unfortunately it didn't work. strace revealed that CMake would prepend CMAKE_FIND_ROOT_PATH (which is set to "${EMSCRIPTEN_ROOT_PATH}/cmake" in $EMSCRIPTEN/cmake/Platform/Emscripten.cmake) to all paths. I tried changing it with -DCMAKE_FIND_ROOT_PATH, but Emscripten.cmake overrode that.

What is the correct way to do this? I think I can make it build by making a script that copies Emscripten.cmake and modifies CMAKE_FIND_ROOT_PATH, but that sounds like the wrong way.

like image 309
cnubidu Avatar asked Mar 29 '14 10:03

cnubidu


1 Answers

There is a simple solution to this problem:

Before calling find_library():

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)

After:

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)

Likewise, before calling find_package():

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)

After:

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
like image 149
Ariel Malka Avatar answered Oct 07 '22 11:10

Ariel Malka