From 9747edd223402e4198dfb649d9b1ba6345549947 Mon Sep 17 00:00:00 2001 From: derek Date: Wed, 15 Dec 2010 15:39:54 -0500 Subject: [PATCH] Added creation of include/ folder in bamtools root directory at build time. * API-related headers are copied here to provide an explicit target for client code. --- README | 32 ++++++++++++++++++++++++------- src/CMakeLists.txt | 6 ++++++ src/ExportHeader.cmake | 31 ++++++++++++++++++++++++++++++ src/api/CMakeLists.txt | 43 +++++++++++++++++++++++++++--------------- 4 files changed, 90 insertions(+), 22 deletions(-) create mode 100644 src/ExportHeader.cmake diff --git a/README b/README index b6a8b07..3581add 100644 --- 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. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f057a61..3925d58 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 index 0000000..d0d8c1e --- /dev/null +++ b/src/ExportHeader.cmake @@ -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 ) + diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index fb2d485..d56be58 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -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}) -- 2.39.2