Skip to content

Commit b0c2a18

Browse files
feat: don't build when used as FetchContent dependency.
Signed-off-by: Shashwat Agrawal <shashwatagrawal473@gmail.com>
1 parent 0c89d62 commit b0c2a18

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

CMakeLists.txt

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
cmake_minimum_required(VERSION 3.10)
22
project(tec.h C)
3-
4-
set(CMAKE_C_STANDARD 11)
3+
set(CMAKE_C_STANDARD 23)
54
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic")
6-
75
include_directories(include)
86

9-
file(GLOB_RECURSE SRC_FILES "src/*.c")
10-
11-
file(GLOB_RECURSE TEST_SOURCES "tests/*.c")
12-
13-
list(FILTER SRC_FILES EXCLUDE REGEX ".*/main\\.c$")
14-
15-
add_executable(main src/main.c ${SRC_FILES})
16-
add_executable(test_runner ${TEST_SOURCES} ${SRC_FILES})
7+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
8+
file(GLOB_RECURSE SRC_FILES "src/*.c")
9+
file(GLOB_RECURSE TEST_SOURCES "tests/*.c")
10+
list(FILTER SRC_FILES EXCLUDE REGEX ".*/main\\.c$")
1711

18-
add_custom_target(test
19-
COMMAND test_runner
20-
DEPENDS test_runner
21-
COMMENT "Running tests..."
22-
)
12+
add_executable(main src/main.c ${SRC_FILES})
13+
add_executable(test_runner ${TEST_SOURCES} ${SRC_FILES})
14+
add_custom_target(build_tests
15+
COMMAND test_runner
16+
DEPENDS test_runner
17+
COMMENT "Running tests..."
18+
)
19+
else()
20+
message(STATUS "tec.h: Header-only library (skipping executables)")
21+
endif()

0 commit comments

Comments
 (0)