-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
118 lines (99 loc) · 4.3 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
cmake_minimum_required(VERSION 3.5)
project(test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
add_definitions(-w)
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
set(TARGET_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME})
set(YAMLCPP_BUILD_DIR ${THIRD_PARTY_DIR}/yaml-cpp/build)
set(GLOG_BUILD_DIR ${THIRD_PARTY_DIR}/glog/build)
set(MECAB_BUILD_DIR ${THIRD_PARTY_DIR}/mecab/build)
file(MAKE_DIRECTORY ${TARGET_DIR}/dic)
#------------------build submodule------------------#
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
#--------------------build glog---------------------#
if(EXISTS ${TARGET_DIR}/libglog.dll)
message(STATUS "libglog.dll found,skip...")
else()
file(MAKE_DIRECTORY ${GLOG_BUILD_DIR})
execute_process(
COMMAND cmake -DCMAKE_INSTALL_PREFIX=${GLOG_BUILD_DIR} -DWITH_GFLAGS=off -DWITH_GTEST=off -DWITH_SYMBOLIZE=off -DWITH_THREADS=off -DWITH_CUSTOM_PREFIX=on -G "MinGW Makefiles" ..
WORKING_DIRECTORY ${GLOG_BUILD_DIR})
execute_process(
COMMAND mingw32-make install --no-print-directory -j8
WORKING_DIRECTORY ${GLOG_BUILD_DIR})
file(COPY ${GLOG_BUILD_DIR}/bin/libglog.dll DESTINATION ${TARGET_DIR})
endif()
set(GLOG_INCLUDE ${GLOG_BUILD_DIR}/include)
file(GLOB GLOG_LIB ${TARGET_DIR}/libglog.dll)
#------------------build yaml-cpp-------------------#
if(EXISTS ${TARGET_DIR}/libyaml-cpp.dll)
message(STATUS "libyaml-cpp.dll found,skip...")
else()
file(MAKE_DIRECTORY ${YAMLCPP_BUILD_DIR})
execute_process(
COMMAND cmake -DCMAKE_INSTALL_PREFIX=${YAMLCPP_BUILD_DIR} -DYAML_BUILD_SHARED_LIBS=on -G "MinGW Makefiles" ..
WORKING_DIRECTORY ${YAMLCPP_BUILD_DIR})
execute_process(
COMMAND mingw32-make install --no-print-directory -j8
WORKING_DIRECTORY ${YAMLCPP_BUILD_DIR})
file(COPY ${YAMLCPP_BUILD_DIR}/bin/libyaml-cpp.dll DESTINATION ${TARGET_DIR})
endif()
file(GLOB YAMLCPP_LIB ${TARGET_DIR}/libyaml-cpp.dll)
set(YAMLCPP_INCLUDE ${THIRD_PARTY_DIR}/yaml-cpp/include)
#----------------build GoInterface-----------------#
if(EXISTS ${TARGET_DIR}/libGoInterface.dll)
message(STATUS "libGoInterface.dll found,skip...")
else()
file(COPY ${THIRD_PARTY_DIR}/TransInterface/libGoInterface.dll DESTINATION ${TARGET_DIR})
endif()
set(GOINTERFACE_INCLUDE ${THIRD_PARTY_DIR}/TransInterface)
file(GLOB GOINTERFACE_LIB ${TARGET_DIR}/libGoInterface.dll)
#--------------------build mecab--------------------#
if(EXISTS ${TARGET_DIR}/libmecab.dll)
message(STATUS "libmecab.dll found,skip...")
else()
file(MAKE_DIRECTORY ${MECAB_BUILD_DIR})
execute_process(
COMMAND cmake -DCMAKE_INSTALL_PREFIX=${MECAB_BUILD_DIR} -G "MinGW Makefiles" ..
WORKING_DIRECTORY ${MECAB_BUILD_DIR})
execute_process(
COMMAND mingw32-make install --no-print-directory -j8
WORKING_DIRECTORY ${MECAB_BUILD_DIR})
file(GLOB DICT_FILES ${THIRD_PARTY_DIR}/mecab/mecab-ipadic/**)
file(COPY ${DICT_FILES} DESTINATION ${TARGET_DIR}/dic)
file(COPY ${MECAB_BUILD_DIR}/bin/libmecab.dll DESTINATION ${TARGET_DIR})
endif()
file(GLOB MECAB_LIB ${TARGET_DIR}/libmecab.dll)
set(MECAB_INCLUDE ${MECAB_BUILD_DIR}/include/mecab)
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
else()
message(ERROR "Unknown Platform...")
endif()
# file(GLOB YAMLCPP_LIB ${TARGET_DIR}/libyaml-cpp.dll)
# set(YAMLCPP_INCLUDE ${THIRD_PARTY_DIR}/yaml-cpp/include)
#------------------build submodule------------------#
include_directories(
${SOURCE_DIR}
${GOINTERFACE_INCLUDE}
${GLOG_INCLUDE}
${YAMLCPP_INCLUDE}
${MECAB_INCLUDE}
)
file(GLOB GAL_SRC
${SOURCE_DIR}/translate/machine_translator.cpp
${SOURCE_DIR}/translate/tencent_trans.cpp
${SOURCE_DIR}/processor/text_processor.cpp
${SOURCE_DIR}/processor/text_analyzer.cpp
${SOURCE_DIR}/gal_translator.cpp)
add_executable(${PROJECT_NAME}
${SOURCE_DIR}/gal.cpp
${GAL_SRC})
target_link_libraries(${PROJECT_NAME}
${GAL_LIB}
${GLOG_LIB}
${GOINTERFACE_LIB}
${YAMLCPP_LIB}
${MECAB_LIB})
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${TARGET_DIR})