-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
141 lines (107 loc) · 5.32 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
cmake_minimum_required(VERSION 3.0) # setting this is required
project(libswid)
set(VERSION_MAJOR 0)
set(VERSION_MINOR 0)
set(VERSION_PATCH 1)
set(VERSION_FULL "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
###############################################################################
## file globbing ##############################################################
###############################################################################
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
list(APPEND private_sources
${CMAKE_SOURCE_DIR}/src/loader-generic.cpp ${CMAKE_SOURCE_DIR}/src/loader-generic.h
${CMAKE_SOURCE_DIR}/src/loader-generic-notemplate.cpp
${CMAKE_SOURCE_DIR}/src/libswid.cpp
${CMAKE_SOURCE_DIR}/src/libswid-base.cpp
${CMAKE_SOURCE_DIR}/src/SWIDStruct.cpp ${CMAKE_SOURCE_DIR}/src/SWIDStruct.h
${CMAKE_SOURCE_DIR}/src/Translator.cpp ${CMAKE_SOURCE_DIR}/src/Translator.h
)
# We can't include extension-less files here, because they puzzle the coverage support:
# -> no append of ${CMAKE_SOURCE_DIR}/src/libswid
list(APPEND public_sources
${CMAKE_SOURCE_DIR}/src/libswid.h
${CMAKE_SOURCE_DIR}/src/libswid-base.h
${CMAKE_SOURCE_DIR}/src/swid-common.h
)
# You can use set(sources src/main.cpp) etc if you don't want to
# use globbing to find files automatically.
find_package(XercesC)
find_package(TinyXML)
find_package(SWIG)
find_package(PythonLibs 3)
find_package(codecov)
include(CMakeDependentOption)
CMAKE_DEPENDENT_OPTION(BUILD_XERCES_BACKEND "Whether to build Xerces-C backend" ON ${XercesC_FOUND} OFF)
CMAKE_DEPENDENT_OPTION(BUILD_TINYXML_BACKEND "Whether to build TinyXML backend" ON ${TinyXML_FOUND} OFF)
CMAKE_DEPENDENT_OPTION(BUILD_PYTHON_BINDINGS "Whether to build Python3 bindings" ON ${SWIG_FOUND} OFF)
if (BUILD_XERCES_BACKEND)
add_definitions(-DHAVE_XERCES)
add_definitions(-DSCHEMA_ABS_PATH="${CMAKE_SOURCE_DIR}/resources/schema/schema.xsd")
list(APPEND private_sources
${CMAKE_SOURCE_DIR}/src/loader-xerces.cpp ${CMAKE_SOURCE_DIR}/src/loader-xerces.h
)
endif()
if (BUILD_TINYXML_BACKEND)
add_definitions(-DHAVE_TINYXML)
list(APPEND private_sources
${CMAKE_SOURCE_DIR}/src/loader-tinyxml.cpp ${CMAKE_SOURCE_DIR}/src/loader-tinyxml.h
)
endif()
message(STATUS "Xerces-c library found: ${XercesC_FOUND}")
message(STATUS "TinyXML library found: ${TinyXML_FOUND}")
message(STATUS "SWIG found: ${SWIG_FOUND}")
message(STATUS "Building Xerces-c XML backend: ${BUILD_XERCES_BACKEND}")
message(STATUS "Building TinyXML XML backend: ${BUILD_TINYXML_BACKEND}")
message(STATUS "Building Python 3 bindings: ${BUILD_PYTHON_BINDINGS}")
###############################################################################
## target definitions #########################################################
###############################################################################
# The data is just added to the executable, because in some IDEs (QtCreator)
# files are invisible when they are not explicitly part of the project.
# add_executable(swid-util src/main.cpp)
# Just for example add some compiler flags.
# target_compile_options(swid-util PUBLIC -std=c++11 -Wall)
# This allows to include files relative to the root of the src directory with a <> pair
# target_include_directories(swid-util PUBLIC src)
add_library(swid SHARED)
target_sources(swid PUBLIC ${public_sources} PRIVATE ${private_sources})
# target_link_libraries(swid-util swid)
set_property(TARGET swid PROPERTY CXX_STANDARD 11)
set_property(TARGET swid PROPERTY CXX_STANDARD_REQUIRED ON)
target_compile_options(swid PUBLIC -Wall)
target_include_directories(swid PUBLIC src ${XercesC_INCLUDE_DIRS} ${TinyXML_INCLUDE_DIRS})
target_link_libraries(swid ${XercesC_LIBRARIES} ${TinyXML_LIBRARIES})
# This copies all resource files in the build directory.
# We need this, because we want to work with paths relative to the executable.
file(COPY ${data} DESTINATION resources)
enable_testing()
add_subdirectory("test")
# Python bindings - put everything to a 'swid' package directory
add_subdirectory("src/swig" "swid")
add_coverage(swid)
list(APPEND LCOV_REMOVE_PATTERNS "'/usr/*'")
list(APPEND LCOV_REMOVE_PATTERNS "'${CMAKE_SOURCE_DIR}/test/*'")
coverage_evaluate()
###############################################################################
## packaging ##################################################################
###############################################################################
# All install commands get the same destination. this allows us to use paths
# relative to the executable.
install(TARGETS swid
LIBRARY DESTINATION lib)
install(FILES ${CMAKE_SOURCE_DIR}/src/include/libswid DESTINATION include)
install(FILES ${CMAKE_SOURCE_DIR}/src/libswid-base.h src/SWIDStruct.h DESTINATION include/swid)
# Now comes everything we need, to create a package
# there are a lot more variables you can set, and some
# you need to set for some package types, but we want to
# be minimal here.
set(CPACK_PACKAGE_NAME "libSWID")
set(CPACK_PACKAGE_VERSION "${VERSION_FULL}")
# We don't want to split our program up into several incomplete pieces.
set(CPACK_MONOLITHIC_INSTALL 1)
SET(CPACK_PACKAGE_VENDOR "libswid upstream")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_SOURCE_IGNORE_FILES "^\\\\..*;sonar-project.properties;codecov.yml")
# This must be last
include(CPack)