Skip to content

Commit

Permalink
Allow to choose to switch off building tests in C++ (#3624)
Browse files Browse the repository at this point in the history
The new option to cmake ANTLR_BUILD_CPP_TESTS is default
on (so the behavior is as before), but it provides a way to
switch off if not needed.

The C++ tests pull in an external dependency (googletests),
which might conflict if ANTLR is used as a subproject in
another cmake project.

Signed-off-by: Henner Zeller <h.zeller@acm.org>
  • Loading branch information
hzeller committed Apr 8, 2022
1 parent 38de75b commit 2095446
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions runtime/Cpp/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
option(ANTLR_BUILD_CPP_TESTS "Build C++ tests." ON)

include_directories(
${PROJECT_SOURCE_DIR}/runtime/src
${PROJECT_SOURCE_DIR}/runtime/src/atn
Expand Down Expand Up @@ -35,35 +37,37 @@ add_custom_target(make_lib_output_dir ALL
add_dependencies(antlr4_shared make_lib_output_dir)
add_dependencies(antlr4_static make_lib_output_dir)

include(FetchContent)
if (ANTLR_BUILD_CPP_TESTS)
include(FetchContent)

FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/e2239ee6043f73722e7aa812a459f54a28552929.zip
)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/e2239ee6043f73722e7aa812a459f54a28552929.zip
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(googletest)
FetchContent_MakeAvailable(googletest)

file(GLOB libantlrcpp_TESTS
"${PROJECT_SOURCE_DIR}/runtime/tests/*.cpp"
)
file(GLOB libantlrcpp_TESTS
"${PROJECT_SOURCE_DIR}/runtime/tests/*.cpp"
)

add_executable(
antlr4_tests
${libantlrcpp_TESTS}
)
add_executable(
antlr4_tests
${libantlrcpp_TESTS}
)

target_link_libraries(
antlr4_tests
antlr4_static
gtest_main
)
target_link_libraries(
antlr4_tests
antlr4_static
gtest_main
)

include(GoogleTest)
include(GoogleTest)

gtest_discover_tests(antlr4_tests)
gtest_discover_tests(antlr4_tests)
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(antlr4_shared ${UUID_LIBRARIES})
Expand Down

0 comments on commit 2095446

Please sign in to comment.