LLVM CMake find include and library for libpfm

Hi everyone, I want to build llvm-exegesis with libpfm but got some issues…

I am using a student server, and I don’t have the permission to install libraries in standard linking&include directory, so I build libpfm from source. I can make sure all headers can be found at xx/libpfm4/include/ and libpfm.a can be found at xx/libpfm4/lib. When I configure llvm-project using the following command, I still got “-- Looking for pfm_initialize in pfm
– Looking for pfm_initialize in pfm - not found” in the Cmake log

#The command is
 cmake -G "Ninja" -DCMAKE_PREFIX_PATH="xx/llvm-18/libpfm4" \
     -DCMAKE_INCLUDE_PATH="xx/llvm-18/libpfm4/include" \
    -DCMAKE_LIBRARY_PATH="xx/llvm-18/libpfm4/lib" \
    -DCMAKE_BUILD_TYPE=Debug  ../llvm

I also tried manually modify llvm/CMakeLists.txt and added


But not worked and still got the same output

Can someone help me with building llvm-project with external libpfm? This is really important to me…

  • CMAKE_INCLUDE_PATH is about xxx.cmake files (not C/C++ include files) I think.
  • You probably have to do something like CMAKE_CXX_FLAGS=-Ixx/include (same for CMAKE_C_FLAGS).
  • CMAKE_LIBRARY_PATH sounds to me like it should work; if it doesn’t then you could also try CMAKE_EXE_LINKER_FLAGS=-Lxx/lib (same for CMAKE_MODULE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS and CMAKE_STATIC_LINKER_FLAGS).
  • For bonus points you could add some extra variables/logic to https://github.com/llvm/llvm-project/blob/main/llvm/cmake/modules/FindLibpfm.cmake and submit a patch to help others in the future :slight_smile:

Hey Thank you MatzeB!
After setting CMAKE_CXX_FLAGS/CMAKE_C_FLAGS=-Ixx/include and CMAKE_EXE_LINKER_FLAGS=-Lxx/lib, I successfully let CMake find the header and library.