Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Remove OSX Homebrew ICU dependency #1851

Merged
merged 19 commits into from
Oct 26, 2015
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
71 changes: 46 additions & 25 deletions src/corefx/System.Globalization.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,49 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_definitions(-DPIC=1)
add_definitions(-DBIT64=1)

set(ICU_HOMEBREW_LIB_PATH "/usr/local/opt/icu4c/lib")
set(ICU_HOMEBREW_INC_PATH "/usr/local/opt/icu4c/include")

find_library(ICUUC NAMES icuuc PATHS ${ICU_HOMEBREW_LIB_PATH})
if(ICUUC STREQUAL ICUUC-NOTFOUND)
message(FATAL_ERROR "Cannot find libicuuc, try installing libicu-dev (or the appropriate package for your platform)")
return()
endif()

find_library(ICUI18N NAMES icui18n PATHS ${ICU_HOMEBREW_LIB_PATH})
if(ICUI18N STREQUAL ICUI18N-NOTFOUND)
message(FATAL_ERROR "Cannot find libicui18n, try installing libicu-dev (or the appropriate package for your platform)")
return()
endif()

find_path(UTYPES_H "unicode/utypes.h" PATHS ${ICU_HOMEBREW_INC_PATH})
if(UTYPES_H STREQUAL UTYPES_H-NOTFOUND)
message(FATAL_ERROR "Cannont find utypes.h, try installing libicu-dev (or the appropriate package for your platform)")
return()
endif()

set(CMAKE_REQUIRED_INCLUDES ${ICU_HOMEBREW_INC_PATH})
CHECK_CXX_SOURCE_COMPILES("
#include <unicode/dtfmtsym.h>
int main() { DateFormatSymbols::DtWidthType e = DateFormatSymbols::DtWidthType::SHORT; }
" HAVE_DTWIDTHTYPE_SHORT)
if(NOT CLR_CMAKE_PLATFORM_DARWIN)
find_library(ICUUC icuuc)
if(ICUUC STREQUAL ICUUC-NOTFOUND)
message(FATAL_ERROR "Cannot find libicuuc, try installing libicu-dev (or the appropriate package for your platform)")
return()
endif()

find_library(ICUI18N icui18n)
if(ICUI18N STREQUAL ICUI18N-NOTFOUND)
message(FATAL_ERROR "Cannot find libicui18n, try installing libicu-dev (or the appropriate package for your platform)")
return()
endif()

set(CMAKE_REQUIRED_INCLUDES ${ICU_HOMEBREW_INC_PATH})
CHECK_CXX_SOURCE_COMPILES("
#include <unicode/udat.h>
int main() { UDateFormatSymbolType e = UDAT_STANDALONE_SHORTER_WEEKDAYS; }
" HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS)

if(HAVE_DTWIDTHTYPE_SHORT)
add_definitions(-DHAVE_DTWIDTHTYPE_SHORT=1)
endif(HAVE_DTWIDTHTYPE_SHORT)
if(HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS)
add_definitions(-DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS=1)
endif(HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS)

else()

find_library(ICUCORE icucore)
if(ICUI18N STREQUAL ICUCORE-NOTFOUND)
message(FATAL_ERROR "Cannot find libicucore, skipping build for System.Globalization.Native. .NET globalization is not expected to function.")
return()
endif()

# libicucore supports UDAT_STANDALONE_SHORTER_WEEKDAYS
add_definitions(-DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS=1)

endif()

add_compile_options(-fPIC)

Expand All @@ -61,9 +74,17 @@ add_library(System.Globalization.Native
# Disable the "lib" prefix.
set_target_properties(System.Globalization.Native PROPERTIES PREFIX "")

target_link_libraries(System.Globalization.Native
${ICUUC}
${ICUI18N}
)
if(NOT CLR_CMAKE_PLATFORM_DARWIN)
target_link_libraries(System.Globalization.Native
${ICUUC}
${ICUI18N}
)
else()
target_link_libraries(System.Globalization.Native
${ICUCORE}
)

add_definitions(-DU_DISABLE_RENAMING=1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nguerrera suggested that I use #if's instead of #ifdef's in in the Globalization code. Using a cmake.configure and configure.h.in files make this really easy. See dotnet/corefx@61bcd09#diff-7bd8c3c1f0189b08e03c9050bca3dc61L18 for how I did it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will need to look into this a little bit more, I have refactored the CMakeLists.txt a bit so that on Darwin we don't probe headers for UDAT_STANDALONE_SHORTER_WEEKDAYS, not sure if that prevents me from doing this or not. I'll investigate and do a follow-up PR if needed.

endif()

install (TARGETS System.Globalization.Native DESTINATION .)
Loading