]> git.donarmstrong.com Git - bamtools.git/commitdiff
Added creation of include/ folder in bamtools root directory at build time.
authorderek <derekwbarnett@gmail.com>
Wed, 15 Dec 2010 20:39:54 +0000 (15:39 -0500)
committerderek <derekwbarnett@gmail.com>
Wed, 15 Dec 2010 20:39:54 +0000 (15:39 -0500)
 * API-related headers are copied here to provide an explicit target for client code.

README
src/CMakeLists.txt
src/ExportHeader.cmake [new file with mode: 0644]
src/api/CMakeLists.txt

diff --git a/README b/README
index b6a8b0721163e88abe3831d7b0b22a4967df03d9..3581add98f3cdd32902d33265fae50345d38cf30 100644 (file)
--- a/README
+++ b/README
@@ -144,6 +144,10 @@ The BamTools-associated libraries will be found here:
 
   ./lib/
 
+The BamTools API headers will be found here:
+  ./include/*
+
 --------------------------------------------------------------------------------
 III. Usage :
 --------------------------------------------------------------------------------
@@ -183,21 +187,35 @@ following:
         // close the reader
         reader.Close();
 
-To use this API in your application, you simply need to do 3 things:
+To use this API in your application, you simply need to do the following:
 
     1 - Build the BamTools library (see Installation steps above). 
 
-    2 - Import BamTools API with the following lines of code
-        #include "BamReader.h"     // (or "BamMultiReader.h") as needed
-        #include "BamWriter.h"     // as needed
-        using namespace BamTools;  // all of BamTools classes/methods live in
+    2 - Import BamTools API functionality as needed, for example:
+
+        #include "api/BamReader.h"     
+        #include "api/BamWriter.h"     
+        using namespace BamTools;  // all BamTools classes/methods live within
                                    // this namespace
 
-    3 - Link with '-lbamtools' ('l' as in Lima).
+    3 - In your own build step, point your include path to the 
+        (BAMTOOLS_ROOT)/include directory. Link your app with '-lbamtools' ('l'
+        as in Lima).
 
-You may need to modify the -L flag (library path) as well to help your linker 
+You may need to modify the -L flag (library path) as well to help your linker 
 find the (BAMTOOLS_ROOT)/lib directory.
 
+* Depending on your platform and where you install the BamTools API library, you 
+may also need to adjust how your app locates the library at runtime. For
+Windows users, this can be as simple as dropping the DLL in the same folder as
+your executable.  For *nix users (using gcc at least), you can add the following
+to your app's CXXFLAGS:
+
+  -Wl,-rpath,$(BAMTOOLS_LIB_DIR)
+
+where BAMTOOLS_LIB_DIR is, as you would guess, the directory containing the libs.
+An alternative is to set your local LD_LIBRARY_PATH environment variable.
+
 See any included programs for more detailed usage examples. See comments in the 
 header files for more detailed API documentation.
 
index f057a61707f07d96814b42fa717712ece36d9294..3925d5826a1679f574ed2c23f805f5eddb7397c5 100644 (file)
@@ -10,3 +10,9 @@ add_subdirectory (utils)
 add_subdirectory (third_party)
 add_subdirectory (toolkit)
 
+# export shared headers
+include(ExportHeader.cmake)
+set(SharedIncludeDir "shared")
+ExportHeader(SharedHeaders shared/bamtools_global.h ${SharedIncludeDir})
+
+
diff --git a/src/ExportHeader.cmake b/src/ExportHeader.cmake
new file mode 100644 (file)
index 0000000..d0d8c1e
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# ExportHeader
+#
+
+function( ExportHeader MODULE FILE DEST )
+
+    # if haven't defined our custom 'build target'
+    # not exactly a build target, but lets this command get
+    # checked any time build step happens
+    if (NOT TARGET ${MODULE})
+        add_custom_target( ${MODULE} ALL COMMENT "Exporting ${MODULE}" )
+    endif (NOT TARGET ${MODULE} )
+
+    # get the filename (without path)
+    get_filename_component( FILENAME "${FILE}" NAME )
+
+    # copy header to destination
+    add_custom_command( TARGET ${MODULE} COMMAND
+        ${CMAKE_COMMAND} -E copy_if_different
+        "${CMAKE_CURRENT_SOURCE_DIR}/${FILE}"
+        "${CMAKE_SOURCE_DIR}/include/${DEST}/${FILENAME}" )
+
+
+
+    # make sure files are properly 'installed'
+   # set(INSTALL_DEST "bamtools/${DEST}")
+   # install( FILES "${FILE}" DESTINATION "${INSTALL_DEST}")
+    install( FILES "${FILE}" DESTINATION "include/bamtools/${DEST}" )
+
+endfunction( ExportHeader )
+
index fb2d48506fde36a6fb53a10e0091722383f4ae4d..d56be583e01311cd7a8432936f675c94555ac496 100644 (file)
@@ -6,27 +6,27 @@
 # ==========================
 
 # list include paths
-include_directories ( ${BamTools_SOURCE_DIR}/src )
+include_directories( ${BamTools_SOURCE_DIR}/src )
 
 # add compiler definitions 
-add_definitions(-DBAMTOOLS_API_LIBRARY) # (for proper exporting of library symbols)
+add_definitions( -DBAMTOOLS_API_LIBRARY ) # (for proper exporting of library symbols)
 
 # create main BamTools API library
-add_library ( BamTools SHARED 
-              BamAlignment.cpp 
-              BamIndex.cpp 
-              BamMultiReader.cpp
-              BamReader.cpp
-              BamWriter.cpp
-              BGZF.cpp
-             internal/BamReader_p.cpp
-             internal/BamStandardIndex_p.cpp
-             internal/BamToolsIndex_p.cpp
-             internal/BamWriter_p.cpp
-            )
+add_library( BamTools SHARED
+             BamAlignment.cpp
+             BamIndex.cpp
+             BamMultiReader.cpp
+             BamReader.cpp
+             BamWriter.cpp
+             BGZF.cpp
+             internal/BamReader_p.cpp
+             internal/BamStandardIndex_p.cpp
+             internal/BamToolsIndex_p.cpp
+             internal/BamWriter_p.cpp
+           )
 
 # link BamTools library with zlib automatically
-target_link_libraries ( BamTools z )
+target_link_libraries( BamTools z )
 
 # set BamTools library properties
 set_target_properties( BamTools PROPERTIES
@@ -34,3 +34,16 @@ set_target_properties( BamTools PROPERTIES
                        OUTPUT_NAME bamtools
                      )
 
+install( TARGETS BamTools LIBRARY DESTINATION "lib/bamtools")
+
+# export API headers
+include(../ExportHeader.cmake)
+set(ApiIncludeDir "api")
+ExportHeader(APIHeaders api_global.h     ${ApiIncludeDir})
+ExportHeader(APIHeaders BamAlignment.h   ${ApiIncludeDir})
+ExportHeader(APIHeaders BamAux.h         ${ApiIncludeDir})
+ExportHeader(APIHeaders BamIndex.h       ${ApiIncludeDir})
+ExportHeader(APIHeaders BamMultiReader.h ${ApiIncludeDir})
+ExportHeader(APIHeaders BamReader.h      ${ApiIncludeDir})
+ExportHeader(APIHeaders BamWriter.h      ${ApiIncludeDir})
+ExportHeader(APIHeaders BGZF.h           ${ApiIncludeDir})