Skip to content

Commit af61a8f

Browse files
committed
Don't build tests/examples if used by another project
1 parent 6fa1399 commit af61a8f

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

CMakeLists.txt

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,32 @@ project(binsparse)
44
set(CMAKE_CXX_STANDARD 20)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66

7-
set(CMAKE_CXX_FLAGS "-O3")
8-
9-
include(FetchContent)
10-
FetchContent_Declare(
11-
googletest
12-
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
13-
)
14-
# For Windows: Prevent overriding the parent project's compiler/linker settings
15-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
16-
FetchContent_MakeAvailable(googletest)
17-
18-
FetchContent_Declare(
19-
fmt
20-
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
21-
GIT_TAG 10.1.1)
22-
FetchContent_MakeAvailable(fmt)
23-
247
find_package(HDF5 REQUIRED COMPONENTS CXX)
258
add_subdirectory(include)
26-
add_subdirectory(examples)
27-
add_subdirectory(test)
9+
10+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
11+
# Dependencies needed only for examples/test
12+
13+
# Google test
14+
include(FetchContent)
15+
FetchContent_Declare(
16+
googletest
17+
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
18+
)
19+
# For Windows: Prevent overriding the parent project's compiler/linker settings
20+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
21+
FetchContent_MakeAvailable(googletest)
22+
23+
# fmt
24+
FetchContent_Declare(
25+
fmt
26+
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
27+
GIT_TAG 10.1.1)
28+
FetchContent_MakeAvailable(fmt)
29+
30+
set(CMAKE_CXX_FLAGS "-O3 -march=native")
31+
32+
add_subdirectory(examples)
33+
add_subdirectory(test)
34+
35+
endif()

0 commit comments

Comments
 (0)