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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With