Skip to content

Commit 8609d07

Browse files
Pierre-Luc GagnéCopilot
andcommitted
feat: only build tests and examples when top-level project
Guard tests and examples subdirectories with: if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) This prevents DSMySQL's tests from being built when consumed as a FetchContent dependency by other projects. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0bba8ba commit 8609d07

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,17 @@ endif()
126126
# Add library
127127
add_subdirectory(lib)
128128

129-
# Add tests
130-
if(BUILD_TESTING)
131-
add_subdirectory(tests)
132-
endif()
129+
# Add tests and examples only when DSMySQL is the top-level project
130+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
131+
# Add tests
132+
if(BUILD_TESTING)
133+
add_subdirectory(tests)
134+
endif()
133135

134-
# Add examples
135-
if(BUILD_EXAMPLES)
136-
add_subdirectory(examples)
136+
# Add examples
137+
if(BUILD_EXAMPLES)
138+
add_subdirectory(examples)
139+
endif()
137140
endif()
138141

139142
# Display configuration summary

0 commit comments

Comments
 (0)