0

I want to use CMAKE_PREFIX_PATH to set a directory (say /usr/local2) for cmake to search for headers and libraries. I tried to use the command line

cmake -DCMAKE_PREFIX_PATH=/usr/local2 /path/to/src

But cmake does not seem to take that hint (i.e. it still found the library in system path /usr/local). I also tried ccmake and cmake-gui, but neither provide me the CMAKE_PREFIX_PATH entry to edit. When I search for "PREFIX", the only one shows up is CMAKE_INSTALL_PREFIX. Am I not looking at the right place? Or did I miss something when installing cmake?

I am using cmake version 3.1.3 (and also tried 3.0.2), which is installed with MacPorts. And I did remember to check the "advanced" box for all options.

My CMakeLists.txt file is pretty simple

cmake_minimum_required (VERSION 3.0)
project (my_project CXX)
find_package (PNG REQUIRED)
include_directories (${PNG_INCLUDE_DIRS})
add_executable (my_executable test.cc)
target_link_libraries (my_executable ${PNG_LIBRARIES})

and I also made sure the /usr/local2/lib contains the libpng.dylib for cmake to search for.

In the CMakeCache.txt file, I found

//No help, variable specified on the command line.
CMAKE_PREFIX_PATH:UNINITIALIZED=/usr/local2

Thanks in advance for your help!

Ying Xiong
  • 4,578
  • 8
  • 33
  • 69
  • Can you share your project CMakeLists.txt? Also, do you see a CMAKE_PREFIX_PATH entry in your CMakeCache.txt file in your build directory? The cmake command you posted should have set an entry in the cache, which should show up when you toggle the advanced box. – atsui Mar 11 '15 at 02:52
  • @atsui Thanks for your response. Please see my edits about the `CMakeLists.txt` and `CMakeCache.txt` files. – Ying Xiong Mar 11 '15 at 03:12

1 Answers1

0

I believe if you make a /usr/local2/lib directory and place libpng.dylib there (instead of just /usr/local2), cmake should be able to pick it up. The manual suggests that it just uses CMAKE_PREFIX_PATH as the base.

atsui
  • 1,008
  • 10
  • 17
  • Yes, that is where I put `libpng.dylib`. I had a type-o in the question and fixed it. Thanks for pointing out. But `cmake` still cannot find it with the `CMAKE_PREFIX_PATH` hint. BTW, if I set `CMAKE_BUILD_PREFIX` to `/usr/local2`, it will find and link to the library there. – Ying Xiong Mar 11 '15 at 12:12
  • I'm don't think setting `CMAKE_BUILD_PREFIX` has an effect since it isn't a cmake special variable. At least I couldn't get it to work for me in a clean build. I think `cmake` might not do anything if you already have `/usr/local/lib/libpng.dylib` cached. Have you tried clearing the build directory and doing a clean build? – atsui Mar 11 '15 at 14:54
  • Actually I meant `CMAKE_INSTALL_PREFIX`. Sorry for the confusion. I tried to start a build directory from scratch, but it does not seem to help. – Ying Xiong Mar 11 '15 at 19:22