forked from srcML/srcML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
110 lines (91 loc) · 3.69 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
##
# @file CMakeLists.txt
#
# @copyright Copyright (C) 2013-2019 srcML, LLC. (www.srcML.org)
#
# The srcML Toolkit is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# The srcML Toolkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the srcML Toolkit; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# The master CMake project file for srcML
cmake_minimum_required(VERSION 3.14)
# Set libsrcml version from src/libsrcml/srcml.h
# Extract this first because manually setting major, minor, and patch leads to bugs
file(STRINGS "${CMAKE_SOURCE_DIR}/src/libsrcml/srcml.h" SRCML_HEADER REGEX "SRCML_VERSION_STRING")
string(REGEX MATCH "\"([0-9.]+)\"" _ "${SRCML_HEADER}")
project(srcML VERSION "${CMAKE_MATCH_1}" HOMEPAGE_URL "https://www.srcML.org")
message(STATUS "Project version: ${PROJECT_VERSION}")
# Turn ON/OFF tests
option(BUILD_CLIENT_TESTS "Build srcml client tests" ON)
option(BUILD_LIBSRCML_TESTS "Build unit tests for libsrcml" OFF)
option(BUILD_PARSER_TESTS "Include tests for parser" OFF)
# Turn ON building all tests
option(BUILD_ALL_TESTS "Build all tests" OFF)
if(BUILD_ALL_TESTS)
set(BUILD_CLIENT_TESTS ON)
set(BUILD_LIBSRCML_TESTS ON)
set(BUILD_PARSER_TESTS ON)
endif()
# Turn ON/OFF building examples
option(BUILD_EXAMPLES "Build examples usage files for libsrcml" OFF)
# Turn ON/OFF building documentation
option(BUILD_CLIENT_DOC "Build client documentation" OFF)
option(INSTALL_CLIENT_DOC "Install (but do not build) client documentation" OFF)
option(BUILD_LIBSRCML_DOC "Build libsrcml documentation" OFF)
if(NOT BUILD_CLIENT_DOC)
set(INSTALL_CLIENT_DOC ON)
endif()
# Turn ON building all documentation
option(BUILD_ALL_DOCS "Build all documentation" OFF)
if(BUILD_ALL_DOCS)
set(BUILD_CLIENT_DOC ON)
set(BUILD_LIBSRCML_DOC ON)
endif()
# Turn ON everything
option(BUILD_ALL "Build all test, documentation, and examples" OFF)
if(BUILD_ALL)
set(BUILD_ALL_TESTS ON)
set(BUILD_EXAMPLES ON)
set(BUILD_ALL_DOCS ON)
endif()
# Build options
option(BUILD_LIBSRCML_STATIC "Build a static version of libsrcml" ON)
option(LINK_LIBSRCML_STATIC "Link srcml client, tests, and examples with static version of libsrcml" OFF)
# The default configuration is to compile in Release mode
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
# Dynamic Load libraries (Unix only)
if(NOT WIN32)
option(DYNAMIC_LOAD_ENABLED "Dynamically load some libraries such as libxslt and libexslt" ON)
endif()
enable_testing()
include(CTest)
# Determine distribution
# Does not work for all distributions, but does work for supported Linux distributions
if(EXISTS /etc/os-release)
file(STRINGS /etc/os-release DISTRO REGEX "^NAME=")
endif()
# Fedora and CentOS do not put /usr/local/{bin,lib64} on the default search paths
# So change installation to /usr
if(DISTRO AND DISTRO MATCHES "CentOS|Fedora")
set(CMAKE_INSTALL_PREFIX /usr)
endif()
# used as defaults for installation and packaging
include(GNUInstallDirs)
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(doc)
add_subdirectory(examples)
# packaging
add_subdirectory(package)