2015-03-16 09:41:00 +00:00
|
|
|
IF(BIICODE)
|
|
|
|
ADD_BIICODE_TARGETS()
|
|
|
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/resources)
|
|
|
|
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
|
|
|
ENDIF()
|
|
|
|
RETURN()
|
|
|
|
ENDIF(BIICODE)
|
2012-09-09 04:23:33 +00:00
|
|
|
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
|
|
|
|
cmake_policy(VERSION 2.6)
|
2017-05-04 18:25:56 +00:00
|
|
|
if(POLICY CMP0063)
|
|
|
|
cmake_policy(SET CMP0063 OLD)
|
|
|
|
endif()
|
2012-09-09 04:23:33 +00:00
|
|
|
|
|
|
|
project(tinyxml2)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
#enable_testing()
|
|
|
|
|
|
|
|
#CMAKE_BUILD_TOOL
|
|
|
|
|
|
|
|
################################
|
|
|
|
# set lib version here
|
|
|
|
|
2016-07-18 05:57:36 +00:00
|
|
|
set(GENERIC_LIB_VERSION "4.0.1")
|
2016-07-18 05:40:43 +00:00
|
|
|
set(GENERIC_LIB_SOVERSION "4")
|
2012-09-09 04:23:33 +00:00
|
|
|
|
|
|
|
################################
|
|
|
|
# Add definitions
|
|
|
|
|
2015-05-19 06:57:59 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
|
|
|
|
2012-09-09 04:23:33 +00:00
|
|
|
################################
|
|
|
|
# Add targets
|
2015-09-18 08:09:51 +00:00
|
|
|
# By Default shared libray is being built
|
2016-02-16 08:10:57 +00:00
|
|
|
# To build static libs also - Do cmake . -DBUILD_STATIC_LIBS:BOOL=ON
|
2017-02-11 12:04:14 +00:00
|
|
|
# User can choose not to build shared library by using cmake -DBUILD_SHARED_LIBS:BOOL=OFF
|
2016-02-16 08:10:57 +00:00
|
|
|
# To build only static libs use cmake . -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON
|
2017-02-21 19:27:38 +00:00
|
|
|
# To build the tests, use cmake . -DBUILD_TESTS:BOOL=ON
|
|
|
|
# To disable the building of the tests, use cmake . -DBUILD_TESTS:BOOL=OFF
|
2015-09-18 08:09:51 +00:00
|
|
|
|
|
|
|
option(BUILD_SHARED_LIBS "build as shared library" ON)
|
|
|
|
option(BUILD_STATIC_LIBS "build as static library" OFF)
|
2017-02-21 19:27:38 +00:00
|
|
|
option(BUILD_TESTS "build xmltest" ON)
|
2015-09-18 08:09:51 +00:00
|
|
|
|
2016-08-09 17:21:06 +00:00
|
|
|
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
|
|
|
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
|
|
|
|
|
2017-05-04 18:25:56 +00:00
|
|
|
# to distinguish between debug and release lib
|
|
|
|
set(CMAKE_DEBUG_POSTFIX "d")
|
|
|
|
|
2015-09-18 08:09:51 +00:00
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
add_library(tinyxml2 SHARED tinyxml2.cpp tinyxml2.h)
|
|
|
|
|
2012-09-09 04:23:33 +00:00
|
|
|
set_target_properties(tinyxml2 PROPERTIES
|
2013-12-12 12:07:34 +00:00
|
|
|
COMPILE_DEFINITIONS "TINYXML2_EXPORT"
|
2012-09-09 04:23:33 +00:00
|
|
|
VERSION "${GENERIC_LIB_VERSION}"
|
|
|
|
SOVERSION "${GENERIC_LIB_SOVERSION}")
|
|
|
|
|
2017-06-02 00:25:30 +00:00
|
|
|
|
2016-06-22 15:21:54 +00:00
|
|
|
if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
|
2017-06-02 00:25:30 +00:00
|
|
|
target_include_directories(tinyxml2 PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
|
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
|
|
|
|
|
|
|
|
if(MSVC)
|
|
|
|
target_compile_definitions(tinyxml2 PUBLIC -D_CRT_SECURE_NO_WARNINGS)
|
|
|
|
endif(MSVC)
|
|
|
|
else()
|
|
|
|
include_directories(${PROJECT_SOURCE_DIR})
|
|
|
|
|
|
|
|
if(MSVC)
|
|
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
|
|
|
endif(MSVC)
|
2016-06-22 15:21:54 +00:00
|
|
|
endif()
|
|
|
|
|
2017-06-02 00:25:30 +00:00
|
|
|
# export targets for find_package config mode
|
|
|
|
export(TARGETS tinyxml2
|
|
|
|
FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)
|
|
|
|
|
2015-09-18 08:09:51 +00:00
|
|
|
install(TARGETS tinyxml2
|
2017-06-02 00:25:30 +00:00
|
|
|
EXPORT ${CMAKE_PROJECT_NAME}Targets
|
2015-09-18 08:09:51 +00:00
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
endif()
|
2012-09-09 04:23:33 +00:00
|
|
|
|
2015-09-18 08:09:51 +00:00
|
|
|
if(BUILD_STATIC_LIBS)
|
|
|
|
add_library(tinyxml2_static STATIC tinyxml2.cpp tinyxml2.h)
|
|
|
|
set_target_properties(tinyxml2_static PROPERTIES
|
|
|
|
COMPILE_DEFINITONS "TINYXML2_EXPORT"
|
|
|
|
VERSION "${GENERIC_LIB_VERSION}"
|
|
|
|
SOVERSION "${GENERIC_LIB_SOVERSION}")
|
|
|
|
set_target_properties( tinyxml2_static PROPERTIES OUTPUT_NAME tinyxml2 )
|
2012-09-09 04:23:33 +00:00
|
|
|
|
2017-06-02 00:25:30 +00:00
|
|
|
target_compile_definitions(tinyxml2 PUBLIC -D_CRT_SECURE_NO_WARNINGS)
|
|
|
|
|
2016-06-22 15:21:54 +00:00
|
|
|
if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
|
2017-06-02 00:25:30 +00:00
|
|
|
target_include_directories(tinyxml2_static PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
|
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
|
|
|
|
|
|
|
|
if(MSVC)
|
|
|
|
target_compile_definitions(tinyxml2 PUBLIC -D_CRT_SECURE_NO_WARNINGS)
|
|
|
|
endif(MSVC)
|
|
|
|
else()
|
|
|
|
include_directories(${PROJECT_SOURCE_DIR})
|
|
|
|
|
|
|
|
if(MSVC)
|
|
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
|
|
|
endif(MSVC)
|
2016-06-22 15:21:54 +00:00
|
|
|
endif()
|
|
|
|
|
2017-06-02 00:25:30 +00:00
|
|
|
# export targets for find_package config mode
|
|
|
|
export(TARGETS tinyxml2_static
|
|
|
|
FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)
|
|
|
|
|
2015-09-18 08:09:51 +00:00
|
|
|
install(TARGETS tinyxml2_static
|
2017-06-02 00:25:30 +00:00
|
|
|
EXPORT ${CMAKE_PROJECT_NAME}Targets
|
2014-11-14 18:40:58 +00:00
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
2015-09-18 08:09:51 +00:00
|
|
|
endif()
|
|
|
|
|
2017-02-21 19:27:38 +00:00
|
|
|
if(BUILD_TESTS)
|
|
|
|
add_executable(xmltest xmltest.cpp)
|
|
|
|
if(BUILD_SHARED_LIBS)
|
2017-05-11 23:19:30 +00:00
|
|
|
add_dependencies(xmltest tinyxml2)
|
|
|
|
target_link_libraries(xmltest tinyxml2)
|
2017-02-21 19:27:38 +00:00
|
|
|
else(BUILD_STATIC_LIBS)
|
2017-05-11 23:19:30 +00:00
|
|
|
add_dependencies(xmltest tinyxml2_static)
|
|
|
|
target_link_libraries(xmltest tinyxml2_static)
|
2017-02-21 19:27:38 +00:00
|
|
|
endif()
|
|
|
|
|
2017-05-11 23:19:30 +00:00
|
|
|
# Copy test resources and create test output directory
|
|
|
|
add_custom_command(TARGET xmltest POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/resources $<TARGET_FILE_DIR:xmltest>/resources
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:xmltest>/resources/out
|
|
|
|
COMMENT "Configuring xmltest resources directory: ${CMAKE_BINARY_DIR}/resources"
|
|
|
|
)
|
2015-09-18 08:09:51 +00:00
|
|
|
endif()
|
2014-11-14 18:40:58 +00:00
|
|
|
|
2012-09-09 04:23:33 +00:00
|
|
|
install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
|
|
|
|
foreach(p LIB INCLUDE)
|
|
|
|
set(var CMAKE_INSTALL_${p}DIR)
|
|
|
|
if(NOT IS_ABSOLUTE "${${var}}")
|
|
|
|
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
configure_file(tinyxml2.pc.in tinyxml2.pc @ONLY)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
|
|
|
|
2015-08-15 23:50:55 +00:00
|
|
|
# uninstall target
|
|
|
|
configure_file(
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
|
|
|
|
IMMEDIATE @ONLY)
|
|
|
|
|
|
|
|
add_custom_target(uninstall
|
|
|
|
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
|
2017-06-02 00:25:30 +00:00
|
|
|
|
|
|
|
file(WRITE
|
|
|
|
${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
|
|
|
|
"include(\${CMAKE_CURRENT_LIST_DIR}/${CMAKE_PROJECT_NAME}Targets.cmake)\n")
|
|
|
|
|
|
|
|
install(FILES
|
|
|
|
${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
|
|
|
|
DESTINATION lib/cmake/${CMAKE_PROJECT_NAME})
|
|
|
|
|
|
|
|
install(EXPORT ${CMAKE_PROJECT_NAME}Targets
|
|
|
|
DESTINATION lib/cmake/${CMAKE_PROJECT_NAME})
|