Created
October 29, 2020 16:39
-
-
Save qis/0b2b52c701818f91404a545a9871a504 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.19 FATAL_ERROR) | |
project(icu VERSION 68.1 LANGUAGES C CXX) | |
#set(ICU_VER "${PROJECT_VERSION_MAJOR}-${PROJECT_VERSION_MINOR}") | |
#set(ICU_URL "https://github.com/unicode-org/icu/archive/release-${ICU_VER}.tar.gz") | |
#set(ICU_SHA "5b3cfb519c20511c1c0429b093ec16960f6a6a0d7968a9065fda393f9eba48fc") | |
#download(${ICU_URL} ${ICU_SHA} src) | |
set(ICU_DIR "release-${PROJECT_VERSION_MAJOR}-${PROJECT_VERSION_MINOR}") | |
set(ICU_TAR "icu4c-${PROJECT_VERSION_MAJOR}_${PROJECT_VERSION_MINOR}-src.tgz") | |
set(ICU_URL "https://github.com/unicode-org/icu/releases/download/${ICU_DIR}/${ICU_TAR}") | |
set(ICU_SHA "a9f2e3d8b4434b8e53878b4308bd1e6ee51c9c7042e2b1a376abefb6fbb29f2d") | |
download(${ICU_URL} ${ICU_SHA} src fix-output-name.patch) | |
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "" FORCE) | |
set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "" FORCE) | |
set(CMAKE_MINSIZEREL_POSTFIX "m" CACHE STRING "" FORCE) | |
set(CMAKE_RELWITHDEBINFO_POSTFIX "i" CACHE STRING "" FORCE) | |
# Headers | |
file(GLOB headers | |
src/source/common/unicode/*.h) | |
# Compile Options | |
if(MSVC) | |
set(compile_options /wd4005 /wd4244 /wd4996 /wd5055 /wd5056) | |
else() | |
set(compile_options | |
-Wno-ambiguous-reversed-operator | |
-Wno-deprecated-anon-enum-enum-conversion | |
-Wno-deprecated-array-compare | |
-Wno-deprecated-enum-enum-conversion | |
-Wno-deprecated-enum-float-conversion | |
-Wno-rewrite-not-bool | |
-Wno-sign-compare | |
-Wno-unused-function) | |
endif() | |
# Compile Definitions | |
if(WIN32) | |
set(compile_definitions | |
_CRT_SECURE_NO_DEPRECATE | |
DEFAULT_ICU_PLUGINS="" | |
HAVE_DLOPEN=0 | |
U_ATTRIBUTE_DEPRECATED= | |
U_DEFINE_FALSE_AND_TRUE=1 | |
U_HAVE_DIRENT_H=0 | |
U_HAVE_MMAP=0 | |
U_HAVE_POPEN=0 | |
U_HAVE_STRTOD_L=0 | |
U_HAVE_TZNAME=0 | |
U_HAVE_WCSCPY=0 | |
U_RELEASE=1) | |
else() | |
set(compile_definitions | |
_REENTRANT PIC | |
U_ATTRIBUTE_DEPRECATED= | |
U_HAVE_ELF_H=1 | |
U_HAVE_STRTOD_L=1 | |
U_HAVE_XLOCALE_H=0) | |
endif() | |
# Library | |
add_library(icu INTERFACE) | |
add_library(icu::icu ALIAS icu) | |
# Library: icudt | |
file(GLOB dt_sources src/source/stubdata/*.cpp) | |
add_library(dt SHARED ${headers} ${dt_sources}) | |
set_target_properties(dt PROPERTIES OUTPUT_NAME "icudt" INSTALL_RPATH "$ORIGIN") | |
target_compile_options(dt PRIVATE ${compile_options}) | |
target_compile_definitions(dt PRIVATE ${compile_definitions}) | |
target_include_directories(dt BEFORE PUBLIC | |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/source/common>) | |
if(WIN32) | |
set(ICU_LIBRARY_NAME "Data") | |
configure_file(icu.rc.in ${CMAKE_CURRENT_BINARY_DIR}/dt.rc) | |
target_sources(dt PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/dt.rc) | |
target_link_libraries(dt PRIVATE advapi32) | |
endif() | |
add_library(icu::dt ALIAS dt) | |
target_link_libraries(icu INTERFACE icu::dt) | |
# Library: icuuc | |
file(GLOB uc_sources src/source/common/*.cpp) | |
add_library(uc SHARED ${headers} ${uc_sources}) | |
set_target_properties(uc PROPERTIES OUTPUT_NAME "icuuc" INSTALL_RPATH "$ORIGIN") | |
target_compile_options(uc PRIVATE ${compile_options}) | |
target_compile_definitions(uc PRIVATE ${compile_definitions} U_COMMON_IMPLEMENTATION) | |
target_link_libraries(uc PUBLIC icu::dt) | |
target_include_directories(uc BEFORE PUBLIC | |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/source/common>) | |
if(WIN32) | |
set(ICU_LIBRARY_NAME "Common") | |
configure_file(icu.rc.in ${CMAKE_CURRENT_BINARY_DIR}/uc.rc) | |
target_sources(uc PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/uc.rc) | |
endif() | |
add_library(icu::uc ALIAS uc) | |
target_link_libraries(icu INTERFACE icu::uc) | |
# Library: icuin | |
file(GLOB in_sources src/source/i18n/*.cpp) | |
add_library(in SHARED ${headers} ${in_sources}) | |
set_target_properties(in PROPERTIES OUTPUT_NAME "icuin" INSTALL_RPATH "$ORIGIN") | |
target_compile_options(in PRIVATE ${compile_options}) | |
target_compile_definitions(in PRIVATE ${compile_definitions} U_I18N_IMPLEMENTATION) | |
target_link_libraries(in PUBLIC icu::uc) | |
target_include_directories(in BEFORE PUBLIC | |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/source/i18n>) | |
if(WIN32) | |
set(ICU_LIBRARY_NAME "I18N") | |
configure_file(icu.rc.in ${CMAKE_CURRENT_BINARY_DIR}/in.rc) | |
target_sources(in PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/in.rc) | |
endif() | |
add_library(icu::in ALIAS in) | |
target_link_libraries(icu INTERFACE icu::in) | |
# Library: icuio | |
file(GLOB io_sources src/source/io/*.cpp) | |
add_library(io SHARED ${headers} ${io_sources}) | |
set_target_properties(io PROPERTIES OUTPUT_NAME "icuio" INSTALL_RPATH "$ORIGIN") | |
target_compile_options(io PRIVATE ${compile_options}) | |
target_compile_definitions(io PRIVATE ${compile_definitions} U_IO_IMPLEMENTATION) | |
target_link_libraries(io PUBLIC icu::uc icu::in) | |
target_include_directories(io BEFORE PUBLIC | |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/source/io>) | |
if(WIN32) | |
set(ICU_LIBRARY_NAME "I/O") | |
configure_file(icu.rc.in ${CMAKE_CURRENT_BINARY_DIR}/io.rc) | |
target_sources(io PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/io.rc) | |
endif() | |
add_library(icu::io ALIAS io) | |
target_link_libraries(icu INTERFACE icu::io) | |
# Library: icutu | |
file(GLOB tu_sources src/source/tools/toolutil/*.cpp) | |
add_library(tu SHARED ${headers} ${tu_sources}) | |
set_target_properties(tu PROPERTIES OUTPUT_NAME "icutu" INSTALL_RPATH "$ORIGIN") | |
target_compile_options(tu PRIVATE ${compile_options}) | |
target_compile_definitions(tu PRIVATE ${definitions} U_TOOLUTIL_IMPLEMENTATION) | |
target_link_libraries(tu PUBLIC icu::uc icu::in) | |
target_include_directories(tu BEFORE PUBLIC | |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/source/tools/toolutil>) | |
if(WIN32) | |
set(ICU_LIBRARY_NAME "Tools/Utilities") | |
configure_file(icu.rc.in ${CMAKE_CURRENT_BINARY_DIR}/tu.rc) | |
target_sources(tu PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/tu.rc) | |
endif() | |
add_library(icu::tu ALIAS tu) | |
target_link_libraries(icu INTERFACE icu::tu) | |
# Data | |
file(MAKE_DIRECTORY | |
${CMAKE_CURRENT_BINARY_DIR}/data | |
${CMAKE_CURRENT_BINARY_DIR}/data/out | |
${CMAKE_CURRENT_BINARY_DIR}/data/out/tmp | |
${CMAKE_CURRENT_BINARY_DIR}/data/out/build | |
${CMAKE_CURRENT_BINARY_DIR}/data/out/build/icudt${PROJECT_VERSION_MAJOR}l) | |
add_executable(icupkg src/source/tools/icupkg/icupkg.cpp) | |
target_compile_options(icupkg PRIVATE ${compile_options}) | |
target_compile_definitions(icupkg PRIVATE ${compile_definitions}) | |
target_link_libraries(icupkg PRIVATE icu::icu) | |
add_custom_command(DEPENDS icupkg COMMAND $<TARGET_FILE:icupkg> | |
-d out/build/icudt${PROJECT_VERSION_MAJOR}l --list | |
-x "*" ${CMAKE_CURRENT_SOURCE_DIR}/src/source/data/in/icudt${PROJECT_VERSION_MAJOR}l.dat | |
-o out/tmp/icudata.lst | |
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/src/source/data/in/icudt${PROJECT_VERSION_MAJOR}l.dat | |
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/data/out/tmp/icudata.lst | |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/data) | |
add_executable(pkgdata src/source/tools/pkgdata/pkgdata.cpp src/source/tools/pkgdata/pkgtypes.c) | |
target_compile_options(pkgdata PRIVATE ${compile_options}) | |
target_compile_definitions(pkgdata PRIVATE ${compile_definitions}) | |
target_include_directories(pkgdata PRIVATE source/tools/pkgdata) | |
target_link_libraries(pkgdata PRIVATE icu::icu) | |
add_custom_command(TARGET dt POST_BUILD | |
COMMAND $<TARGET_FILE:pkgdata> | |
-O icupkg.inc # ICU directory | |
-v # quiet (q) or verbose (v) | |
-c # copiright | |
-s out/build/icudt${PROJECT_VERSION_MAJOR}l # source directory | |
-d $<TARGET_FILE_DIR:dt> # destination directory | |
-r ${PROJECT_VERSION_MAJOR} # revision | |
-e icudt # entry point and export library name | |
-p icudt${PROJECT_VERSION_MAJOR}l # data name | |
-T out/tmp # temporary directory | |
-m dll # mode | |
-L icudt # import library name | |
out/tmp/icudata.lst | |
COMMAND ${CMAKE_COMMAND} -E copy out/build/icudt${PROJECT_VERSION_MAJOR}l/icudt.dll $<TARGET_FILE_DIR_DIR:dt> | |
COMMAND ${CMAKE_COMMAND} -E copy out/build/icudt${PROJECT_VERSION_MAJOR}l/icudt.lib $<TARGET_FILE_DIR_DIR:dt> | |
DEPENDS pkgdata ${CMAKE_CURRENT_BINARY_DIR}/data/out/tmp/icudata.lst | |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/data) | |
# Install | |
install(TARGETS icu dt uc in io tu EXPORT icu | |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) | |
install(DIRECTORY src/source/common/unicode | |
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | |
CONFIGURATIONS Debug) | |
install(EXPORT icu FILE icu-config.cmake NAMESPACE icu:: | |
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/icu) | |
include(CMakePackageConfigHelpers) | |
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/icu-config-version.cmake | |
VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion) | |
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/icu-config-version.cmake | |
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/icu) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment