diff --git a/CMakeLists.txt b/CMakeLists.txt index 7859943..1bdb7cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,40 +11,71 @@ set(PROJECT_URL "https://github.com/y-256/libdivsufsort") set(PROJECT_DESCRIPTION "A lightweight suffix sorting library") include(VERSION.cmake) -## CPack configuration ## -set(CPACK_GENERATOR "TGZ;TBZ2;ZIP") -set(CPACK_SOURCE_GENERATOR "TGZ;TBZ2;ZIP") -include(ProjectCPack) +# If libdivsudfort is being bundled in another project, we don't want +# to install anything. However, we want to let people override this, +# so we'll use the LIBDIVSUFSORT_BUNDLE_MODE variable to let them do +# that; just set it to OFF in your project before you +# add_subdirectory(libdivsufsort). +get_directory_property(LIBDIVSUFSORT_PARENT_DIRECTORY PARENT_DIRECTORY) +if("${LIBDIVSUFSORT_BUNDLE_MODE}" STREQUAL "") + # Bundled mode hasn't been set one way or the other, set the default + # depending on whether or not we are the top-level project. + if(LIBDIVSUFSORT_PARENT_DIRECTORY) + set(LIBDIVSUFSORT_BUNDLE_MODE ON) + else() + set(LIBDIVSUFSORT_BUNDLE_MODE OFF) + endif(LIBDIVSUFSORT_PARENT_DIRECTORY) +endif() +mark_as_advanced(LIBDIVSUFSORT_BUNDLE_MODE) -## Project options ## -option(BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON) -option(BUILD_EXAMPLES "Build examples" ON) -option(BUILD_DIVSUFSORT64 "Build libdivsufsort64" OFF) -option(USE_OPENMP "Use OpenMP for parallelization" OFF) -option(WITH_LFS "Enable Large File Support" ON) +if(NOT LIBDIVSUFSORT_BUNDLE_MODE) + ## CPack configuration ## + set(CPACK_GENERATOR "TGZ;TBZ2;ZIP") + set(CPACK_SOURCE_GENERATOR "TGZ;TBZ2;ZIP") + include(ProjectCPack) + + ## Project options ## + option(BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON) + option(BUILD_EXAMPLES "Build examples" ON) + option(BUILD_DIVSUFSORT64 "Build libdivsufsort64" OFF) + option(USE_OPENMP "Use OpenMP for parallelization" OFF) + option(WITH_LFS "Enable Large File Support" ON) +else() + set(BUILD_SHARED_LIBS OFF) + # These can be overridden by setting them to OFF in a higher-level + # directory. + if(BUILD_EXAMPLES STREQUAL "") + set(BUILD_EXAMPLES ON) + endif(BUILD_EXAMPLES STREQUAL "") + if(WITH_LFS STREQUAL "") + set(WITH_LFS ON) + endif(WITH_LFS STREQUAL "") +endif(NOT LIBDIVSUFSORT_BUNDLE_MODE) ## Installation directories ## -set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32 or 64)") +if(NOT LIBDIVSUFSORT_BUNDLE_MODE) + set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32 or 64)") -set(CMAKE_INSTALL_RUNTIMEDIR "" CACHE PATH "Specify the output directory for dll runtimes (default is bin)") -if(NOT CMAKE_INSTALL_RUNTIMEDIR) - set(CMAKE_INSTALL_RUNTIMEDIR "${CMAKE_INSTALL_PREFIX}/bin") -endif(NOT CMAKE_INSTALL_RUNTIMEDIR) + set(CMAKE_INSTALL_RUNTIMEDIR "" CACHE PATH "Specify the output directory for dll runtimes (default is bin)") + if(NOT CMAKE_INSTALL_RUNTIMEDIR) + set(CMAKE_INSTALL_RUNTIMEDIR "${CMAKE_INSTALL_PREFIX}/bin") + endif(NOT CMAKE_INSTALL_RUNTIMEDIR) -set(CMAKE_INSTALL_LIBDIR "" CACHE PATH "Specify the output directory for libraries (default is lib)") -if(NOT CMAKE_INSTALL_LIBDIR) - set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") -endif(NOT CMAKE_INSTALL_LIBDIR) + set(CMAKE_INSTALL_LIBDIR "" CACHE PATH "Specify the output directory for libraries (default is lib)") + if(NOT CMAKE_INSTALL_LIBDIR) + set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") + endif(NOT CMAKE_INSTALL_LIBDIR) -set(CMAKE_INSTALL_INCLUDEDIR "" CACHE PATH "Specify the output directory for header files (default is include)") -if(NOT CMAKE_INSTALL_INCLUDEDIR) - set(CMAKE_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include") -endif(NOT CMAKE_INSTALL_INCLUDEDIR) + set(CMAKE_INSTALL_INCLUDEDIR "" CACHE PATH "Specify the output directory for header files (default is include)") + if(NOT CMAKE_INSTALL_INCLUDEDIR) + set(CMAKE_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include") + endif(NOT CMAKE_INSTALL_INCLUDEDIR) -set(CMAKE_INSTALL_PKGCONFIGDIR "" CACHE PATH "Specify the output directory for pkgconfig files (default is lib/pkgconfig)") -if(NOT CMAKE_INSTALL_PKGCONFIGDIR) - set(CMAKE_INSTALL_PKGCONFIGDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig") -endif(NOT CMAKE_INSTALL_PKGCONFIGDIR) + set(CMAKE_INSTALL_PKGCONFIGDIR "" CACHE PATH "Specify the output directory for pkgconfig files (default is lib/pkgconfig)") + if(NOT CMAKE_INSTALL_PKGCONFIGDIR) + set(CMAKE_INSTALL_PKGCONFIGDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + endif(NOT CMAKE_INSTALL_PKGCONFIGDIR) +endif(NOT LIBDIVSUFSORT_BUNDLE_MODE) ## Build type ## if(NOT CMAKE_BUILD_TYPE) @@ -91,9 +122,18 @@ if(BUILD_EXAMPLES) endif(BUILD_EXAMPLES) ## Add 'uninstall' target ## -CONFIGURE_FILE( - "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/CMakeModules/cmake_uninstall.cmake" - IMMEDIATE @ONLY) -ADD_CUSTOM_TARGET(uninstall - "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/CMakeModules/cmake_uninstall.cmake") +if(NOT LIBDIVSUFSORT_BUNDLE_MODE) + CONFIGURE_FILE( + "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/CMakeModules/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + ADD_CUSTOM_TARGET(uninstall + "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/CMakeModules/cmake_uninstall.cmake") +endif(NOT LIBDIVSUFSORT_BUNDLE_MODE) + +## Add some relevant variables for the parent project +if(NOT LIBDIVSUFSORT_PARENT_DIRECTORY STREQUAL "") + set(divsufsort_LIBRARIES "divsufsort" PARENT_SCOPE) + set(divsufsort_INCLUDE_DIRS "${CMAKE_CURRENT_BINARY_DIR}/include" PARENT_SCOPE) + set(divsufsort_DEFINITIONS "" PARENT_SCOPE) +endif() diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 37781cc..da87acb 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -150,13 +150,17 @@ set(SAINDEX_TYPE "${SAINT32_TYPE}") set(SAINDEX_PRId "${SAINT32_PRId}") set(SAINT_PRId "${SAINT32_PRId}") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/divsufsort.h.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" @ONLY) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" @ONLY) +if(NOT LIBDIVSUFSORT_BUNDLE_MODE) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +endif(NOT LIBDIVSUFSORT_BUNDLE_MODE) if(BUILD_DIVSUFSORT64) set(W64BIT "64") set(SAINDEX_TYPE "${SAINT64_TYPE}") set(SAINDEX_PRId "${SAINT64_PRId}") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/divsufsort.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/divsufsort64.h" @ONLY) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/divsufsort64.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + if(NOT LIBDIVSUFSORT_BUNDLE_MODE) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/divsufsort64.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + endif(NOT LIBDIVSUFSORT_BUNDLE_MODE) endif(BUILD_DIVSUFSORT64) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index abc90e6..15ab05a 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -5,10 +5,12 @@ set(divsufsort_SRCS divsufsort.c sssort.c trsort.c utils.c) ## libdivsufsort ## add_library(divsufsort ${divsufsort_SRCS}) -install(TARGETS divsufsort - RUNTIME DESTINATION ${CMAKE_INSTALL_RUNTIMEDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +if(NOT LIBDIVSUFSORT_BUNDLE_MODE) + install(TARGETS divsufsort + RUNTIME DESTINATION ${CMAKE_INSTALL_RUNTIMEDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif(NOT LIBDIVSUFSORT_BUNDLE_MODE) set_target_properties(divsufsort PROPERTIES VERSION "${LIBRARY_VERSION}" SOVERSION "${LIBRARY_SOVERSION}" @@ -18,10 +20,12 @@ set_target_properties(divsufsort PROPERTIES ## libdivsufsort64 ## if(BUILD_DIVSUFSORT64) add_library(divsufsort64 ${divsufsort_SRCS}) - install(TARGETS divsufsort64 - RUNTIME DESTINATION ${CMAKE_INSTALL_RUNTIMEDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + if(NOT LIBDIVSUFSORT_BUNDLE_MODE) + install(TARGETS divsufsort64 + RUNTIME DESTINATION ${CMAKE_INSTALL_RUNTIMEDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif(NOT LIBDIVSUFSORT_BUNDLE_MODE) set_target_properties(divsufsort64 PROPERTIES VERSION "${LIBRARY_VERSION}" SOVERSION "${LIBRARY_SOVERSION}" diff --git a/pkgconfig/CMakeLists.txt b/pkgconfig/CMakeLists.txt index ee7063c..8e8b8c2 100644 --- a/pkgconfig/CMakeLists.txt +++ b/pkgconfig/CMakeLists.txt @@ -1,9 +1,11 @@ ## generate libdivsufsort.pc ## -set(W64BIT "") -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libdivsufsort.pc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/libdivsufsort.pc" @ONLY) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libdivsufsort.pc" DESTINATION ${CMAKE_INSTALL_PKGCONFIGDIR}) -if(BUILD_DIVSUFSORT64) - set(W64BIT "64") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libdivsufsort.pc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/libdivsufsort64.pc" @ONLY) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libdivsufsort64.pc" DESTINATION ${CMAKE_INSTALL_PKGCONFIGDIR}) -endif(BUILD_DIVSUFSORT64) +if(NOT LIBDIVSUFSORT_BUNDLE_MODE) + set(W64BIT "") + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libdivsufsort.pc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/libdivsufsort.pc" @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libdivsufsort.pc" DESTINATION ${CMAKE_INSTALL_PKGCONFIGDIR}) + if(BUILD_DIVSUFSORT64) + set(W64BIT "64") + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libdivsufsort.pc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/libdivsufsort64.pc" @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libdivsufsort64.pc" DESTINATION ${CMAKE_INSTALL_PKGCONFIGDIR}) + endif(BUILD_DIVSUFSORT64) +endif(NOT LIBDIVSUFSORT_BUNDLE_MODE)