Skip to content

Commit

Permalink
Make BinaryDict.hpp and DartsDict.hpp usable alone (#550)
Browse files Browse the repository at this point in the history
From d18eac4ee14b871c2c9ebeb9fc9ee797e6b2109a Mon Sep 17 00:00:00 2001
From: Arfrever Frehtes Taifersar Arahesis <[email protected]>
Date: Tue, 2 Mar 2021 00:00:00 +0000
  • Loading branch information
Arfrever Frehtes Taifersar Arahesis authored and BYVoid committed Mar 4, 2021
1 parent 8015eed commit 736b93d
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 9 deletions.
1 change: 1 addition & 0 deletions node/node_opencc.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"../node/opencc.cc",
],
"include_dirs": [
"../node",
"../src",
"../deps/rapidjson-1.1.0",
"../deps/marisa-0.2.6/include",
Expand Down
21 changes: 21 additions & 0 deletions node/opencc_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Open Chinese Convert
*
* Copyright 2021 Carbo Kuo <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

/* #undef OPENCC_ENABLE_DARTS */
10 changes: 10 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
include (GenerateExportHeader)

include_directories("${PROJECT_BINARY_DIR}/src")
include_directories("${PROJECT_SOURCE_DIR}/src")

if(NOT USE_SYSTEM_MARISA)
include_directories(../deps/marisa-0.2.6/include)
endif()
Expand Down Expand Up @@ -38,6 +42,7 @@ set(
UTF8StringSlice.hpp
UTF8Util.hpp
opencc.h
"${PROJECT_BINARY_DIR}/src/opencc_config.h"
)

set(
Expand Down Expand Up @@ -78,6 +83,7 @@ set(UNITTESTS
)

if (ENABLE_DARTS)
set(OPENCC_ENABLE_DARTS 1)
if(NOT USE_SYSTEM_DARTS)
include_directories(../deps/darts-clone)
endif()
Expand All @@ -101,6 +107,10 @@ if (ENABLE_DARTS)
)
endif()

configure_file(
"${PROJECT_SOURCE_DIR}/src/opencc_config.h.in"
"${PROJECT_BINARY_DIR}/src/opencc_config.h")

add_library(libopencc ${LIBOPENCC_SOURCES} ${LIBOPENCC_HEADERS})
set_target_properties(libopencc PROPERTIES POSITION_INDEPENDENT_CODE ON)
source_group(libopencc FILES ${LIBOPENCC_SOURCES} ${LIBOPENCC_HEADERS})
Expand Down
6 changes: 2 additions & 4 deletions src/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "Export.hpp"
#include "Optional.hpp"
#include "opencc_config.h"

// Forward decalarations and alias
namespace opencc {
Expand Down Expand Up @@ -61,7 +62,7 @@ typedef std::shared_ptr<Segments> SegmentsPtr;
typedef std::shared_ptr<SerializableDict> SerializableDictPtr;
typedef std::shared_ptr<TextDict> TextDictPtr;

#ifdef ENABLE_DARTS
#ifdef OPENCC_ENABLE_DARTS
class BinaryDict;
class DartsDict;
typedef std::shared_ptr<BinaryDict> BinaryDictPtr;
Expand All @@ -79,6 +80,3 @@ const std::string PACKAGE_DATA_DIRECTORY = PKGDATADIR "/";
#ifndef VERSION
#define VERSION "1.0.*"
#endif // ifndef VERSION

// The following definitions are provided by CMake
// #define ENABLE_DARTS
2 changes: 0 additions & 2 deletions src/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include_directories(..)

add_executable(performance Performance.cpp)
target_link_libraries(performance benchmark libopencc)
add_test(BenchmarkTest performance)
Expand Down
21 changes: 21 additions & 0 deletions src/opencc_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Open Chinese Convert
*
* Copyright 2021 Carbo Kuo <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#cmakedefine OPENCC_ENABLE_DARTS
2 changes: 0 additions & 2 deletions src/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include_directories(..)

# Executables

## opencc
Expand Down
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_directories(../src)
include_directories("${PROJECT_BINARY_DIR}/src")
include_directories("${PROJECT_SOURCE_DIR}/src")

set(CONFIG_TEST
config_test/config_test.json
Expand Down

0 comments on commit 736b93d

Please sign in to comment.