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 "6.0.0") 25set(GENERIC_LIB_SOVERSION "6") 26 27################################ 28# Add definitions 29 30set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") 31 32################################ 33# Add targets 34# By Default shared libray is being built 35# To build static libs also - Do cmake . -DBUILD_STATIC_LIBS:BOOL=ON 36# User can choose not to build shared library by using cmake -DBUILD_SHARED_LIBS:BOOL=OFF 37# To build only static libs use cmake . -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON 38# To build the tests, use cmake . -DBUILD_TESTS:BOOL=ON 39# To disable the building of the tests, use cmake . -DBUILD_TESTS:BOOL=OFF 40 41option(BUILD_SHARED_LIBS "build as shared library" ON) 42option(BUILD_STATIC_LIBS "build as static library" OFF) 43option(BUILD_TESTS "build xmltest (deprecated: Use BUILD_TESTING)" 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 51if(BUILD_SHARED_LIBS) 52add_library(tinyxml2 SHARED tinyxml2.cpp tinyxml2.h) 53 54set_target_properties(tinyxml2 PROPERTIES 55 COMPILE_DEFINITIONS "TINYXML2_EXPORT" 56 VERSION "${GENERIC_LIB_VERSION}" 57 SOVERSION "${GENERIC_LIB_SOVERSION}") 58 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_PREFIX}/include>) 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 DESTINATION ${CMAKE_INSTALL_BINDIR} 83 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 84 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 85endif() 86 87if(BUILD_STATIC_LIBS) 88add_library(tinyxml2_static STATIC tinyxml2.cpp tinyxml2.h) 89set_target_properties(tinyxml2_static PROPERTIES 90 COMPILE_DEFINITONS "TINYXML2_EXPORT" 91 VERSION "${GENERIC_LIB_VERSION}" 92 SOVERSION "${GENERIC_LIB_SOVERSION}") 93set_target_properties( tinyxml2_static PROPERTIES OUTPUT_NAME tinyxml2 ) 94 95target_compile_definitions(tinyxml2_static PUBLIC -D_CRT_SECURE_NO_WARNINGS) 96 97if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") 98 target_include_directories(tinyxml2_static PUBLIC 99 $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> 100 $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>) 101 102 if(MSVC) 103 target_compile_definitions(tinyxml2_static PUBLIC -D_CRT_SECURE_NO_WARNINGS) 104 endif(MSVC) 105else() 106 include_directories(${PROJECT_SOURCE_DIR}) 107 108 if(MSVC) 109 add_definitions(-D_CRT_SECURE_NO_WARNINGS) 110 endif(MSVC) 111endif() 112 113# export targets for find_package config mode 114export(TARGETS tinyxml2_static 115 FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake) 116 117install(TARGETS tinyxml2_static 118 EXPORT ${CMAKE_PROJECT_NAME}Targets 119 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 120 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 121 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 122endif() 123 124if(BUILD_TESTING AND BUILD_TESTS) 125 add_executable(xmltest xmltest.cpp) 126 if(BUILD_SHARED_LIBS) 127 add_dependencies(xmltest tinyxml2) 128 target_link_libraries(xmltest tinyxml2) 129 else(BUILD_STATIC_LIBS) 130 add_dependencies(xmltest tinyxml2_static) 131 target_link_libraries(xmltest tinyxml2_static) 132 endif() 133 134 # Copy test resources and create test output directory 135 add_custom_command(TARGET xmltest POST_BUILD 136 COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/resources $<TARGET_FILE_DIR:xmltest>/resources 137 COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:xmltest>/resources/out 138 COMMENT "Configuring xmltest resources directory: ${CMAKE_BINARY_DIR}/resources" 139 ) 140 141 add_test(NAME xmltest COMMAND xmltest) 142endif() 143 144install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 145 146foreach(p LIB INCLUDE) 147 set(var CMAKE_INSTALL_${p}DIR) 148 if(NOT IS_ABSOLUTE "${${var}}") 149 set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") 150 endif() 151endforeach() 152 153configure_file(tinyxml2.pc.in tinyxml2.pc @ONLY) 154install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) 155 156# uninstall target 157if(NOT TARGET uninstall) 158 configure_file( 159 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" 160 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 161 IMMEDIATE @ONLY) 162 163 add_custom_target(uninstall 164 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 165endif() 166 167file(WRITE 168 ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake 169 "include(\${CMAKE_CURRENT_LIST_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)\n") 170 171install(FILES 172 ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake 173 DESTINATION lib/cmake/${CMAKE_PROJECT_NAME}) 174 175install(EXPORT ${CMAKE_PROJECT_NAME}Targets 176 DESTINATION lib/cmake/${CMAKE_PROJECT_NAME}) 177