Skip to content

Commit

Permalink
cmake: avoid testing when FetchContent by other project
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyiwu committed Sep 21, 2024
1 parent 5ef74f3 commit 6e167a3
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,27 @@ set(CMAKE_CXX_EXTENSIONS OFF)

ADD_DEFINITIONS(-O3 -g)

ADD_SUBDIRECTORY(test)
# Define a variable to check if this is the top-level project
if(NOT DEFINED CPPJIEBA_TOP_LEVEL_PROJECT)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CPPJIEBA_TOP_LEVEL_PROJECT ON)
else()
set(CPPJIEBA_TOP_LEVEL_PROJECT OFF)
endif()
endif()


option(CPPJIEBA_BUILD_TESTS "Build cppjieba tests" ${CPPJIEBA_TOP_LEVEL_PROJECT})

ENABLE_TESTING()
if(NOT MSVC)
ADD_TEST(NAME ./test/test.run COMMAND ./test/test.run)
ADD_TEST(NAME ./load_test COMMAND ./load_test)
if(CPPJIEBA_BUILD_TESTS)
ENABLE_TESTING()

ADD_SUBDIRECTORY(test)
if(NOT MSVC)
ADD_TEST(NAME ./test/test.run COMMAND ./test/test.run)
ADD_TEST(NAME ./load_test COMMAND ./load_test)
endif()
endif()


# ... other CMake configurations ...

0 comments on commit 6e167a3

Please sign in to comment.