Skip to content

Commit 6c2f21a

Browse files
author
Alexandre jublot
committed
build: added CMake file for final users to let them include the library in their project
1 parent a672d97 commit 6c2f21a

File tree

3 files changed

+44
-43
lines changed

3 files changed

+44
-43
lines changed

CMakeLists.txt

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,33 @@ project(NetworkLibrary)
33

44
set(CMAKE_CXX_STANDARD 20)
55

6-
set(REPOSITORY repository_dir)
7-
8-
if (NOT TARGET asio)
9-
include(cmake/FindAsio.cmake)
10-
FIND_PACKAGE(asio REQUIRED)
11-
endif ()
12-
13-
14-
file(GLOB_RECURSE SRCS src/*.cpp)
15-
list(REMOVE_ITEM SRCS src/main.cpp)
16-
17-
file(GLOB_RECURSE ICLS include/*.hpp)
18-
file(GLOB_RECURSE PRIV_ICLS src/include/*.hpp)
6+
if (NOT TARGET PolymorphNetwork)
7+
if (NOT TARGET asio)
8+
include(cmake/FindAsio.cmake)
9+
FIND_PACKAGE(asio REQUIRED)
10+
endif ()
1911

20-
add_library(PolymorphNetwork ${SRCS} ${ICLS} ${PRIV_ICLS})
2112

22-
target_include_directories(PolymorphNetwork PUBLIC
23-
include
24-
)
13+
file(GLOB_RECURSE SRCS src/*.cpp)
14+
list(REMOVE_ITEM SRCS src/main.cpp)
2515

26-
target_include_directories(PolymorphNetwork PRIVATE
27-
src/include
28-
)
16+
file(GLOB_RECURSE ICLS include/*.hpp)
17+
file(GLOB_RECURSE PRIV_ICLS src/include/*.hpp)
2918

30-
target_link_libraries(PolymorphNetwork
31-
asio
32-
)
19+
add_library(PolymorphNetwork ${SRCS} ${ICLS} ${PRIV_ICLS})
20+
target_include_directories(PolymorphNetwork PUBLIC include)
21+
target_include_directories(PolymorphNetwork PRIVATE src/include)
22+
target_link_libraries(PolymorphNetwork asio)
23+
if(WIN32)
24+
# MSVC
25+
# /wd4100: unreferenced formal parameter (= unused parameter)
26+
target_compile_options(PolymorphNetwork PRIVATE /W4)
27+
endif()
28+
endif()
3329

3430
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
35-
if (NOT TARGET GTest::gtest_main)
36-
include(FetchContent)
37-
FetchContent_Declare(
38-
googletest
39-
GIT_REPOSITORY https://github.com/google/googletest.git
40-
GIT_TAG release-1.12.1
41-
)
42-
43-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
44-
FetchContent_MakeAvailable(googletest)
45-
endif ()
46-
31+
include(tests/cmake/FindGoogleTest.cmake)
4732
enable_testing()
4833

4934
add_subdirectory(tests)
50-
51-
5235
endif ()
53-
54-
if(WIN32)
55-
# MSVC
56-
# /wd4100: unreferenced formal parameter (= unused parameter)
57-
target_compile_options(PolymorphNetwork PRIVATE /W4)
58-
endif()

FindPolymorphNetworkLibrary.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.17)
2+
3+
if (NOT TARGET PolymorphNetwork)
4+
include(FetchContent)
5+
FetchContent_Declare(
6+
PolymorphNetwork
7+
GIT_REPOSITORY git@github.com:PolymorphEngine/NetworkLibrary.git
8+
GIT_TAG master
9+
)
10+
FetchContent_MakeAvailable(PolymorphNetwork)
11+
endif()

tests/cmake/FindGoogleTest.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.17)
2+
3+
if (NOT TARGET GTest::gtest_main)
4+
include(FetchContent)
5+
FetchContent_Declare(
6+
googletest
7+
GIT_REPOSITORY https://github.com/google/googletest.git
8+
GIT_TAG release-1.12.1
9+
)
10+
11+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
12+
FetchContent_MakeAvailable(googletest)
13+
endif ()

0 commit comments

Comments
 (0)