37

On a project I develop on, we're using cmake to compile our service. Currently, we need to get data for Qt from 3 different locations and I'm curious if there's a way to run one cmake command over three separate ones.

What we currently use:

cmake -G "Visual Studio 12 2013" -DWITH_SERVER=1 -DCMAKE_PREFIX_PATH=C:\Qt\5.5\msvc2013\lib\cmake ..
cmake -G "Visual Studio 12 2013" -DWITH_SERVER=1 -DCMAKE_PREFIX_PATH=C:\protobuf\src ..
cmake -G "Visual Studio 12 2013" -DWITH_SERVER=1 -DCMAKE_PREFIX_PATH=C:\protobuf\cmake\build\Release ..

We've attempted to pass the same flag 3 times and separating the paths with : and ;, but none seem to work as expected.

3
  • 2
    Do you need multiple entries in CMAKE_PREFIX_PATH or I misunderstood you? If so then use -DCMAKE_PREFIX_PATH="C:\Qt\5.5\msvc2013\lib\cmake;C:\protobuf\src;C:\protobuf\cmake\build\Release"
    – ixSci
    Jul 7, 2015 at 5:12
  • Yes, I need to have multiple entries for the prefix path. When I tried that earlier it didn't seem to work as expected, ending after the first option
    – ZeldaZach
    Jul 7, 2015 at 5:14
  • I've just tried it and it prints as it should: message("!!!!!! " ${CMAKE_PREFIX_PATH}) Running with the aforementioned string produces the following: !!!!!! C:\Qt\5.5\msvc2013\lib\cmakeC:\protobuf\srcC:\protobuf\c??make\build\Release Note the question marks in the 3rd path. Something is not right with the string - seems like some unicode character there
    – ixSci
    Jul 7, 2015 at 5:20

1 Answer 1

42

To provide multiple paths in the CMAKE_PREFIX_PATH variable you need to delimit each entry by ;(semicolon). So your command will look like:

cmake -DCMAKE_PREFIX_PATH="C:\Qt\5.5\msvc2013\lib\cmake;C:\protobuf\src;C:\protobuf\c‌​make\build\Release"

To check if everything alright with the provided paths you can use the following code in the cmake file:

foreach(path ${CMAKE_PREFIX_PATH})
  message("Path: " ${path})
endforeach(path)

It will print every path provided.

5
  • 1
    Does not seem to work in Jenkins 2.60.2 and CMake 3.9.1.
    – StarShine
    Aug 28, 2017 at 13:30
  • cmake -DCMAKE_PREFIX_PATH=/home/Olumide/src/project/Release/install/lib/cmake;/home/Olumide/src/project/Release/cmake . does not work in cmake version: 3.19.1. (Ubuntu 18.04.5 LTS)
    – Olumide
    Apr 5, 2021 at 4:05
  • Commenting on the comment. It didn't work because you are missing the quotes Aug 5, 2021 at 23:36
  • @Olumide commenting on the comment on the comment: when you don't use quotes around -D...=...;..., the shell can interpret special characters instead of treating them as part of a string literal. In bash, ; is a command separator.
    – user
    Sep 5, 2022 at 19:36
  • Another option to get it to work might be to put the first quote right at the start: "-DCMAKE_PREFIX_PATH=/path/1;/path/2" (needed this on linux with cmake 3.7.1)
    – Amfasis
    Oct 25, 2022 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.