Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to switch off building C++ tests, needed if used as sub-project #3624

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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