title: Antlr4 with C++ and CMake
body: <p>I'm trying to use antlr4 with C++.  I have the following CMakeLists.txt in my root directory:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.10)
  project(demo VERSION 0.1 DESCRIPTION "demo")
  
  include_directories(${CMAKE_CURRENT_BINARY_DIR})
  
  set(CMAKE_CXX_STANDARD 17)
  #############################################################################
  # ANTLR SPECIFIC CMAKE COMMANDS
  # This is derived from: https://github.com/blorente/antlr-4.7-cpp-cmake-base
  #############################################################################
  # Set the ocation of the JAR.
  set(ANTLR4CPP_JAR_LOCATION ${CMAKE_SOURCE_DIR}/antlr/jar/antlr.jar)
  
  # Add external build for antlrcpp.
  include (${CMAKE_SOURCE_DIR}/antlr/runtime/ExternalAntlr4Cpp.cmake)
  
  # add antrl4cpp artifacts to project environment.
  include_directories( ${ANTLR4CPP_INCLUDE_DIRS} )
  link_directories( ${ANTLR4CPP_LIBS} )
  # message(WARNING "Found antlr4cpp libs: ${ANTLR4CPP_LIBS} and includes: ${ANTLR4CPP_INCLUDE_DIRS} ")
  
  # Build the lexer/parser .h/.cpp files off the g4 grammar files.
  antlr4cpp_process_grammar(demo demoparser
      ${CMAKE_SOURCE_DIR}/grammar/DemoLexer.g4
      ${CMAKE_SOURCE_DIR}/grammar/DemoParser.g4)
  
  # include the generated files from the grammar/lexer.
  include_directories(${antlr4cpp_include_dirs_demoparser})
  #############################################################################
  
  # Build demo
  add_executable(demo main.cpp ${antlr4cpp_src_files_demoparser})
  # Add dependencies for antlr
  add_dependencies(demo antlr4cpp antlr4cpp_generation_demoparser)
  target_link_libraries(demo antlr4-runtime)
  </code></pre>
  
  <p>I have, more or less, copied the example from: <a href="https://github.com/blorente/antlr-4.7-cpp-cmake-base" rel="noreferrer">the "official" cmake/antlr tutorial</a>.  For brevity I have omitted the contents of <code>include (${CMAKE_SOURCE_DIR}/antlr/runtime/ExternalAntlr4Cpp.cmake)</code></p>
  
  <p>So the files are all in the same structure, except the jar.  I just include it as a project file and, as you can see from the <code>set(ANTLR4CPP_JAR_LOCATION)</code> command, it resides where I want it.</p>
  
  <p>When I build this, I get this error:</p>
  
  <pre><code>dyld: Library not loaded: libantlr4-runtime.4.7.1.dylib
  Referenced from: /path/to/demo/cmake-build-debug/demo
  Reason: image not found
  </code></pre>
  
  <p>However, when I look in: <code>/path/to/demo/cmake-build-debug/external/antlr4cpp/lib/</code> I see the <code>libantlr4-runtime.4.7.1.dylib</code> file that should be referenced by using the <code>target_link_libraries(demo antlr4-runtime)</code> command.  There are static libraries in there as well.</p>
  
  <p>Am I missing something?  Why is CMake not finding the static or dylib files it's supposed to?</p>