CMake find_path return NOT FOUND

27 Views Asked by At

I built a PCRE2 libaray, using rsicv32 cross compiler

source /opt/sdk/4.0.13/environment-setup-riscv32-poky-linux

I customized the installation dir, after installation, I can find the .h and .a files are installed successfully

root@b6af0bec113a:/workspaces/code/test_pcre2# ls /opt/riscv32/include/
pcre2.h  pcre2posix.h
root@b6af0bec113a:/workspaces/code/test_pcre2# ls /opt/riscv32/lib     
libpcre2-8.a  libpcre2-posix.a  pkgconfig

But when I build another project which depends on the PCRE2, it can't find the library, I debug the CMake files, and minimized it to following CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

project(FindPCRE2)

unset(PCRE2_SDK_INCLUDE_DIR CACHE)
find_path(
    PCRE2_SDK_INCLUDE_DIR
    NAMES "pcre2.h"
    PATHS /opt/riscv32/include
    )
message(STATUS "pcre2 => ${PCRE2_SDK_INCLUDE_DIR}")

When I configure above CMake which cmake ., the var PCRE2_SDK_INCLUDE_DIR is always PCRE2_SDK_INCLUDE_DIR-NOTFOUND

CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- pcre2 => PCRE2_SDK_INCLUDE_DIR-NOTFOUND
-- Configuring done
-- Generating done
-- Build files have been written to: /workspaces/code/test_pcre2

I use the cmake version 3.22.3

1

There are 1 best solutions below

0
bzhu On

Thanks @Tsyvarev comments

As it is cross compiling,

find_path(
   PCRE2_SDK_INCLUDE_DIR
   NAMES "pcre2.h"
   PATHS /opt/riscv32/include
   )

will check the pcre2.h under $SYSROOT/opt/riscv32/include, please note the $SYSROOT is defined by your cross compiler, in my case it is:

/opt/sdk/4.0.13/sysroots/riscv32-poky-linux/

So When I install the PCRE2 libray, I should configure the installation dir to : /opt/sdk/4.0.13/sysroots/riscv32-poky-linux/opt/riscv32

Then it works