Skip to content

Instantly share code, notes, and snippets.

@DiKorsch
Last active August 29, 2015 14:27
Show Gist options
  • Save DiKorsch/d35f169de26d888fcfac to your computer and use it in GitHub Desktop.
Save DiKorsch/d35f169de26d888fcfac to your computer and use it in GitHub Desktop.
CMakeLists.txt for Boost to compile some libraries with cmake (eg for Android)
set(Boost_INCLUDE_DIRS @Boost_INCLUDE_DIRS@)
set(Boost_LIBRARIES @Boost_LIBRARIES@)
link_directories(@Boost_LINK_DIRS@)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} @Boost_C_FLAGS@")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} @Boost_CXX_FLAGS@")
cmake_minimum_required(VERSION 2.8)
project(android-boost)
#find patched boost directory
set(boost_root ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH
"Boost")
if(NOT EXISTS ${boost_root})
message(FATAL_ERROR
"${boost_root} does not exist!")
endif()
# ICU support
add_definitions(-DBOOST_LOCALE_WITH_ICU)
set(ICU_PATH "/home/dima/repos/icu/source/build_android/icu_build")
include_directories(
${boost_root}
${ICU_PATH}/include
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_BZIP2" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNO_BZIP2")
file(GLOB lib_srcs ${boost_root}/libs/system/src/*.cpp)
add_library( boost_system ${lib_srcs})
#file(GLOB lib_srcs ${boost_root}/libs/filesystem/v2/src/*.cpp)
#add_library( boost_filesystem ${lib_srcs})
set(lib_dir ${boost_root}/libs/iostreams/src)
set(lib_srcs ${lib_dir}/file_descriptor.cpp ${lib_dir}/gzip.cpp ${lib_dir}/mapped_file.cpp ${lib_dir}/zlib.cpp)
add_library( boost_iostreams ${lib_srcs})
file(GLOB lib_srcs ${boost_root}/libs/program_options/src/*.cpp)
add_library( boost_program_options ${lib_srcs})
file(GLOB lib_srcs ${boost_root}/libs/regex/src/*.cpp)
add_library( boost_regex ${lib_srcs})
file(GLOB lib_srcs
${boost_root}/libs/locale/src/encoding/*.cpp
${boost_root}/libs/locale/src/encoding/*.ipp
${boost_root}/libs/locale/src/icu/*.cpp
#${boost_root}/libs/locale/src/posix/*.cpp
${boost_root}/libs/locale/src/shared/*.cpp
${boost_root}/libs/locale/src/std/*.cpp
${boost_root}/libs/locale/src/util/*.cpp )
add_library( boost_locale ${lib_srcs})
file(GLOB lib_srcs ${boost_root}/libs/signals/src/*.cpp)
add_library( boost_signals ${lib_srcs})
file(GLOB lib_srcs ${boost_root}/libs/thread/src/pthread/*.cpp)
add_library( boost_thread ${lib_srcs})
file(GLOB lib_srcs ${boost_root}/libs/date_time/src/gregorian/*.cpp ${boost_root}/libs/date_time/src/posix_time/*.cpp)
add_library( boost_date_time ${lib_srcs})
#target_link_libraries(boost_filesystem boost_system)
set(Boost_INCLUDE_DIRS ${boost_root})
set(Boost_LIBRARIES boost_system boost_program_options boost_iostreams boost_date_time)
set(Boost_LINK_DIRS ${LIBRARY_OUTPUT_PATH})
configure_file(${CMAKE_SOURCE_DIR}/BoostConfig.cmake.in
${CMAKE_BINARY_DIR}/BoostConfig.cmake @ONLY)
install(DIRECTORY ${boost_root}/boost DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(TARGETS boost_system DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
#install(TARGETS boost_filesystem DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS boost_program_options DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS boost_iostreams DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS boost_regex DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS boost_locale DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS boost_signals DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS boost_thread DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS boost_date_time DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment