Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ set (DIR_SHARE_LOCALE ${DIR_SHARE}/locale/)

######## Configuration

include(CMakePackageConfigHelpers)

set(targets_export_name OpenCCTargets)

configure_file(
opencc.pc.in
opencc.pc
Expand All @@ -118,6 +122,26 @@ install(
${DIR_LIBRARY}/pkgconfig
)

write_basic_package_version_file(
OpenCCConfigVersion.cmake
VERSION ${OPENCC_VERSION}
COMPATIBILITY SameMajorVersion
)

configure_package_config_file(
OpenCCConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/OpenCCConfig.cmake
INSTALL_DESTINATION lib/cmake/opencc
)

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/OpenCCConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/OpenCCConfigVersion.cmake
DESTINATION
lib/cmake/opencc
)

######## Compiler flags

add_definitions(
Expand Down
4 changes: 4 additions & 0 deletions OpenCCConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake)
check_required_components(OpenCC)
22 changes: 19 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ configure_file(
"${PROJECT_BINARY_DIR}/src/opencc_config.h")

add_library(libopencc ${LIBOPENCC_SOURCES} ${LIBOPENCC_HEADERS})
add_library(OpenCC::OpenCC ALIAS libopencc)
set_target_properties(libopencc PROPERTIES POSITION_INDEPENDENT_CODE ON)
source_group(libopencc FILES ${LIBOPENCC_SOURCES} ${LIBOPENCC_HEADERS})
target_link_libraries(libopencc marisa)
Expand All @@ -131,6 +132,8 @@ set_target_properties(
CXX
OUTPUT_NAME
opencc
EXPORT_NAME
OpenCC
VERSION
${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}
SOVERSION
Expand All @@ -139,13 +142,26 @@ set_target_properties(

# Installation

if (USE_SYSTEM_MARISA)
set(INSTALL_TARGETS libopencc)
else()
set(INSTALL_TARGETS libopencc marisa)
endif()

install(
TARGETS libopencc
LIBRARY DESTINATION ${DIR_LIBRARY}
ARCHIVE DESTINATION ${DIR_LIBRARY}
TARGETS ${INSTALL_TARGETS} EXPORT ${targets_export_name}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)

install(
EXPORT ${targets_export_name}
FILE ${targets_export_name}.cmake
DESTINATION lib/cmake/opencc
NAMESPACE OpenCC::
)

install(
FILES ${LIBOPENCC_HEADERS}
DESTINATION ${DIR_INCLUDE}/opencc
Expand Down