Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for building shared/static and install headers #21

Merged
merged 11 commits into from

4 participants

@hasufell

by default the build-system will now install
libtinyxml2.a and libtinyxml2.so into "lib"
and tinyxml2.h into "include"

BUILD_STATIC_LIBS=OFF will disable libtinyxml2.a

@leethomason
Owner

I have very mixed feelings about having the cmake stuff for just this reason...why on would someone want tinyxml-2 as a library? Wouldn't it make more sense just to disable the option? The API doesn't even have binary compatibility between minor versions.

@diasbruno

yep, i was thinking the same for xcode, that it could be good to have txml2 as library, framework...but...i agree with @leethomason.

@hasufell

I'v added library-versioning.
I mean... this is totally optional and cmake prefers static libs anyway if it finds both static and shared afair. On gentoo we would not care too much about API-breakage as long as the library-versions are updated.

We want to include tinyxml2 in the tree, but would need support for shared libs.
https://bugs.gentoo.org/show_bug.cgi?id=414647

@leethomason
Owner

But the version script need to change CMakeLists.txt for this to work?

@hasufell

Not too familiar with python, but this should do it.

@hyperair

I'm packaging this for Debian and am using a similar patch downstream. I believe the situation here is pretty similar with tinyxml, which did get a shared library built for Debian in the end: http://packages.debian.org/sid/libtinyxml2.6.2

Given that at least two distros would be applying this fix downstream, it would be nice to have this fix incorporated in a centralized location -- here.

In Debian, we typically append the major ABI version number of the shared library to the package name, but in the case of TinyXml, the entire version has been appended to the package name, since, as @leethomason mentioned earlier, binary compatibility is not maintained even between minor versions.

This still does allow us to apply minor bugfixes that don't break binary compatibility to the tinyxml package between upstream releases without needing to recompile every package (~22 in Debian) that uses it, which is something that is pretty important for a binary distribution like Debian.

hyperair and others added some commits
@hyperair hyperair Use GNUInstallDirs for CMAKE_INSTALL_*DIR e9f2aba
@hyperair hyperair Add pkgconfig file a1beafa
hasufell Merge pull request #1 from hyperair/master
Add .pc file and use GNUInstallDirs for CMAKE_INSTALL_*DIR variables
7c1f52a
@hyperair hyperair Standardize style of CMakeLists.txt
1. Use lowercase commands everywhere
2. Use tabs for indentation
abcdbd9
@hyperair hyperair Fix out of source installation with tinyxml2.pc 0eb8e9d
hasufell Merge pull request #2 from hyperair/master
Cosmetic fixes to CMakeLists.txt and a fix for out-of-source-tree builds when installing the .pc file
2cc75b3
@leethomason
Owner

Got a little out of sync - looking at pull now.

@leethomason
Owner

Okay, in general this looks good: improved CMakeList, support for the python script. (I still don't endorse building tinyxml2 as a library, but I'm trying to give the people what they want. :) ) However, the current branch is crazy old, before the files were moved around and the 'resources' directory created. The branch needs a pull from master before I can merge it.

@hasufell

I hope that did it.

@leethomason leethomason merged commit 9a0eb46 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 4, 2012
  1. Add BUILD_STATIC_LIBS option, install headers

    hasufell authored
  2. rm xmltest.h from installed headers

    hasufell authored
Commits on May 9, 2012
  1. add support for soname/symlink

    hasufell authored
Commits on May 14, 2012
Commits on May 22, 2012
  1. @hyperair
  2. @hyperair

    Add pkgconfig file

    hyperair authored
  3. Merge pull request #1 from hyperair/master

    hasufell authored
    Add .pc file and use GNUInstallDirs for CMAKE_INSTALL_*DIR variables
Commits on May 23, 2012
  1. @hyperair

    Standardize style of CMakeLists.txt

    hyperair authored
    1. Use lowercase commands everywhere
    2. Use tabs for indentation
  2. @hyperair
Commits on May 24, 2012
  1. Merge pull request #2 from hyperair/master

    hasufell authored
    Cosmetic fixes to CMakeLists.txt and a fix for out-of-source-tree builds when installing the .pc file
Commits on May 26, 2012
  1. Merge git://github.com/leethomason/tinyxml2

    hasufell authored
This page is out of date. Refresh to see the latest.
Showing with 77 additions and 2 deletions.
  1. +39 −2 CMakeLists.txt
  2. +28 −0 setversion.py
  3. +10 −0 tinyxml2.pc.in
View
41 CMakeLists.txt
@@ -2,11 +2,19 @@ cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
cmake_policy(VERSION 2.6)
project(tinyxml2)
+include(GNUInstallDirs)
#enable_testing()
#CMAKE_BUILD_TOOL
################################
+# set lib version here
+
+set(GENERIC_LIB_VERSION "1.0.1")
+set(GENERIC_LIB_SOVERSION "1")
+
+
+################################
# Add common source
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/.")
@@ -37,11 +45,40 @@ endif(MSVC)
################################
# Add targets
-
-add_library(tinyxml2 STATIC tinyxml2.cpp tinyxml2.h)
+set(BUILD_STATIC_LIBS ON CACHE BOOL "Set to ON to build static libraries")
+if(BUILD_STATIC_LIBS)
+ add_library(tinyxml2static STATIC tinyxml2.cpp tinyxml2.h)
+ set_target_properties(tinyxml2static PROPERTIES OUTPUT_NAME tinyxml2)
+endif(BUILD_STATIC_LIBS)
+add_library(tinyxml2 SHARED tinyxml2.cpp tinyxml2.h)
+set_target_properties(tinyxml2 PROPERTIES
+ VERSION "${GENERIC_LIB_VERSION}"
+ SOVERSION "${GENERIC_LIB_SOVERSION}")
add_executable(test xmltest.cpp)
add_dependencies(test tinyxml2)
add_dependencies(test ${TARGET_DATA_COPY})
target_link_libraries(test tinyxml2)
+
+
+if(BUILD_STATIC_LIBS)
+ install(TARGETS tinyxml2 tinyxml2static
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+else(BUILD_STATIC_LIBS)
+ install(TARGETS tinyxml2
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+endif(BUILD_STATIC_LIBS)
+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)
+
#add_test(test ${SAMPLE_NAME} COMMAND $<TARGET_FILE:${SAMPLE_NAME}>)
View
28 setversion.py 100644 → 100755
@@ -77,3 +77,31 @@ def doxRule( line ):
fileProcess( "dox", doxRule )
+
+#### Write the CMakeLists.txt ####
+
+def cmakeRule1( line ):
+
+ matchVersion = "set(GENERIC_LIB_VERSION"
+
+ if line[0:len(matchVersion)] == matchVersion:
+ print "1)tinyxml2.h Major found"
+ return matchVersion + " \"" + `major` + "." + `minor` + "." + `build` + "\")" + "\n"
+
+ else:
+ return line;
+
+fileProcess( "CMakeLists.txt", cmakeRule1 )
+
+def cmakeRule2( line ):
+
+ matchSoversion = "set(GENERIC_LIB_SOVERSION"
+
+ if line[0:len(matchSoversion)] == matchSoversion:
+ print "1)tinyxml2.h Major found"
+ return matchSoversion + " \"" + `major` + "\")" + "\n"
+
+ else:
+ return line;
+
+fileProcess( "CMakeLists.txt", cmakeRule2 )
View
10 tinyxml2.pc.in
@@ -0,0 +1,10 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=${prefix}
+libdir=@CMAKE_INSTALL_LIBDIR@
+includedir=@CMAKE_INSTALL_INCLUDEDIR@
+
+Name: TinyXML2
+Description: simple, small, C++ XML parser
+Version: @GENERIC_LIB_VERSION@
+Libs: -L${libdir} -ltinyxml2
+Cflags: -I${includedir}
Something went wrong with that request. Please try again.