title: cmake doesn't recognize dependency on static lz4
body: <p>I'm trying to link against a statically built lz4. As an example I'm using a hello world project</p>
  <pre><code>$ tree hello-world/
  hello-world/
  ├── CMakeLists.txt
  └── main.cpp
  
  0 directories, 2 files
  
  $ cat main.cpp
  #include &lt;iostream&gt;
  
  int main()
  {
      std::cout &lt;&lt; &quot;Hello World!\n&quot;;
      return 0;
  }
  
  $ cat CMakeLists.txt
  cmake_minimum_required(VERSION 3.12.2)                                                                                                                                                                                                                                                                 
  project(hello-world)
  
  set(CMAKE_VERBOSE_MAKEFILE ON)
  
  set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
  set(CMAKE_CXX_STANDARD 17)
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
  set(CMAKE_CXX_EXTENSIONS OFF)
  
  include(FetchContent)
  
  # ================ lz4 ================
  option(LZ4_BUILD_CLI &quot;Build lz4 program&quot; OFF)
  option(LZ4_BUILD_LEGACY_LZ4C &quot;Build lz4c progam with legacy argument support&quot; OFF)
  # Per lz4 documentation, https://github.com/lz4/lz4/blob/d44371841a2f1728a3f36839fd4b7e872d0927d3/build/cmake/CMakeLists.txt#L39,
  # need to set LZ4_BUNDLED_MODE to anything but empty string
  set(LZ4_BUNDLED_MODE &quot;ON&quot;)
  
  set(LZ4_REPO &quot;https://github.com/lz4/lz4&quot;)
  set(LZ4_REPO_TAG &quot;v1.9.3&quot;)
  message(STATUS &quot;Fetching ${LZ4_REPO} ${LZ4_REPO_TAG}&quot;)
  FetchContent_Declare(
      lz4
      GIT_REPOSITORY ${LZ4_REPO}
      GIT_TAG        ${LZ4_REPO_TAG}
      )
  
  FetchContent_GetProperties(lz4)
  if(NOT lz4_POPULATED)
      FetchContent_Populate(lz4)
  
      message(STATUS &quot;running body&quot;)
      add_subdirectory(${lz4_SOURCE_DIR}/build/cmake ${lz4_BINARY_DIR})
      include_directories(${lz4_SOURCE_DIR}/lib)
  endif()
  set(LZ4_STATIC_LIBRARY &quot;${lz4_BINARY_DIR}/liblz4.a&quot;)
  message(STATUS ${lz4_SOURCE_DIR})
  message(STATUS ${lz4_BINARY_DIR})
  
  add_executable(${PROJECT_NAME} main.cpp)
  target_link_libraries(${PROJECT_NAME} ${LZ4_STATIC_LIBRARY})
  </code></pre>
  <p>Here is what I'm getting when I build and compile the project</p>
  <pre><code>$ mkdir build
  $ cd build
  $ cmake ..
  -- The C compiler identification is GNU 9.3.0
  -- The CXX compiler identification is GNU 9.3.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/cc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: /usr/bin/c++ - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Fetching https://github.com/lz4/lz4 v1.9.3
  -- running body
  CMake Deprecation Warning at build/_deps/lz4-src/build/cmake/CMakeLists.txt:37 (cmake_minimum_required):
    Compatibility with CMake &lt; 2.8.12 will be removed from a future version of
    CMake.
  
    Update the VERSION argument &lt;min&gt; value or use a ...&lt;max&gt; suffix to tell
    CMake that the project does not need compatibility with older versions.
  
  
  -- Performing Test CFLAG_Wall
  -- Performing Test CFLAG_Wall - Success
  -- Performing Test CFLAG_Wextra
  -- Performing Test CFLAG_Wextra - Success
  -- Performing Test CFLAG_Wundef
  -- Performing Test CFLAG_Wundef - Success
  -- Performing Test CFLAG_Wcast_qual
  -- Performing Test CFLAG_Wcast_qual - Success
  -- Performing Test CFLAG_Wcast_align
  -- Performing Test CFLAG_Wcast_align - Success
  -- Performing Test CFLAG_Wshadow
  -- Performing Test CFLAG_Wshadow - Success
  -- Performing Test CFLAG_Wswitch_enum
  -- Performing Test CFLAG_Wswitch_enum - Success
  -- Performing Test CFLAG_Wdeclaration_after_statement
  -- Performing Test CFLAG_Wdeclaration_after_statement - Success
  -- Performing Test CFLAG_Wstrict_prototypes
  -- Performing Test CFLAG_Wstrict_prototypes - Success
  -- Performing Test CFLAG_Wpointer_arith
  -- Performing Test CFLAG_Wpointer_arith - Success
  -- Performing Test CFLAG_W4
  -- Performing Test CFLAG_W4 - Failed
  -- /tmp/hello-world/build/_deps/lz4-src
  -- /tmp/hello-world/build/_deps/lz4-build
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /tmp/hello-world/build
  $ make
  /opt/cmake-3.19.5-Linux-x86_64/bin/cmake -S/tmp/hello-world -B/tmp/hello-world/build --check-build-system CMakeFiles/Makefile.cmake 0
  /opt/cmake-3.19.5-Linux-x86_64/bin/cmake -E cmake_progress_start /tmp/hello-world/build/CMakeFiles /tmp/hello-world/build//CMakeFiles/progress.marks
  make  -f CMakeFiles/Makefile2 all
  make[1]: Entering directory '/tmp/hello-world/build'
  make  -f CMakeFiles/hello-world.dir/build.make CMakeFiles/hello-world.dir/depend
  make[2]: Entering directory '/tmp/hello-world/build'
  cd /tmp/hello-world/build &amp;&amp; /opt/cmake-3.19.5-Linux-x86_64/bin/cmake -E cmake_depends &quot;Unix Makefiles&quot; /tmp/hello-world /tmp/hello-world /tmp/hello-world/build /tmp/hello-world/build /tmp/hello-world/build/CMakeFiles/hello-world.dir/DependInfo.cmake --color=
  Scanning dependencies of target hello-world
  make[2]: Leaving directory '/tmp/hello-world/build'
  make  -f CMakeFiles/hello-world.dir/build.make CMakeFiles/hello-world.dir/build
  make[2]: Entering directory '/tmp/hello-world/build'
  [ 14%] Building CXX object CMakeFiles/hello-world.dir/main.cpp.o
  /usr/bin/c++  -I/tmp/hello-world/build/_deps/lz4-src/lib -std=c++17 -o CMakeFiles/hello-world.dir/main.cpp.o -c /tmp/hello-world/main.cpp
  make[2]: *** No rule to make target '_deps/lz4-build/liblz4.a', needed by 'hello-world'.  Stop.
  make[2]: Leaving directory '/tmp/hello-world/build'
  make[1]: *** [CMakeFiles/Makefile2:118: CMakeFiles/hello-world.dir/all] Error 2
  make[1]: Leaving directory '/tmp/hello-world/build'
  make: *** [Makefile:106: all] Error 2
  </code></pre>
  <p>I thought because of <code>add_subdirectory(${lz4_SOURCE_DIR}/build/cmake ${lz4_BINARY_DIR})</code> it should be working, however clearly that's not the case. What am I missing?</p>