-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
116 lines (93 loc) · 2.96 KB
/
CMakeLists.txt
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
# Define parameters
option(BUILD_SHARED_LIBRARY "Whether the shared library should be built." ON)
option(BUILD_STATIC_LIBRARY "Whether the static library should be built." OFF)
# Define project
project(libxml VERSION 0.1 LANGUAGES CXX)
# Set source files of the project
set(XML_SOURCE_FILES
src/parent-node.cpp
src/child-node.cpp
src/node.cpp
src/document.cpp
src/element.cpp
src/attribute.cpp
src/text.cpp
)
# Set header files of the project
set(XML_HEADER_FILES
include/node-interface.h
include/parent-node.h
include/child-node.h
include/node.h
include/iterator.h
include/document.h
include/element.h
include/attribute.h
include/text.h
)
# Set include directory of library
include_directories(include)
# Set compilation flags
set(CMAKE_CXX_FLAGS_DEFAULT "-O2 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_CXX_FLAGS "-Wall -Werror -fno-rtti" )
# Register dynamic library
if(BUILD_SHARED_LIBRARY)
# Add source files to library
add_library(xml SHARED ${XML_SOURCE_FILES})
# Set C++11 flag
target_compile_features(xml PRIVATE cxx_variadic_templates)
# Set targets properties
set_target_properties(xml PROPERTIES
VERSION ${libxml_VERSION}
SOVERSION ${libxml_VERSION}
)
# Install library
install(TARGETS xml
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
)
endif()
# Register static library
if(BUILD_STATIC_LIBRARY)
# Add source files to library
add_library(xml_static STATIC ${XML_SOURCE_FILES})
# Set C++11 flag
target_compile_features(xml_static PRIVATE cxx_variadic_templates)
# Set targets properties
set_target_properties(xml_static PROPERTIES
VERSION ${libxml_VERSION}
)
# Install library
install(TARGETS xml_static
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
)
endif()
if(BUILD_SHARED_LIBRARY OR BUILD_STATIC_LIBRARY)
# Install headers
install(FILES ${XML_HEADER_FILES}
DESTINATION "${CMAKE_INSTALL_PREFIX}/include/xml/${libxml_VERSION}"
)
endif()
# Set useful environment variables
set(XML_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(XML_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(XML_VERSION ${libxml_VERSION})
# Compile unit tests if requested
option(UNIT_TESTS "Compile and run unit tests." OFF)
if(UNIT_TESTS)
add_subdirectory(tests/ ${CMAKE_CURRENT_SOURCE_DIR}/tests/build/)
endif()
# Compile examples if requested
option(EXAMPLES "Compile and install examples." ON)
if(EXAMPLES)
add_subdirectory(examples/ ${CMAKE_CURRENT_SOURCE_DIR}/examples/build/)
endif()
# Generate doxygen documentation if requested
option(DOCUMENTATION "Generate HTML and PDF documentation." ON)
if(DOCUMENTATION)
add_subdirectory(doc/ ${CMAKE_CURRENT_SOURCE_DIR}/doc/build/)
endif()