Skip to content

Commit

Permalink
fix: improve Windows build compatibility
Browse files Browse the repository at this point in the history
- Use full source file paths with CMAKE_CURRENT_SOURCE_DIR
- Add special handling for dictionary file copying on Windows
- Ensure directory exists before copying files
  • Loading branch information
xujiajiadexiaokeai committed Feb 7, 2025
1 parent 773a131 commit ba7ff45
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,37 @@ if(SIMPLE_WITH_JIEBA)
endif()

set(SOURCE_FILES
pinyin.h
simple_highlight.h
simple_tokenizer.h
pinyin.cc
simple_highlight.cc
simple_tokenizer.cc
entry.cc
${CMAKE_CURRENT_SOURCE_DIR}/pinyin.h
${CMAKE_CURRENT_SOURCE_DIR}/simple_highlight.h
${CMAKE_CURRENT_SOURCE_DIR}/simple_tokenizer.h
${CMAKE_CURRENT_SOURCE_DIR}/pinyin.cc
${CMAKE_CURRENT_SOURCE_DIR}/simple_highlight.cc
${CMAKE_CURRENT_SOURCE_DIR}/simple_tokenizer.cc
${CMAKE_CURRENT_SOURCE_DIR}/entry.cc
)

OPTION(BUILD_STATIC "Option to build static lib" OFF)
if (IOS OR BUILD_STATIC)
# iOS only support static library.
add_library(simple STATIC ${SOURCE_FILES})
# iOS only support static library.
add_library(simple STATIC ${SOURCE_FILES})
else()
add_library(simple SHARED ${SOURCE_FILES})
add_library(simple SHARED ${SOURCE_FILES})
endif()

if(SIMPLE_WITH_JIEBA)
add_dependencies(simple cppjieba)
include_directories(${SQLITE3_HEADERS_DIR} ${source_dir}/include ${source_dir}/deps)
target_include_directories(simple INTERFACE ${SQLITE3_HEADERS_DIR} ${source_dir}/include ${source_dir}/deps)
# for tests only
add_custom_command(TARGET simple PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${source_dir}/dict/ $<TARGET_FILE_DIR:simple>/../test/dict/)
if(MSVC)
add_custom_command(TARGET simple PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/test/dict
COMMAND ${CMAKE_COMMAND} -E copy_directory ${source_dir}/dict ${CMAKE_BINARY_DIR}/test/dict)
else()
add_custom_command(TARGET simple PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${source_dir}/dict/ $<TARGET_FILE_DIR:simple>/../test/dict/)
endif()
INSTALL(DIRECTORY ${source_dir}/dict/ DESTINATION bin/dict FILES_MATCHING PATTERN "*.utf8")
else()
include_directories(${SQLITE3_HEADERS_DIR})
Expand Down

0 comments on commit ba7ff45

Please sign in to comment.