forked from srcML/srcML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
srcMLConfig.cmake.in
67 lines (56 loc) · 2.41 KB
/
srcMLConfig.cmake.in
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
@PACKAGE_INIT@
cmake_minimum_required(VERSION 3.10)
list(APPEND CMAKE_MODULE_PATH "@PACKAGE_cmakeModulesDir@")
# Check the components
set(LibsrcML_KNOWN_COMPONENTS static shared)
set(LibsrcML_COMPONENT_static NO)
set(LibsrcML_COMPONENT_shared NO)
foreach (LibsrcML_COMPONENT IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
if (LibsrcML_COMPONENT IN_LIST LibsrcML_KNOWN_COMPONENTS)
set(LibsrcML_COMPONENT_${LibsrcML_COMPONENT} YES)
else()
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE
"srcML does not recognize component `${LibsrcML_COMPONENT}`.")
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
return()
endif()
endforeach()
# Not allowed to specify both static and shared components
if(LibsrcML_COMPONENT_static AND LibsrcML_COMPONENT_shared)
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE
"srcML components `static` and `shared` are mutually exclusive.")
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
return()
endif()
set(COMPONENT "shared")
if (LibsrcML_COMPONENT_static)
set(COMPONENT "static")
endif()
set(LibsrcML_static_targets "${CMAKE_CURRENT_LIST_DIR}/srcML-static-targets.cmake")
set(LibsrcML_shared_targets "${CMAKE_CURRENT_LIST_DIR}/srcML-shared-targets.cmake")
if (NOT EXISTS "${LibsrcML_${COMPONENT}_targets}")
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE
"LibsrcML `${COMPONENT}` libraries were requested but not found.")
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)
return()
endif()
include("${LibsrcML_${COMPONENT}_targets}")
# Path depends on location of include directory for install. Custom path
# here is for Windows non-default directory install
# Default paths should work for Linux/macOS
find_path(srcML_INCLUDE_DIR
NAMES srcml.h
PATHS "${CMAKE_CURRENT_LIST_DIR}/../../../include"
DOC "libsrcml include directory"
)
# Add the include file
target_include_directories(srcML::libsrcml_${COMPONENT} PUBLIC INTERFACE ${srcML_INCLUDE_DIR})
# For the libsrcml shared library, the external shared libraries are private to it and already built
# For the libsrcml static library, the external shared libraries must be linked to the executable
if(LibsrcML_COMPONENT_static)
find_package(LibXml2 REQUIRED)
find_package(Iconv REQUIRED)
find_package(LibXslt REQUIRED)
endif()
set_target_properties(srcML::libsrcml_${COMPONENT} PROPERTIES IMPORTED_GLOBAL TRUE)
add_library(srcML::LibsrcML ALIAS srcML::libsrcml_${COMPONENT})