How to discard/not use a target from imported CMake file

I would like to use the Antlr framework in a project. I’m using CMake to build the project.

I would like to use the SHARED library version of Antlr, not the STATIC one. Its CMake file contains targets for both.

Antlr’s github site explicity tells me to use the following code:

find_package(antlr4-runtime REQUIRED)

# add runtime include directories on this project.
include_directories( ${ANTLR4_INCLUDE_DIR} )

# add runtime to project dependencies
add_dependencies( Parsertest antlr4_shared )

# add runtime to project link libraries
target_link_libraries( Parsertest PRIVATE
                       antlr4_shared)

(another target, antlr4_static, exists, but shouldn´t be used.)

I copied it exactly like this and am getting the following error:

CMake Error at /usr/lib64/cmake/antlr4-runtime/antlr4-targets.cmake:82 (message):
  The imported target "antlr4_static" references the file

     "/usr/lib/libantlr4-runtime.a"

  but this file does not exist.

I dont have the static library installed in my system as I have no intention of using it. Still, how do I make CMake stop looking for the wrong target in the first place? I use it nowhere in my CMakeLists.txt file and am puzzled by this behavior.

antlr4-runtime module is not part of CMake distribution. Each module is specific, so a generic answer cannot be given.

The best place to ask for support is the module’s developer.

It sounds like the package dependencies are not correct. The -devel package should also install the static library (or antlr can use different export sets and include them as they’re available).