-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
71 lines (52 loc) · 2.29 KB
/
CMakeLists.txt
File metadata and controls
71 lines (52 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
cmake_minimum_required(VERSION 3.12.4)
project (helloworld)
option(BUILD_BINARIES "Build the binaries in {project}/bin directory" ON)
option(BUILD_UNITTEST "Build the unittest in {project}/test directory" ON)
option(BUILD_STATIC_LIBS "Build the static library" ON)
option(BUILD_SHARED_LIBS "Build the shared library" ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
find_package(glog REQUIRED)
find_package(gflags REQUIRED)
# dir to include
set(HELLOWORLD_INCLUDE_DIRECTORIES include)
add_compile_options("-Wall" "-W" "-Wextra" "-fPIC")
add_subdirectory(gtest)
# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
# headers to install
file(GLOB_RECURSE HELLOWORLD_PUBLIC_HEADER include/*)
# source for the lib
file(GLOB_RECURSE HELLOWORLD_SOURCE src/*)
add_library(helloworld_obj OBJECT ${HELLOWORLD_SOURCE})
target_include_directories(helloworld_obj PUBLIC ${HELLOWORLD_INCLUDE_DIRECTORIES})
target_link_libraries(helloworld_obj PUBLIC ${GLOG_LIBRARIES} ${GFLAGS_LIBRARIES})
target_include_directories(helloworld_obj PUBLIC ${GLOG_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS})
if (${BUILD_UNITTEST})
add_subdirectory(test)
enable_testing()
endif()
if (${BUILD_BINARIES})
add_subdirectory(bin)
endif()
if (${BUILD_STATIC_LIBS})
add_library(helloworld-static STATIC $<TARGET_OBJECTS:helloworld_obj>)
# install instructions
set_target_properties(helloworld-static PROPERTIES PUBLIC_HEADER "${HELLOWORLD_PUBLIC_HEADER}")
install(TARGETS helloworld-static PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include/helloworld
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif()
if (${BUILD_SHARED_LIBS})
add_library(helloworld-dynamic SHARED $<TARGET_OBJECTS:helloworld_obj>)
# install instructions
set_target_properties(helloworld-dynamic PROPERTIES PUBLIC_HEADER "${HELLOWORLD_PUBLIC_HEADER}")
install(TARGETS helloworld-dynamic PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include/helloworld
LIBRARY DESTINATION lib)
endif()