blob: 8802fb81c588ba9dcfeac361e9c35359234ba7b2 [file] [log] [blame]
Alex Reinking7df6b3f2021-03-10 16:47:19 -08001cmake_minimum_required(VERSION 3.15)
Lee Thomason1dee28e2021-06-06 17:10:24 -07002project(tinyxml2 VERSION 9.0.0)
Lee Thomason (grinliz)4dbe8692012-09-08 21:23:33 -07003
Chow Loong Jin53811452017-06-22 01:14:07 +08004include(CTest)
Alex Reinking7df6b3f2021-03-10 16:47:19 -08005option(tinyxml2_BUILD_TESTING "Build tests for tinyxml2" "${BUILD_TESTING}")
Lee Thomason (grinliz)4dbe8692012-09-08 21:23:33 -07006
Alex Reinking7df6b3f2021-03-10 16:47:19 -08007##
8## Honor tinyxml2_SHARED_LIBS to match install interface
9##
Lee Thomason (grinliz)4dbe8692012-09-08 21:23:33 -070010
Alex Reinking7df6b3f2021-03-10 16:47:19 -080011if (DEFINED tinyxml2_SHARED_LIBS)
12 set(BUILD_SHARED_LIBS "${tinyxml2_SHARED_LIBS}")
13endif ()
Lee Thomason (grinliz)4dbe8692012-09-08 21:23:33 -070014
Alex Reinking7df6b3f2021-03-10 16:47:19 -080015##
16## Main library build
17##
Masadow4be5bc82018-10-09 14:57:44 +020018
Matthew Woehlke8170bdc2016-08-09 13:21:06 -040019set(CMAKE_CXX_VISIBILITY_PRESET hidden)
Alex Reinking7df6b3f2021-03-10 16:47:19 -080020set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
Mark Mossberg60e96162019-12-03 22:35:33 +000021
Lukas Solankab7c169c2018-04-28 00:55:28 +010022add_library(tinyxml2 tinyxml2.cpp tinyxml2.h)
Alex Reinking7df6b3f2021-03-10 16:47:19 -080023add_library(tinyxml2::tinyxml2 ALIAS tinyxml2)
renu555871d72f2015-09-18 13:39:51 +053024
Alex Reinking7df6b3f2021-03-10 16:47:19 -080025# Uncomment the following line to require C++11 (or greater) to use tinyxml2
26# target_compile_features(tinyxml2 PUBLIC cxx_std_11)
27target_include_directories(tinyxml2 PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
Lee Thomason (grinliz)4dbe8692012-09-08 21:23:33 -070028
Alex Reinking7df6b3f2021-03-10 16:47:19 -080029target_compile_definitions(
30 tinyxml2
31 PUBLIC $<$<CONFIG:Debug>:TINYXML2_DEBUG>
32 INTERFACE $<$<BOOL:${BUILD_SHARED_LIBS}>:TINYXML2_IMPORT>
33 PRIVATE $<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>
34)
jasjuangf66441e2017-06-01 17:25:30 -070035
Alex Reinking7df6b3f2021-03-10 16:47:19 -080036set_target_properties(
37 tinyxml2
38 PROPERTIES
39 DEFINE_SYMBOL "TINYXML2_EXPORT"
40 VERSION "${tinyxml2_VERSION}"
41 SOVERSION "${tinyxml2_VERSION_MAJOR}"
42)
jasjuangf66441e2017-06-01 17:25:30 -070043
Alex Reinking7df6b3f2021-03-10 16:47:19 -080044if (tinyxml2_BUILD_TESTING)
45 add_executable(xmltest xmltest.cpp)
46 target_link_libraries(xmltest PRIVATE tinyxml2::tinyxml2)
jasjuangf66441e2017-06-01 17:25:30 -070047
Alex Reinking7df6b3f2021-03-10 16:47:19 -080048 add_test(
49 NAME xmltest
50 COMMAND xmltest
51 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
52 )
Lukasz Kurylo2818e672016-06-22 17:21:54 +020053
Alex Reinking7df6b3f2021-03-10 16:47:19 -080054 set_tests_properties(xmltest PROPERTIES PASS_REGULAR_EXPRESSION ", Fail 0")
55endif ()
jasjuangf66441e2017-06-01 17:25:30 -070056
Alex Reinking7df6b3f2021-03-10 16:47:19 -080057##
58## Installation
59##
renu555871d72f2015-09-18 13:39:51 +053060
Alex Reinking7df6b3f2021-03-10 16:47:19 -080061## Standard modules
62include(GNUInstallDirs)
Lukas Solanka392ec182018-05-04 23:02:00 +010063include(CMakePackageConfigHelpers)
jasjuangf66441e2017-06-01 17:25:30 -070064
Alex Reinking7df6b3f2021-03-10 16:47:19 -080065## Custom locations
66set(tinyxml2_INSTALL_PKGCONFIGDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
67 CACHE PATH "Directory for pkgconfig files")
68
69set(tinyxml2_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/tinyxml2"
70 CACHE STRING "Path to tinyxml2 CMake files")
71
72## CMake targets and export scripts
73
74install(
75 TARGETS tinyxml2 EXPORT tinyxml2-targets
76 RUNTIME COMPONENT tinyxml2_runtime
77 LIBRARY COMPONENT tinyxml2_runtime
78 NAMELINK_COMPONENT tinyxml2_development
79 ARCHIVE COMPONENT tinyxml2_development
80 INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
81)
82
83# Type-specific targets
84
85if (BUILD_SHARED_LIBS)
86 set(type shared)
87else ()
88 set(type static)
89endif ()
90
91install(
92 EXPORT tinyxml2-targets
93 DESTINATION "${tinyxml2_INSTALL_CMAKEDIR}"
94 NAMESPACE tinyxml2::
95 FILE tinyxml2-${type}-targets.cmake
96 COMPONENT tinyxml2_development
97)
98
99# Auto-generated version compatibility file
100write_basic_package_version_file(
101 tinyxml2-config-version.cmake
102 COMPATIBILITY SameMajorVersion
103)
104
105install(
106 FILES
107 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/tinyxml2-config.cmake"
108 "${CMAKE_CURRENT_BINARY_DIR}/tinyxml2-config-version.cmake"
109 DESTINATION "${tinyxml2_INSTALL_CMAKEDIR}"
110 COMPONENT tinyxml2_development
111)
112
113## Headers
114
115install(
116 FILES tinyxml2.h
117 TYPE INCLUDE
118 COMPONENT tinyxml2_development
119)
120
121## pkg-config
122
123configure_file(cmake/tinyxml2.pc.in tinyxml2.pc.gen @ONLY)
124file(GENERATE OUTPUT tinyxml2.pc INPUT "${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc.gen")
125install(
126 FILES "${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc"
127 DESTINATION "${tinyxml2_INSTALL_PKGCONFIGDIR}"
128 COMPONENT tinyxml2_development
129)