UCL / GreatCMakeCookOff

Bunch of CMake pain in the baker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LookUPGtest broken with Ninja builds

jenshnielsen opened this issue · comments

I am not sure if this happens because Ninja doesn't honor the dependencies correctly or we are doing someting wrong. Building HJCFIT with Ninja results in

ninja: error: 'external/lib/libgtest.a', needed by 'likelihood/test_likelihood', missing and no known rule to make it

This happens since Ninja apparently goes looking for the library before building the dependency regardless of the fact that there is but a

    add_executable(test_${name} ${source})
    if(MSVC)
      target_link_libraries(test_${name} ${EXTERNAL_ROOT}/lib/gtest.lib)
    else(MSVC)
      target_link_libraries(test_${name} ${EXTERNAL_ROOT}/lib/libgtest.a)
    endif(MSVC)
    if(CMAKE_THREAD_LIBS_INIT)
      target_link_libraries(test_${name} ${CMAKE_THREAD_LIBS_INIT})
    endif(CMAKE_THREAD_LIBS_INIT)

    add_dependencies(test_${name} Lookup-GTest)

I tried changing the dependencies to create an explicit library in CMake land

+add_library(mylibgtest UNKNOWN IMPORTED)
+set_property(TARGET mylibgtest PROPERTY
+    IMPORTED_LOCATION ${EXTERNAL_ROOT}/lib/libgtest.a)
+add_dependencies(mylibgtest Lookup-GTest)

and replace

-      target_link_libraries(test_${name} ${EXTERNAL_ROOT}/lib/libgtest.a)
+      target_link_libraries(test_${name} mylibgtest)

but with no effect.

With ninja, you have to call build twice. Unfortunately, ninja cannot be made to reload it's configuration (AFAIK) so the newly downloaded codes are only found on the second pass.

Another option is to do ninja lookup_dependencies and then ninja

Works thanks

To be clean, running ninja; ninja doesn't work. The first run of ninja never gets to run the lookup but fails before that. Doing ninja lookup_dependencies; ninja works

This is in DCProgs?

It's not that important I was just curious if there was something obvious that I have missed.