Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make CMake find google protobuf on windows?

I am using Google Protobuf with CMake. On Linux the Protobuf library is found by:

find_package( Protobuf REQUIRED ) 

CMake knows where to look for the library. How though do I get this to work in Windows? Is there an environment variable I should create, such as PROTOBUF_LIB? I have looked in FindProtobuf.cmake but cannot work out what is required.

like image 264
John W Avatar asked Nov 22 '10 15:11

John W


3 Answers

I also struggled with this. To be more clear.

On Windows (7, similar on older windows): Start → Control Panel → System → Advanced System Settings → Environment Variables

Then either on the top panel or the bottom panel (if you want it to apply to other users do it on the bottom), create two new variables. The 1st one is

  • CMAKE_INCLUDE_PATH which points at the bottom of your include path (should contain a "google" folder)
  • CMAKE_LIBRARY_PATH which should contain "libprotobuf" "libprotobuf-lite" "liteprotoc" .lib files.

After you create the variables press OK and then re-start cmake (or clean the cache).

like image 130
Jubei Avatar answered Nov 18 '22 03:11

Jubei


Newest protobuf v3 have CMake support out of the box.

You could use protobuf repository as submodule and just use

add_subdiretory("third-party/protobuf/cmake")

to get all protobuf targets. Then you can add dependency to protobuf with

target_link_libraries(YourLibrary libprotobuf libprotobuf-lite libprotoc)

Another possible way is available. With protobuf's CMake configuration you can build and install protobuf binaries once and use them across several projects in your development:

git clone https://github.com/google/protobuf.git
mkdir protobuf\tmp
cd protobuf\tmp
cmake ..\cmake
cmake --build .
cmake --build . --target install

Then you can use find_package with hint paths like

find_package(protobuf REQUIRED
    HINTS
       "C:/Program Files/protobuf"
        "C:/Program Files (x86)/protobuf")
if (NOT PROTOBUF_FOUND)
    message("protobuf not found")
    return()
endif()

Hope this helps.

like image 22
hal Avatar answered Nov 18 '22 03:11

hal


Protobuf on windows calls find_library which will search your PATH and LIB variables.

like image 4
RobertJMaynard Avatar answered Nov 18 '22 02:11

RobertJMaynard