2

I'm trying to build the specialized Youtube API, which is included in the standard distribution of the google-api-cpp-client library. The documentation states:

If you download the C++ libraries and unzip them into the service_apis directory at the root of the source installation for this SDK then the default build scripts will automatically build them.

However, the build scripts do not. Building the samples which are included in the distribution reveals this quite clearly.

Linking CXX executable ../../bin/calendar_sample
ld: library not found for -lgoogle_calendar_api

The tail of the root CMakeLists.txt reads as follows:

add_subdirectory(src)

if (googleapis_build_samples)
  set(googleapis_build_service_apis true)  # force on
endif()
if (googleapis_build_service_apis)
  add_subdirectory(service_apis)
endif()

# Build samples after the service apis
# but keep them under src
if (googleapis_build_samples)
  add_subdirectory(src/samples)
endif()

Which eventually leads to this CMakeLists.txt (in the root of the service_apis directory):

file(GLOB all_valid_subdirs RELATIVE
          ${CMAKE_CURRENT_SOURCE_DIR} "*/CMakeLists.txt")

foreach(dir ${all_valid_subdirs})
    message(STATUS "path = ${dir}")
    if(${dir} MATCHES "^([^/]*)//CMakeLists.txt")
        string(REGEX REPLACE
               "^([^/]*)//CMakeLists.txt" "\\1" dir_trimmed ${dir})
        add_subdirectory(${dir_trimmed})
    endif()
endforeach(dir)

I've put a message output inside the if statement. It seems the add_subdirectory call is never reached. The foreach does iterate through all the subdirectories though.

Why does the regex comparison fail?

Thijs
  • 714
  • 9
  • 23

1 Answers1

2

I've actually found the error while finishing up this question. The regex comparison contains an extra forward slash. The following regex will successfully include the libraries.

^([^/]*)/CMakeLists.txt

I will raise a bug with the developer.

Thijs
  • 714
  • 9
  • 23
  • Another script writer who doesn't understand regex. The fact is `^([^/]*)/CMakeLists.txt` will only match a single subdir before `/CMakeList.txt`. Group 1 also matches the empty string before `/CMakeLists.txt`, or a bunch of whitespaces (including line breaks) –  Oct 13 '15 at 19:45
  • So `[\S/]+/CMakeLists.txt` would be better? – Thijs Oct 15 '15 at 14:09
  • Well, not sure what this `GLOB ___ RELATIVE` does, whether it could include `sub1/sub2/sub3`/CMakeLists.txt multiple sub dirs., or a single one. He's using an anchor `^` and a one-sub filter `[^/]+` which won't match multiple's. If you want multiples use `^(.+)/CMakeLists.txt`. if you want a single only, use `^([^/]+)/CMakeLists.txt` For both ways you can trim leading tabs/spaces with `^\s*(` ... –  Oct 15 '15 at 19:21
  • The file /google-api-cpp-client-master/service_apis/CMakeLists.txt does have a extra slash and removing it worked for me – Anish Aug 11 '16 at 04:05