-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ability create static library #85
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,19 +13,55 @@ set(SO_MAJOR 2) | |
set(SO_MINOR 0) | ||
set(SO_PATCH 2) | ||
|
||
add_definitions ( | ||
-DUTF8PROC_EXPORTS | ||
) | ||
# configure build type | ||
|
||
set(_utf8proc_is_set_build_shared_libs TRUE) | ||
if(DEFINED BUILD_SHARED_LIBS) | ||
set(_utf8proc_is_set_build_shared_libs ${BUILD_SHARED_LIBS}) | ||
endif(DEFINED BUILD_SHARED_LIBS) | ||
|
||
set(UTF8PROC_BUILD_AS_SHARED ${_utf8proc_is_set_build_shared_libs} CACHE BOOL "If present and true, this will cause utf8proc to be built shared unless the utf8proc was explicitly added as a static library.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does "explicitly added as a static library" mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, my english is not good. Maybe you formulate a better this help phrase. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also. If you want. You can add support build as MODULE too. in this case better rewrite something like this:
|
||
|
||
# set additional defined | ||
|
||
if (NOT MSVC) | ||
if(NOT DEFINED _utf8proc_additional_defined) | ||
set(_utf8proc_additional_defined ) | ||
endif(NOT DEFINED _utf8proc_additional_defined) | ||
|
||
if(UTF8PROC_BUILD_AS_SHARED) | ||
list(APPEND _utf8proc_additional_defined | ||
"-DUTF8PROC_EXPORTS" | ||
) | ||
set(_utf8proc_build_type "SHARED") | ||
else(UTF8PROC_BUILD_AS_SHARED) | ||
list(APPEND _utf8proc_additional_defined | ||
"-DUTF8PROC_BUILD_AS_LIB" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe |
||
) | ||
set(_utf8proc_build_type "STATIC") | ||
endif(UTF8PROC_BUILD_AS_SHARED) | ||
list(REMOVE_DUPLICATES _utf8proc_additional_defined) | ||
add_definitions("${_utf8proc_additional_defined}") | ||
|
||
# other config | ||
|
||
if(NOT MSVC) | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -std=c99 -pedantic -Wall") | ||
endif () | ||
endif() | ||
|
||
add_library (utf8proc | ||
add_library (utf8proc ${_utf8proc_build_type} | ||
utf8proc.c | ||
utf8proc.h | ||
) | ||
|
||
if(MSVC) | ||
get_target_property(_utf8proc_msvc_build_prop_val utf8proc COMPILE_FLAGS) | ||
if(${_utf8proc_msvc_build_prop_val} STREQUAL "_utf8proc_msvc_build_prop_val-NOTFOUND") | ||
set_target_properties(utf8proc PROPERTIES COMPILE_FLAGS "/Wall") | ||
else(${_utf8proc_msvc_build_prop_val} STREQUAL "_utf8proc_msvc_build_prop_val-NOTFOUND") | ||
set_target_properties(utf8proc PROPERTIES COMPILE_FLAGS "${_utf8proc_msvc_build_prop_val} /Wall") | ||
endif(${_utf8proc_msvc_build_prop_val} STREQUAL "_utf8proc_msvc_build_prop_val-NOTFOUND") | ||
endif() | ||
|
||
set_target_properties (utf8proc PROPERTIES | ||
POSITION_INDEPENDENT_CODE ON | ||
VERSION "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,16 +113,24 @@ typedef bool utf8proc_bool; | |
#endif | ||
#include <limits.h> | ||
|
||
#ifdef _WIN32 | ||
# ifdef UTF8PROC_EXPORTS | ||
# define UTF8PROC_DLLEXPORT __declspec(dllexport) | ||
#ifndef UTF8PROC_BUILD_AS_LIB | ||
# ifdef _WIN32 | ||
# ifdef UTF8PROC_EXPORTS | ||
# define UTF8PROC_DLLEXPORT __declspec(dllexport) | ||
# else | ||
# define UTF8PROC_DLLEXPORT __declspec(dllimport) | ||
# endif | ||
# elif defined(__GNUC__) && __GNUC__ >= 4 | ||
# define UTF8PROC_DLLEXPORT __attribute__ ((visibility("default"))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are building a static library, it doesn't seem like the visibility attribute is relevant, since that seems to correspond to the ELF ABI for shared objects. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ifNdef UTF8PROC_BUILD_AS_LIB in this place we are building shared library. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad; in that case the comment applies to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In any case, this seems a bit superfluous, since the visibility is |
||
# else | ||
# define UTF8PROC_DLLEXPORT __declspec(dllimport) | ||
# define UTF8PROC_DLLEXPORT | ||
# endif | ||
#elif __GNUC__ >= 4 | ||
# define UTF8PROC_DLLEXPORT __attribute__ ((visibility("default"))) | ||
#else | ||
# define UTF8PROC_DLLEXPORT | ||
# if defined(__GNUC__) && __GNUC__ >= 4 | ||
# define UTF8PROC_DLLEXPORT __attribute__ ((visibility("hidden"))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
read more https://gcc.gnu.org/wiki/Visibility There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand why you would want to hide symbols that you are not exporting. We are already doing this by declaring internal functions as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, this code is for when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The whole point of these symbols is that they are the public API of this library. Making them hidden makes little sense. End users can decide whether to ask to linker to hide them or not when they build this into their libraries and applications. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When i build static library - this meen that i want use this library for internal purposes only. And it hide for external user. I think that using visibility("default") for all symbols - is legacy gcc practices. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It just means that this code is not intended to be used as a shared library (by itself). People would very well decide to use -Wl,--whole-archive and re-export those symbols. Visibility is an API concern and whether or not this library is build shared does not affect what the library's public API is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, just leave that part as-is. |
||
# else | ||
# define UTF8PROC_DLLEXPORT | ||
# endif | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a weird variable name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change to any other :)