Skip to content

Commit

Permalink
cmake: add GRN_EMBED option to build Groonga for embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Feb 2, 2015
1 parent 0da7305 commit ab0f068
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 89 deletions.
22 changes: 14 additions & 8 deletions CMakeLists.txt
@@ -1,4 +1,4 @@
# Copyright(C) 2012-2014 Brazil
# Copyright(C) 2012-2015 Brazil
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -44,6 +44,10 @@ include(CheckCXXCompilerFlag)
include(FindPkgConfig)
include(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake_modules/ReadFileList.cmake)

option(GRN_EMBED
"Build as a static library to embed into an application"
OFF)

set(BIN_DIR "bin")
set(SBIN_DIR "sbin")
set(LIB_DIR "lib")
Expand Down Expand Up @@ -150,7 +154,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
check_cxxflag("-fexceptions")
check_cxxflag("-fimplicit-templates")
check_build_flag("-Wno-clobbered")
if(MRN_GROONGA_BUNDLED)
if(GRN_EMBED)
check_build_flag("-fPIC")
endif()
endif()
Expand Down Expand Up @@ -228,7 +232,7 @@ ac_check_lib(rt clock_gettime)
if(HAVE_LIBRT)
set(HAVE_CLOCK_GETTIME TRUE)
endif()
if(MRN_GROONGA_BUNDLED)
if(GRN_EMBED)
check_library_exists(stdc++ __cxa_begin_catch "${ARG2}"
STDCPP)
if(STDCPP)
Expand Down Expand Up @@ -504,10 +508,12 @@ endif()

add_subdirectory(vendor)
add_subdirectory(lib)
add_subdirectory(src)
add_subdirectory(plugins)
add_subdirectory(include)
add_subdirectory(data)
if(NOT GRN_EMBED)
add_subdirectory(src)
add_subdirectory(plugins)
add_subdirectory(include)
add_subdirectory(data)
endif()

configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)

Expand All @@ -531,7 +537,7 @@ set(GRN_EXPANDED_DEFAULT_DOCUMENT_ROOT "${GRN_DEFAULT_DOCUMENT_ROOT}")
set(EXEEXT "${CMAKE_EXECUTABLE_SUFFIX}")
configure_file(groonga.pc.in "${CMAKE_CURRENT_BINARY_DIR}/groonga.pc" @ONLY)

if(NOT MRN_GROONGA_BUNDLED)
if(NOT GRN_EMBED)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/groonga.pc"
DESTINATION "${LIB_DIR}/pkgconfig/")
Expand Down
4 changes: 1 addition & 3 deletions data/CMakeLists.txt
Expand Up @@ -15,6 +15,4 @@

add_subdirectory(html)

if(NOT MRN_GROONGA_BUNDLED)
install(FILES groonga.conf DESTINATION "${GRN_CONFIG_DIR}/")
endif()
install(FILES groonga.conf DESTINATION "${GRN_CONFIG_DIR}/")
4 changes: 1 addition & 3 deletions data/html/CMakeLists.txt
Expand Up @@ -13,6 +13,4 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

if(NOT MRN_GROONGA_BUNDLED)
install(DIRECTORY admin DESTINATION "${GRN_DATA_DIR}/html")
endif()
install(DIRECTORY admin DESTINATION "${GRN_DATA_DIR}/html")
8 changes: 3 additions & 5 deletions include/CMakeLists.txt
Expand Up @@ -13,8 +13,6 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

if(NOT MRN_GROONGA_BUNDLED)
install(FILES groonga.h DESTINATION "${GRN_INCLUDE_DIR}")
install(DIRECTORY groonga DESTINATION "${GRN_INCLUDE_DIR}"
FILES_MATCHING PATTERN "*.h")
endif()
install(FILES groonga.h DESTINATION "${GRN_INCLUDE_DIR}")
install(DIRECTORY groonga DESTINATION "${GRN_INCLUDE_DIR}"
FILES_MATCHING PATTERN "*.h")
49 changes: 19 additions & 30 deletions lib/CMakeLists.txt
Expand Up @@ -39,56 +39,45 @@ set_source_files_properties(dat.cpp ${LIBGRNDAT_SOURCES}
PROPERTIES
COMPILE_FLAGS "${GRN_CXX_COMPILE_FLAGS}")

if(MRN_GROONGA_BUNDLED)
add_library(libgroonga STATIC
${LIBGROONGA_SOURCES}
${LIBGRNDAT_SOURCES}
${LIBGRNMRB_SOURCES}
${MRUBY_LIBS})
set(GRN_ALL_SOURCES
${LIBGROONGA_SOURCES}
${LIBGRNDAT_SOURCES}
${LIBGRNMRB_SOURCES}
${MRUBY_LIBS})
if(GRN_EMBED)
add_library(libgroonga STATIC ${GRN_ALL_SOURCES})
else()
add_library(libgroonga SHARED
${LIBGROONGA_SOURCES}
${LIBGRNDAT_SOURCES}
${LIBGRNMRB_SOURCES}
${MRUBY_LIBS})
add_library(libgroonga SHARED ${GRN_ALL_SOURCES})
endif()
set_target_properties(libgroonga PROPERTIES OUTPUT_NAME "groonga")
if(NOT MRN_GROONGA_BUNDLED)
target_link_libraries(libgroonga

set(GRN_ALL_LIBRARIES
${EXECINFO_LIBS}
${RT_LIBS}
${PTHREAD_LIBS}
${Z_LIBS}
${LIBLZ4_LIBRARIES}
${DL_LIBS}
${M_LIBS}
${WS2_32_LIBS})
if(GRN_EMBED)
target_link_libraries(libgroonga
${GRN_ALL_LIBRARIES}
${STDCPP_LIBS})
else()
target_link_libraries(libgroonga
${GRN_ALL_LIBRARIES})
install(TARGETS libgroonga
ARCHIVE DESTINATION "${LIB_DIR}"
LIBRARY DESTINATION "${LIB_DIR}"
RUNTIME DESTINATION "${BIN_DIR}")
else()
target_link_libraries(libgroonga
${EXECINFO_LIBS}
${RT_LIBS}
${PTHREAD_LIBS}
${Z_LIBS}
${LIBLZ4_LIBRARIES}
${DL_LIBS}
${M_LIBS}
${STDCPP_LIBS}
${WS2_32_LIBS})
endif()

if(GRN_WITH_MRUBY)
if(GRN_WITH_MRUBY AND NOT GRN_EMBED)
read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/mrb/scripts/sources.am
RUBY_SCRIPTS)
string(REGEX REPLACE "([^;]+)" "mrb/scripts/\\1"
RUBY_SCRIPTS "${RUBY_SCRIPTS}")
if(NOT MRN_GROONGA_BUNDLED)
install(
FILES ${RUBY_SCRIPTS}
DESTINATION "${GRN_RELATIVE_RUBY_SCRIPTS_DIR}")
endif()
install(
FILES ${RUBY_SCRIPTS}
DESTINATION "${GRN_RELATIVE_RUBY_SCRIPTS_DIR}")
Expand Down
4 changes: 1 addition & 3 deletions plugins/query_expanders/CMakeLists.txt
Expand Up @@ -27,6 +27,4 @@ set_target_properties(tsv_query_expander PROPERTIES
PREFIX ""
OUTPUT_NAME "tsv")
target_link_libraries(tsv_query_expander libgroonga)
if(NOT MRN_GROONGA_BUNDLED)
install(TARGETS tsv_query_expander DESTINATION "${QUERY_EXPANDERS_DIR}")
endif()
install(TARGETS tsv_query_expander DESTINATION "${QUERY_EXPANDERS_DIR}")
8 changes: 2 additions & 6 deletions plugins/ruby/CMakeLists.txt
Expand Up @@ -27,9 +27,7 @@ if(GRN_WITH_MRUBY)
COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}")
set_target_properties(eval PROPERTIES PREFIX "")
target_link_libraries(eval libgroonga)
if(NOT MRN_GROONGA_BUNDLED)
install(TARGETS eval DESTINATION "${GRN_RELATIVE_RUBY_PLUGINS_DIR}")
endif()
install(TARGETS eval DESTINATION "${GRN_RELATIVE_RUBY_PLUGINS_DIR}")

read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/load_sources.am RUBY_LOAD_SOURCES)
add_library(load MODULE ${RUBY_LOAD_SOURCES})
Expand All @@ -38,7 +36,5 @@ if(GRN_WITH_MRUBY)
COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}")
set_target_properties(load PROPERTIES PREFIX "")
target_link_libraries(load libgroonga)
if(NOT MRN_GROONGA_BUNDLED)
install(TARGETS load DESTINATION "${GRN_RELATIVE_RUBY_PLUGINS_DIR}")
endif()
install(TARGETS load DESTINATION "${GRN_RELATIVE_RUBY_PLUGINS_DIR}")
endif()
4 changes: 1 addition & 3 deletions plugins/suggest/CMakeLists.txt
Expand Up @@ -24,6 +24,4 @@ set_source_files_properties(${SUGGEST_SOURCES}
COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}")
set_target_properties(suggest PROPERTIES PREFIX "")
target_link_libraries(suggest libgroonga)
if(NOT MRN_GROONGA_BUNDLED)
install(TARGETS suggest DESTINATION "${GRN_RELATIVE_PLUGINS_DIR}/suggest")
endif()
install(TARGETS suggest DESTINATION "${GRN_RELATIVE_PLUGINS_DIR}/suggest")
4 changes: 1 addition & 3 deletions plugins/table/CMakeLists.txt
Expand Up @@ -24,6 +24,4 @@ set_source_files_properties(${TABLE_SOURCES}
COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}")
set_target_properties(table PROPERTIES PREFIX "")
target_link_libraries(table libgroonga)
if(NOT MRN_GROONGA_BUNDLED)
install(TARGETS table DESTINATION "${GRN_RELATIVE_PLUGINS_DIR}/table")
endif()
install(TARGETS table DESTINATION "${GRN_RELATIVE_PLUGINS_DIR}/table")
8 changes: 2 additions & 6 deletions plugins/tokenizers/CMakeLists.txt
Expand Up @@ -30,9 +30,7 @@ if(GRN_WITH_MECAB)
PREFIX ""
OUTPUT_NAME "mecab")
target_link_libraries(mecab_tokenizer libgroonga ${MECAB_LIBRARIES})
if(NOT MRN_GROONGA_BUNDLED)
install(TARGETS mecab_tokenizer DESTINATION "${TOKENIZERS_DIR}")
endif()
install(TARGETS mecab_tokenizer DESTINATION "${TOKENIZERS_DIR}")
endif()

if(GRN_WITH_KYTEA)
Expand All @@ -47,7 +45,5 @@ if(GRN_WITH_KYTEA)
PREFIX ""
OUTPUT_NAME "kytea")
target_link_libraries(kytea_tokenizer libgroonga ${KYTEA_LIBRARIES})
if(NOT MRN_GROONGA_BUNDLED)
install(TARGETS kytea_tokenizer DESTINATION "${TOKENIZERS_DIR}")
endif()
install(TARGETS kytea_tokenizer DESTINATION "${TOKENIZERS_DIR}")
endif()
12 changes: 3 additions & 9 deletions src/CMakeLists.txt
Expand Up @@ -25,9 +25,7 @@ set_source_files_properties(${GROONGA_SOURCES}
PROPERTIES
COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}")
target_link_libraries(groonga libgroonga)
if(NOT MRN_GROONGA_BUNDLED)
install(TARGETS groonga DESTINATION ${BIN_DIR})
endif()
install(TARGETS groonga DESTINATION ${BIN_DIR})

if(NOT WIN32)
read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/grnslap_sources.am GRNSLAP_SOURCES)
Expand All @@ -36,9 +34,7 @@ if(NOT WIN32)
PROPERTIES
COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}")
target_link_libraries(grnslap libgroonga)
if(NOT MRN_GROONGA_BUNDLED)
install(TARGETS grnslap DESTINATION ${BIN_DIR})
endif()
install(TARGETS grnslap DESTINATION ${BIN_DIR})
endif()

read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/groonga_benchmark_sources.am
Expand All @@ -48,7 +44,5 @@ set_source_files_properties(${GROONGA_BENCHMARK_SOURCES}
PROPERTIES
COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}")
target_link_libraries(groonga-benchmark libgroonga)
if(NOT MRN_GROONGA_BUNDLED)
install(TARGETS groonga-benchmark DESTINATION ${BIN_DIR})
endif()
install(TARGETS groonga-benchmark DESTINATION ${BIN_DIR})

16 changes: 6 additions & 10 deletions src/suggest/CMakeLists.txt
Expand Up @@ -25,11 +25,9 @@ set_source_files_properties(${GROONGA_SUGGEST_CREATE_DATASET_SOURCES}
PROPERTIES
COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}")
target_link_libraries(groonga-suggest-create-dataset libgroonga)
if(NOT MRN_GROONGA_BUNDLED)
install(
TARGETS groonga-suggest-create-dataset
DESTINATION ${BIN_DIR})
endif()
install(
TARGETS groonga-suggest-create-dataset
DESTINATION ${BIN_DIR})

if(GRN_WITH_LIBEVENT AND GRN_WITH_ZEROMQ AND GRN_WITH_MESSAGE_PACK)
set(GRN_WITH_SUGGEST_LEARNER TRUE)
Expand Down Expand Up @@ -82,9 +80,7 @@ if(GRN_WITH_SUGGEST_LEARNER)
${ZEROMQ_LIBRARIES}
${MESSAGE_PACK_LIBRARIES})

if(NOT MRN_GROONGA_BUNDLED)
install(
TARGETS groonga-suggest-learner groonga-suggest-httpd
DESTINATION ${BIN_DIR})
endif()
install(
TARGETS groonga-suggest-learner groonga-suggest-httpd
DESTINATION ${BIN_DIR})
endif()

0 comments on commit ab0f068

Please sign in to comment.