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 "7.0.1")
     25 set(GENERIC_LIB_SOVERSION "7")
     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 
     39 option(BUILD_SHARED_LIBS "build as shared library" ON)
     40 option(BUILD_TESTS "build xmltest (deprecated: Use BUILD_TESTING)" ON)
     41 
     42 # To allow using tinyxml in another shared library
     43 set(CMAKE_POSITION_INDEPENDENT_CODE 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 add_library(tinyxml2 tinyxml2.cpp tinyxml2.h)
     52 
     53 set_target_properties(tinyxml2 PROPERTIES
     54         COMPILE_DEFINITIONS "TINYXML2_EXPORT"
     55 	VERSION "${GENERIC_LIB_VERSION}"
     56 	SOVERSION "${GENERIC_LIB_SOVERSION}")
     57 
     58 target_compile_definitions(tinyxml2 PUBLIC $<$<CONFIG:Debug>:TINYXML2_DEBUG>)
     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_INCLUDEDIR}>)
     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 
     86 if(BUILD_TESTING AND BUILD_TESTS)
     87   add_executable(xmltest xmltest.cpp)
     88   add_dependencies(xmltest tinyxml2)
     89   target_link_libraries(xmltest tinyxml2)
     90 
     91   # Copy test resources and create test output directory
     92   add_custom_command(TARGET xmltest POST_BUILD
     93     COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/resources $<TARGET_FILE_DIR:xmltest>/resources
     94     COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:xmltest>/resources/out
     95     COMMENT "Configuring xmltest resources directory: ${CMAKE_CURRENT_BINARY_DIR}/resources"
     96   )
     97 
     98   add_test(NAME xmltest COMMAND xmltest WORKING_DIRECTORY $<TARGET_FILE_DIR:xmltest>)
     99 endif()
    100 
    101 install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
    102 
    103 configure_file(tinyxml2.pc.in tinyxml2.pc @ONLY)
    104 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
    105 
    106 # uninstall target
    107 if(NOT TARGET uninstall)
    108   configure_file(
    109       "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
    110       "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
    111       IMMEDIATE @ONLY)
    112 
    113   add_custom_target(uninstall
    114       COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
    115 endif()
    116 
    117 include(CMakePackageConfigHelpers)
    118 set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
    119 configure_package_config_file(
    120   "Config.cmake.in"
    121   "${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake"
    122   INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}"
    123 )
    124 install(FILES
    125         ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
    126         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME})
    127 
    128 install(EXPORT ${CMAKE_PROJECT_NAME}Targets NAMESPACE tinyxml2::
    129         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME})
    130