Home | History | Annotate | Download | only in tinyxml2
      1 IF(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()
      7 ENDIF(BIICODE)
      8 cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
      9 cmake_policy(VERSION 2.6)
     10 if(POLICY CMP0063)
     11 	cmake_policy(SET CMP0063 OLD)
     12 endif()
     13 
     14 project(tinyxml2)
     15 include(GNUInstallDirs)
     16 include(CTest)
     17 #enable_testing()
     18 
     19 #CMAKE_BUILD_TOOL
     20 
     21 ################################
     22 # set lib version here
     23 
     24 set(GENERIC_LIB_VERSION "6.0.0")
     25 set(GENERIC_LIB_SOVERSION "6")
     26 
     27 ################################
     28 # Add definitions
     29 
     30 set(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 
     41 option(BUILD_SHARED_LIBS "build as shared library" ON)
     42 option(BUILD_STATIC_LIBS "build as static library" OFF)
     43 option(BUILD_TESTS "build xmltest (deprecated: Use BUILD_TESTING)" ON)
     44 
     45 set(CMAKE_CXX_VISIBILITY_PRESET hidden)
     46 set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
     47 
     48 # to distinguish between debug and release lib
     49 set(CMAKE_DEBUG_POSTFIX "d")
     50 
     51 if(BUILD_SHARED_LIBS)
     52 add_library(tinyxml2 SHARED tinyxml2.cpp tinyxml2.h)
     53 
     54 set_target_properties(tinyxml2 PROPERTIES
     55         COMPILE_DEFINITIONS "TINYXML2_EXPORT"
     56 	VERSION "${GENERIC_LIB_VERSION}"
     57 	SOVERSION "${GENERIC_LIB_SOVERSION}")
     58 
     59 
     60 if(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)
     68 else()
     69     include_directories(${PROJECT_SOURCE_DIR})
     70 
     71     if(MSVC)
     72       add_definitions(-D_CRT_SECURE_NO_WARNINGS)
     73     endif(MSVC)
     74 endif()
     75 
     76 # export targets for find_package config mode
     77 export(TARGETS tinyxml2
     78       FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)
     79 
     80 install(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})
     85 endif()
     86 
     87 if(BUILD_STATIC_LIBS)
     88 add_library(tinyxml2_static STATIC tinyxml2.cpp tinyxml2.h)
     89 set_target_properties(tinyxml2_static PROPERTIES
     90         COMPILE_DEFINITONS "TINYXML2_EXPORT"
     91         VERSION "${GENERIC_LIB_VERSION}"
     92         SOVERSION "${GENERIC_LIB_SOVERSION}")
     93 set_target_properties( tinyxml2_static PROPERTIES OUTPUT_NAME tinyxml2 )
     94 
     95 target_compile_definitions(tinyxml2_static PUBLIC -D_CRT_SECURE_NO_WARNINGS)
     96 
     97 if(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)
    105 else()
    106     include_directories(${PROJECT_SOURCE_DIR})
    107 
    108     if(MSVC)
    109       add_definitions(-D_CRT_SECURE_NO_WARNINGS)
    110     endif(MSVC)
    111 endif()
    112 
    113 # export targets for find_package config mode
    114 export(TARGETS tinyxml2_static
    115       FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)
    116 
    117 install(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})
    122 endif()
    123 
    124 if(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)
    142 endif()
    143 
    144 install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
    145 
    146 foreach(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()
    151 endforeach()
    152 
    153 configure_file(tinyxml2.pc.in tinyxml2.pc @ONLY)
    154 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
    155 
    156 # uninstall target
    157 if(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)
    165 endif()
    166 
    167 file(WRITE
    168     ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
    169     "include(\${CMAKE_CURRENT_LIST_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)\n")
    170 
    171 install(FILES
    172         ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
    173         DESTINATION lib/cmake/${CMAKE_PROJECT_NAME})
    174 
    175 install(EXPORT ${CMAKE_PROJECT_NAME}Targets
    176         DESTINATION lib/cmake/${CMAKE_PROJECT_NAME})
    177