Reputation: 365
I am cross-compiling a project with CMake. find_library
fails to find a library that is located in ${CMAKE_INSTALL_PREFIX}/lib
, because CMAKE_INSTALL_PREFIX
is not being appended to CMAKE_SYSTEM_PREFIX_PATH
as it should according to the documentation.
The cause for this is that I set CMAKE_SYSTEM_NAME
to Generic
in my toolchain file. I stripped down the toolchain file to this single command. Why does it affect the behaviour of CMAKE_INSTALL_PREFIX
?
If I set CMAKE_SYSTEM_NAME
to Linux
or Windows
, CMAKE_SYSTEM_PREFIX_PATH
has some preset and also CMAKE_INSTALL_PREFIX
is appended as expected.
Upvotes: 1
Views: 969
Reputation: 365
I think the documentation is wrong here. Adding CMAKE_INSTALL_PREFIX
to CMAKE_SYSTEM_PREFIX_PATH
is not done automatically. This is done inside CMake modules that are specific to the Windows and Linux platforms (e.g. c:\Program Files\CMake\share\cmake-3.14\Modules\Platform\WindowsPaths.cmake on my computer).
To mimic the same behaviour for non-Windows and non-Linux platforms, you can do the following. In the toolchain file, define a unique system name and also add the current directory to CMAKE_MODULE_PATH
so that Cmake will look for modules here:
set(CMAKE_SYSTEM_NAME "MySystem")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
Then create a platform file called <CMAKE_SYSTEM_NAME>.cmake
in a sub-folder called Platform
(e.g. Platform\MySystem.cmake
). Inside this file you can append CMAKE_INSTALL_PREFIX
to CMAKE_SYSTEM_PREFIX_PATH
:
# Copied from c:\Program Files\CMake\share\cmake-3.14\Modules\Platform\WindowsPaths.cmake
if (NOT CMAKE_FIND_NO_INSTALL_PREFIX)
list(APPEND CMAKE_SYSTEM_PREFIX_PATH
# Project install destination.
"${CMAKE_INSTALL_PREFIX}"
)
if(CMAKE_STAGING_PREFIX)
list(APPEND CMAKE_SYSTEM_PREFIX_PATH
# User-supplied staging prefix.
"${CMAKE_STAGING_PREFIX}"
)
endif()
endif()
Upvotes: 1