forked from srcML/srcML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
74 lines (58 loc) · 2.75 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
# SPDX-License-Identifier: GPL-3.0-only
##
# @file CMakeLists.txt
#
# @copyright Copyright (C) 2013-2024 srcML, LLC. (www.srcML.org)
#
# The master CMake project file for srcML
if(DEFINED ENV{VCPKG_ROOT} OR DEFINED CMAKE_TOOLCHAIN_FILE)
set(VCPKG_BUILD_TYPE "release")
endif()
cmake_minimum_required(VERSION 3.28)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# If performed here, before project(), then this prefix becomes part of the CMAKE_SYSTEM_PREFIX_PATH
# and then the installed version of srcML can be found by the tests without building srcml.
# Note that the default for the install prefix is "C:/Program Files (x86)/srcML", which contradicts
# the CMake documentation (https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html)
# Also note that without this, the install target places the files in "C:/Program Files (x86)/srcML",
# while the package installer places it in "C:/Program Files/srcML"
# Note that this overwrites any changes to the CMAKE_INSTALL_PREFIX from the command line cmake options.
if(WIN32 AND NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "C:/Program Files/srcML" CACHE PATH "Set Windows install dir" FORCE)
endif()
# Set libsrcml version from src/libsrcml/srcml.h
# Extract this before project() 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 everything
option(BUILD_ALL "Build all test, documentation, and examples" 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()
# Determine distribution
# Does not work for all distributions, but does work for supported Linux distributions
if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
cmake_host_system_information(RESULT DISTRO QUERY DISTRIB_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()
# Link the stdc++fs library if on gcc 7.5.0
if(CMAKE_CXX_COMPILER_VERSION STREQUAL "7.5.0")
link_libraries(stdc++fs)
endif()
# used as defaults for installation and packaging
include(GNUInstallDirs)
# Call at root so testing can be run at root
enable_testing()
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(doc)
add_subdirectory(examples)
# packaging
add_subdirectory(package)