Skip to content

Commit

Permalink
refactor(cmake): cmake code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
kionz authored and lotem committed Mar 30, 2017
1 parent 7f41f65 commit 33101c0
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 116 deletions.
102 changes: 54 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cxx_fla
project(rime)
cmake_minimum_required(VERSION 2.8)

set(LIBRIME_VERSION 1.2.9)
set(LIBRIME_SOVERSION 1)
set(rime_version 1.2.9)
set(rime_soversion 1)

add_definitions(-DRIME_VERSION="${LIBRIME_VERSION}")
add_definitions(-DRIME_VERSION="${rime_version}")

option(BUILD_SHARED_LIBS "Build Rime as shared library" ON)
option(BUILD_STATIC "Build with dependencies as static libraries" OFF)
Expand All @@ -18,10 +18,10 @@ option(ENABLE_LOGGING "Enable logging with google-glog library" ON)
option(BOOST_USE_CXX11 "Boost has been built with C++11 support" OFF)
option(BOOST_USE_SIGNALS2 "Boost use signals2 instead of signals" ON)

SET(RIME_DATA_DIR "/share/rime-data" CACHE STRING "Target directory for Rime data")
SET(rime_data_dir "/share/rime-data" CACHE STRING "Target directory for Rime data")

if(WIN32)
set(EXT ".exe")
set(ext ".exe")
endif(WIN32)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
Expand All @@ -38,91 +38,94 @@ set(YamlCpp_STATIC ${BUILD_STATIC})
set(Boost_USE_MULTITHREADED ON)
if(MSVC)
set(Boost_USE_STATIC_RUNTIME ON)
endif(MSVC)
endif()
find_package(Boost 1.46.0 REQUIRED COMPONENTS filesystem regex signals system locale)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
endif(Boost_FOUND)
endif()

if(ENABLE_LOGGING)

find_package(Gflags)
if(Gflags_FOUND)
include_directories(${Gflags_INCLUDE_PATH})
endif(Gflags_FOUND)
find_package(Gflags)
if(Gflags_FOUND)
include_directories(${Gflags_INCLUDE_PATH})
endif()

find_package(Glog REQUIRED)
if(Glog_FOUND)
include_directories(${Glog_INCLUDE_PATH})
endif(Glog_FOUND)
if(Glog_STATIC)
add_definitions(-DGOOGLE_GLOG_DLL_DECL=)
endif(Glog_STATIC)
find_package(Glog REQUIRED)
if(Glog_FOUND)
include_directories(${Glog_INCLUDE_PATH})
endif()
if(Glog_STATIC)
add_definitions(-DGOOGLE_GLOG_DLL_DECL=)
endif()

add_definitions(-DRIME_ENABLE_LOGGING)
add_definitions(-DRIME_ENABLE_LOGGING)

endif(ENABLE_LOGGING)
endif()

find_package(Threads)

find_package(Iconv)
if (ICONV_FOUND)
include_directories(${ICONV_INCLUDE_DIRS})
endif(ICONV_FOUND)
endif()

if(BUILD_TEST)
find_package(GTest REQUIRED)
if(GTEST_FOUND)
enable_testing()
include_directories(${GTEST_INCLUDE_DIRS})
endif(GTEST_FOUND)
endif(BUILD_TEST)
if(GTEST_FOUND)
enable_testing()
include_directories(${GTEST_INCLUDE_DIRS})
endif()
endif()

find_package(YamlCpp REQUIRED)
if(YamlCpp_FOUND)
include_directories(${YamlCpp_INCLUDE_PATH})
endif(YamlCpp_FOUND)
endif()

find_package(LevelDb REQUIRED)
if(LevelDb_FOUND)
include_directories(${LevelDb_INCLUDE_PATH})
endif(LevelDb_FOUND)
endif()

find_package(Marisa REQUIRED)
if(Marisa_FOUND)
include_directories(${Marisa_INCLUDE_PATH})
endif(Marisa_FOUND)
endif()

find_package(Opencc REQUIRED)
if(Opencc_FOUND)
include_directories(${Opencc_INCLUDE_PATH})
endif(Opencc_FOUND)
endif()
if(Opencc_STATIC)
add_definitions(-DOpencc_BUILT_AS_STATIC)
endif(Opencc_STATIC)
endif()

find_path(X11Keysym X11/keysym.h)
if(X11Keysym)
message(STATUS "Found X11/keysym.h at ${X11Keysym}")
include_directories(${X11Keysym})
else(X11Keysym)
else()
message(WARNING "X11/keysym.h not found.")
endif(X11Keysym)
endif()

include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/thirdparty/include)
link_directories(${PROJECT_SOURCE_DIR}/thirdparty/lib)

if(MSVC)
if(MSVC10)
# stdint.h is missing from VS2010
include_directories(${PROJECT_SOURCE_DIR}/thirdparty/include/msvc)
endif(MSVC10)
endif()
add_definitions("/wd4244 /wd4996")
endif(MSVC)
endif()

if(UNIX)
add_definitions("-std=c++11")
endif(UNIX)
endif()

if(NOT BOOST_USE_CXX11)
add_definitions("-DBOOST_NO_CXX11_SCOPED_ENUMS")
endif()
Expand All @@ -147,11 +150,12 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)

set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
set(bindir "${exec_prefix}/bin")
set(libdir "${LIB_INSTALL_DIR}")
set(pkgdatadir "${prefix}${RIME_DATA_DIR}")
set(pkgdatadir "${prefix}${rime_data_dir}")
set(includedir "${CMAKE_INSTALL_PREFIX}/include")
configure_file(
${PROJECT_SOURCE_DIR}/rime.pc.in
Expand All @@ -160,27 +164,29 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(FILES src/rime_api.h DESTINATION include)
install(FILES ${PROJECT_BINARY_DIR}/rime.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
install(FILES cmake/RimeConfig.cmake DESTINATION share/cmake/rime)

if(BUILD_DATA)
file(GLOB preset_data_files ${PROJECT_SOURCE_DIR}/data/preset/*.yaml)
install(FILES ${preset_data_files} DESTINATION ${pkgdatadir})
endif(BUILD_DATA)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
endif()
endif()

if(BUILD_SHARED_LIBS)
add_definitions(-DRIME_BUILD_SHARED_LIBS)
set(RIME_LIBRARY rime)
set(rime_library rime)
if(BUILD_SEPARATE_LIBS)
set(RIME_GEARS_LIBRARY rime-gears)
endif(BUILD_SEPARATE_LIBS)
else(BUILD_SHARED_LIBS)
set(RIME_LIBRARY rime-static)
set(rime_gears_library rime-gears)
endif()
else()
set(rime_library rime-static)
if(BUILD_SEPARATE_LIBS)
set(RIME_GEARS_LIBRARY rime-gears-static)
endif(BUILD_SEPARATE_LIBS)
endif(BUILD_SHARED_LIBS)
set(rime_gears_library rime-gears-static)
endif()
endif()

add_subdirectory(src)
add_subdirectory(tools)

if(GTEST_FOUND)
add_subdirectory(test)
endif(GTEST_FOUND)
endif()
2 changes: 1 addition & 1 deletion rime.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ includedir=@includedir@

Name: Rime
Description: Rime Input Method Engine
Version: @LIBRIME_VERSION@
Version: @rime_version@
Cflags: -I${includedir}
Libs: -L${libdir} -lrime
101 changes: 62 additions & 39 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,63 +1,86 @@
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

aux_source_directory(. LIBRIME_SRC_API)
aux_source_directory(rime LIBRIME_SRC_BASE)
aux_source_directory(rime/algo LIBRIME_SRC_ALGO)
aux_source_directory(rime/dict LIBRIME_SRC_DICT)
aux_source_directory(rime/gear LIBRIME_SRC_GEAR)
aux_source_directory(rime/lever LIBRIME_SRC_LEVER)
aux_source_directory(. rime_src_api)
aux_source_directory(rime rime_src_base)
aux_source_directory(rime/algo rime_src_algo)
aux_source_directory(rime/dict rime_src_dict)
aux_source_directory(rime/gear rime_src_gear)
aux_source_directory(rime/lever rime_src_lever)

if(BUILD_SEPARATE_LIBS)
set(LIBRIME_SRC ${LIBRIME_SRC_API} ${LIBRIME_SRC_BASE})
set(LIBRIME_GEARS_SRC ${LIBRIME_SRC_ALGO} ${LIBRIME_SRC_DICT} ${LIBRIME_SRC_GEAR} ${LIBRIME_SRC_LEVER})
else(BUILD_SEPARATE_LIBS)
set(LIBRIME_SRC ${LIBRIME_SRC_API} ${LIBRIME_SRC_BASE} ${LIBRIME_SRC_ALGO} ${LIBRIME_SRC_DICT} ${LIBRIME_SRC_GEAR} ${LIBRIME_SRC_LEVER})
endif(BUILD_SEPARATE_LIBS)
set(rime_src
${rime_src_api}
${rime_src_base}
${rime_src_config})
set(librime_gears_src
${rime_src_algo}
${rime_src_dict}
${rime_src_gear}
${rime_src_lever})
else()
set(rime_src
${rime_src_api}
${rime_src_base}
${rime_src_algo}
${rime_src_config}
${rime_src_dict}
${rime_src_gear}
${rime_src_lever})
endif()

set(RIME_OPTIONAL_DEPS "")
set(rime_optional_deps "")
if(Gflags_FOUND)
set(RIME_OPTIONAL_DEPS ${RIME_OPTIONAL_DEPS} ${Gflags_LIBRARY})
endif(Gflags_FOUND)
set(rime_optional_deps ${rime_optional_deps} ${Gflags_LIBRARY})
endif()

set(RIME_CORE_DEPS ${Boost_LIBRARIES} ${Glog_LIBRARY} ${YamlCpp_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${RIME_OPTIONAL_DEPS})
set(RIME_EXTRA_DEPS ${ICONV_LIBRARIES} ${LevelDb_LIBRARY} ${Marisa_LIBRARY} ${Opencc_LIBRARY})
set(rime_core_deps
${Boost_LIBRARIES}
${Glog_LIBRARY}
${YamlCpp_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${rime_optional_deps})
set(rime_extra_deps
${ICONV_LIBRARIES}
${LevelDb_LIBRARY}
${Marisa_LIBRARY}
${Opencc_LIBRARY})

if(BUILD_SEPARATE_LIBS)
set(RIME_DEPS ${RIME_CORE_DEPS})
set(RIME_GEARS_DEPS ${RIME_LIBRARY} ${RIME_EXTRA_DEPS})
else(BUILD_SEPARATE_LIBS)
set(RIME_DEPS ${RIME_CORE_DEPS} ${RIME_EXTRA_DEPS})
endif(BUILD_SEPARATE_LIBS)
set(rime_deps ${rime_core_deps})
set(rime_gears_deps ${rime_library} ${rime_extra_deps})
else()
set(rime_deps ${rime_core_deps} ${rime_extra_deps})
endif()

if(BUILD_SHARED_LIBS)
add_library(rime ${LIBRIME_SRC})
target_link_libraries(rime ${RIME_DEPS})
add_library(rime ${rime_src})
target_link_libraries(rime ${rime_deps})
set_target_properties(rime PROPERTIES DEFINE_SYMBOL "RIME_EXPORTS")
set_target_properties(rime PROPERTIES VERSION ${LIBRIME_VERSION} SOVERSION ${LIBRIME_SOVERSION})
set_target_properties(rime PROPERTIES VERSION ${rime_version} SOVERSION ${rime_soversion})
if(XCODE_VERSION)
set_target_properties(rime PROPERTIES INSTALL_NAME_DIR "@rpath")
endif(XCODE_VERSION)
endif()
install(TARGETS rime DESTINATION ${LIB_INSTALL_DIR})
if(BUILD_SEPARATE_LIBS)
add_library(rime-gears ${LIBRIME_GEARS_SRC})
target_link_libraries(rime-gears ${RIME_GEARS_DEPS})
add_dependencies(rime-gears ${RIME_LIBRARY})
set_target_properties(rime-gears PROPERTIES VERSION ${LIBRIME_VERSION} SOVERSION ${LIBRIME_SOVERSION})
add_library(rime-gears ${librime_gears_src})
target_link_libraries(rime-gears ${rime_gears_deps})
add_dependencies(rime-gears ${rime_library})
set_target_properties(rime-gears PROPERTIES VERSION ${rime_version} SOVERSION ${rime_soversion})
if(XCODE_VERSION)
set_target_properties(rime-gears PROPERTIES INSTALL_NAME_DIR "@rpath")
endif(XCODE_VERSION)
endif()
install(TARGETS rime-gears DESTINATION ${LIB_INSTALL_DIR})
endif(BUILD_SEPARATE_LIBS)
else(BUILD_SHARED_LIBS)
add_library(rime-static STATIC ${LIBRIME_SRC})
target_link_libraries(rime-static ${RIME_DEPS})
endif()
else()
add_library(rime-static STATIC ${rime_src})
target_link_libraries(rime-static ${rime_deps})
set_target_properties(rime-static PROPERTIES OUTPUT_NAME "rime" PREFIX "lib")
install(TARGETS rime-static DESTINATION ${LIB_INSTALL_DIR})
if(BUILD_SEPARATE_LIBS)
add_library(rime-gears-static STATIC ${LIBRIME_GEARS_SRC})
target_link_libraries(rime-gears-static ${RIME_GEARS_DEPS})
add_dependencies(rime-gears-static ${RIME_LIBRARY})
add_library(rime-gears-static STATIC ${librime_gears_src})
target_link_libraries(rime-gears-static ${rime_gears_deps})
add_dependencies(rime-gears-static ${rime_library})
set_target_properties(rime-gears-static PROPERTIES OUTPUT_NAME "rime-gears" PREFIX "lib")
install(TARGETS rime-gears-static DESTINATION ${LIB_INSTALL_DIR})
endif(BUILD_SEPARATE_LIBS)
endif(BUILD_SHARED_LIBS)
endif()
endif()
14 changes: 7 additions & 7 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
if(NOT (MSVC AND BUILD_SHARED_LIBS))

aux_source_directory(. RIME_TEST_SRC)
aux_source_directory(. rime_test_src)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test)
add_executable(rime_test ${RIME_TEST_SRC})
add_executable(rime_test ${rime_test_src})
target_link_libraries(rime_test
${RIME_LIBRARY} ${RIME_GEARS_LIBRARY}
${rime_library} ${rime_gears_library}
${GTEST_LIBRARIES})
add_dependencies(rime_test ${RIME_LIBRARY} ${RIME_GEARS_LIBRARY})
add_dependencies(rime_test ${rime_library} ${rime_gears_library})

file(COPY ${PROJECT_SOURCE_DIR}/data/test/config_test.yaml
DESTINATION ${EXECUTABLE_OUTPUT_PATH})
file(COPY ${PROJECT_SOURCE_DIR}/data/test/dictionary_test.dict.yaml
DESTINATION ${EXECUTABLE_OUTPUT_PATH})

set(RIME_TEST_EXECUTABLE ${EXECUTABLE_OUTPUT_PATH}/rime_test${EXT})
add_test(rime_test ${RIME_TEST_EXECUTABLE})
set(rime_test_executable ${EXECUTABLE_OUTPUT_PATH}/rime_test${ext})
add_test(rime_test ${rime_test_executable})

endif(NOT (MSVC AND BUILD_SHARED_LIBS))
endif()
Loading

0 comments on commit 33101c0

Please sign in to comment.