1IF(BIICODE) 2 ADD_BIICODE_TARGETS() 3 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/resources) 4 file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 5 ENDIF() 6 RETURN() 7ENDIF(BIICODE) 8cmake_minimum_required(VERSION 2.6 FATAL_ERROR) 9cmake_policy(VERSION 2.6) 10if(POLICY CMP0063) 11 cmake_policy(SET CMP0063 OLD) 12endif() 13 14project(tinyxml2) 15include(GNUInstallDirs) 16include(CTest) 17#enable_testing() 18 19#CMAKE_BUILD_TOOL 20 21################################ 22# set lib version here 23 24set(GENERIC_LIB_VERSION "8.0.0") 25set(GENERIC_LIB_SOVERSION "8") 26 27################################ 28# Add definitions 29 30################################ 31# Add targets 32# By Default shared library is being built 33# To build static libs also - Do cmake . -DBUILD_STATIC_LIBS:BOOL=ON 34# User can choose not to build shared library by using cmake -DBUILD_SHARED_LIBS:BOOL=OFF 35# To build only static libs use cmake . -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON 36# To build the tests, use cmake . -DBUILD_TESTS:BOOL=ON 37# To disable the building of the tests, use cmake . -DBUILD_TESTS:BOOL=OFF 38 39option(BUILD_SHARED_LIBS "build as shared library" ON) 40option(BUILD_TESTS "build xmltest (deprecated: Use BUILD_TESTING)" ON) 41 42# To allow using tinyxml in another shared library 43set(CMAKE_POSITION_INDEPENDENT_CODE ON) 44 45set(CMAKE_CXX_VISIBILITY_PRESET hidden) 46set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) 47 48# to distinguish between debug and release lib 49set(CMAKE_DEBUG_POSTFIX "d") 50 51add_library(tinyxml2 tinyxml2.cpp tinyxml2.h) 52 53set_target_properties(tinyxml2 PROPERTIES 54 COMPILE_DEFINITIONS "TINYXML2_EXPORT" 55 VERSION "${GENERIC_LIB_VERSION}" 56 SOVERSION "${GENERIC_LIB_SOVERSION}") 57 58target_compile_definitions(tinyxml2 PUBLIC $<$<CONFIG:Debug>:TINYXML2_DEBUG>) 59 60if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") 61 target_include_directories(tinyxml2 PUBLIC 62 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> 63 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) 64 65 if(MSVC) 66 target_compile_definitions(tinyxml2 PUBLIC -D_CRT_SECURE_NO_WARNINGS) 67 endif(MSVC) 68else() 69 include_directories(${PROJECT_SOURCE_DIR}) 70 71 if(MSVC) 72 add_definitions(-D_CRT_SECURE_NO_WARNINGS) 73 endif(MSVC) 74endif() 75 76# export targets for find_package config mode 77export(TARGETS tinyxml2 78 FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake) 79 80install(TARGETS tinyxml2 81 EXPORT ${CMAKE_PROJECT_NAME}Targets 82 RUNTIME 83 DESTINATION ${CMAKE_INSTALL_BINDIR} 84 COMPONENT tinyxml2_runtime 85 LIBRARY 86 DESTINATION ${CMAKE_INSTALL_LIBDIR} 87 COMPONENT tinyxml2_libraries 88 ARCHIVE 89 DESTINATION ${CMAKE_INSTALL_LIBDIR} 90 COMPONENT tinyxml2_libraries) 91 92if(BUILD_TESTING AND BUILD_TESTS) 93 add_executable(xmltest xmltest.cpp) 94 add_dependencies(xmltest tinyxml2) 95 target_link_libraries(xmltest tinyxml2) 96 97 # Copy test resources and create test output directory 98 add_custom_command(TARGET xmltest POST_BUILD 99 COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/resources $<TARGET_FILE_DIR:xmltest>/resources 100 COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:xmltest>/resources/out 101 COMMENT "Configuring xmltest resources directory: ${CMAKE_CURRENT_BINARY_DIR}/resources" 102 ) 103 104 add_test(NAME xmltest COMMAND xmltest WORKING_DIRECTORY $<TARGET_FILE_DIR:xmltest>) 105endif() 106 107install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT tinyxml2_headers) 108 109configure_file(tinyxml2.pc.in tinyxml2.pc @ONLY) 110install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT tinyxml2_config) 111 112# uninstall target 113if(NOT TARGET uninstall) 114 configure_file( 115 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" 116 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 117 IMMEDIATE @ONLY) 118 119 add_custom_target(uninstall 120 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 121endif() 122 123include(CMakePackageConfigHelpers) 124set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") 125configure_package_config_file( 126 "Config.cmake.in" 127 "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake" 128 INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}" 129) 130write_basic_package_version_file( 131 "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake" 132 VERSION ${GENERIC_LIB_VERSION} 133 COMPATIBILITY SameMajorVersion 134) 135install(FILES 136 ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake 137 ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake 138 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME} 139 COMPONENT tinyxml2_config) 140 141install(EXPORT ${CMAKE_PROJECT_NAME}Targets NAMESPACE tinyxml2:: 142 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME} 143 COMPONENT tinyxml2_config) 144