Skip to content

Commit

Permalink
Add CMake Option 'BUILD_STATICLIB' and 'BUILD_SHAREDLIB'
Browse files Browse the repository at this point in the history
  • Loading branch information
MorvenH committed May 2, 2018
1 parent 03af820 commit d428891
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
include/qingstor/QsSdkOption.h
3 changes: 2 additions & 1 deletion CMake/Options.cmake
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#OPTION(ENABLE_CURL_WIN_CLIENT "using curl on windows" ON)
OPTION(BUILD_STATICLIB "Set to ON to build libqingstor with static linking." OFF)
OPTION(BUILD_SHAREDLIB "Set to ON to build libqingstor with shared linking." ON)
24 changes: 22 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,36 @@ You can use the following variations to create your build directory:
`make`


To create a **release build**, do one of the following:
To create a **release build**, do the following:
* For Auto Make build systems:
```
cmake -DCMAKE_BUILD_TYPE=Release <path-to-root-of-this-source-code>
make
sudo make install
```

To create a **build with C style interface (defaul is off)**, do one of the following:
To create a **debug build with symbolic information**, do the following:
* For Auto Make build systems:
```
cmake -DCMAKE_BUILD_TYPE=Debug <path-to-root-of-this-source-code>
make
sudo make install
```

To create a **static library**, do the following:
* For Auto Make build systems:
```
cmake -DBUILD_STATICLIB=ON <path-to-root-of-this-source-code>
make
sudo make install
```

To create a **build with C style interface (defaul is off)**, do the following:
```
cmake -DBUILD_C_STYLE_INTERFACE=ON <path-to-root-of-this-source-code>
make
sudo make install
```

## Examples
We provide a sample for C and a sample for C++. The samples show how to use cmake to introduce SDK to build project:
Expand Down
10 changes: 5 additions & 5 deletions docs/sdk_c_style_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ qs_list_buckets_input_t input;
init_list_buckets_input(&input);
QsError err = qs_list_buckets(&input,&output,context_hdl);
if ( QS_ERR_NO_ERROR != err)
if ( QS_ERR_NO_ERROR == err)
{
// Print the HTTP status code.
printf("%d\n",output->response_code);
Expand Down Expand Up @@ -68,7 +68,7 @@ int limit = 200;
input->limit =&limit;

QsError err = qs_list_objects(&input,&output,context_hdl);
if ( QS_ERR_NO_ERROR != err)
if ( QS_ERR_NO_ERROR == err)
{
// Print the HTTP status code.
// Example: 200
Expand Down Expand Up @@ -119,7 +119,7 @@ qs_list_init (input.acl);
qs_list_append (&acl_item.node, input.acl);
QsError err = qs_put_bucket_acl(&input, &output, context_hdl);
if (QS_ERR_NO_ERROR != err)
if (QS_ERR_NO_ERROR == err)
{
// Print the HTTP status code.
printf("%d\n",output->response_code);
Expand Down Expand Up @@ -149,7 +149,7 @@ input.content_length = &length;
input.bufLength = &length;

QsError err = qs_put_object(objectKey, &input, &output, context_hdl);
if ( QS_ERR_NO_ERROR != err)
if ( QS_ERR_NO_ERROR == err)
{
// Print the HTTP status code.
printf("%d\n",output->response_code);
Expand Down Expand Up @@ -179,7 +179,7 @@ qs_delete_object_output_t output;
init_delete_object_input(&input);
QsError err = qs_delete_object(objectkey, &input, &output, context_hdl);
if ( QS_ERR_NO_ERROR != err)
if ( QS_ERR_NO_ERROR == err)
{
// Print the HTTP status code.
printf("%d\n",output->response_code);
Expand Down
15 changes: 7 additions & 8 deletions docs/sdk_cpp_style_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ aclList.push_back(acl);
input.SetACL(aclList);

QsError err = qsBucket.PutBucketACL(input, output);
if (QsError::QS_ERR_NO_ERROR != err)
if (QsError::QS_ERR_NO_ERROR == err)
{
// Print the HTTP status code.
printf("Got response code : %s",output.GetResponseCode());
Expand All @@ -136,7 +136,7 @@ input.SetBody(objectStream);
input.SetContentLength(streamSize);

QsError err = qsBucket.PutObject(objectKey, input, output);
if (QsError::QS_ERR_NO_ERROR != err)
if (QsError::QS_ERR_NO_ERROR == err)
{
// Print the HTTP status code.
printf("Got response code : %s",output.GetResponseCode());
Expand All @@ -159,7 +159,7 @@ DeleteObjectInput input;
DeleteObjectOutput output;
QsError err = qsBucket.DeleteObject(objectkey, input, output);
if (QsError::QS_ERR_NO_ERROR != err)
if (QsError::QS_ERR_NO_ERROR == err)
{
// Print the HTTP status code.
printf("Got response code : %s",output.GetResponseCode());
Expand Down Expand Up @@ -199,7 +199,7 @@ Upload Multipart
UploadMultipartInput inputPart1;
UploadMultipartOutput outputPart1;

std::iostream* objectStream1 = new std::fstream(filePath1));
std::iostream* objectStream1 = new std::fstream(filePath1), std::ios::binary | std::ios::in);
objectStream1->seekg(0, objectStream1->end);
size_t streamSize1 = objectStream1->tellg();
objectStream1->seekg(0, objectStream1->beg);
Expand All @@ -214,7 +214,7 @@ if (QsError::QS_ERR_NO_ERROR == err1)
printf("Got response code : %s",output.GetResponseCode());
}

if (QsError::QS_ERR_UNEXCEPTED_RESPONSE == err)
if (QsError::QS_ERR_UNEXCEPTED_RESPONSE == err1)
{
ResponseErrorInfo errorInfo = output.GetResponseErrInfo();
printf("request_id = %s , with detail message : %s\n" , errorInfo.requestID.c_str(), errorInfo.message.c_str());
Expand All @@ -227,8 +227,7 @@ if(objectStream1)
// Upload the second part
UploadMultipartInput inputPart2;
UploadMultipartOutput outputPart2;

std::iostream* objectStream2 = new std::fstream(filePath2));
std::iostream* objectStream2 = new std::fstream(filePath2), std::ios::binary | std::ios::in);
objectStream2->seekg(0, objectStream2->end);
size_t streamSize2 = objectStream2->tellg();
objectStream2->seekg(0, objectStream2->beg);
Expand All @@ -244,7 +243,7 @@ if (QsError::QS_ERR_NO_ERROR == err2)
printf("Got response code : %s",output.GetResponseCode());
}

if (QsError::QS_ERR_UNEXCEPTED_RESPONSE == err)
if (QsError::QS_ERR_UNEXCEPTED_RESPONSE == err2)
{
ResponseErrorInfo errorInfo = output.GetResponseErrInfo();
printf("request_id = %s , with detail message : %s\n" , errorInfo.requestID.c_str(), errorInfo.message.c_str());
Expand Down
12 changes: 10 additions & 2 deletions samples/samples_sdk_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SET(SRC_LIST main.c)

IF (APPLE)
INCLUDE_DIRECTORIES( /usr/local/include/ )
SET(LIBRARYS_MY /usr/local/lib/libqingstor.dylib)
SET(LIBRARYS_MY d/usr/local/lib/libqingstor.dylib)
ELSEIF(WIN32)
INCLUDE_DIRECTORIES(${VC_DIR}/include/)
INCLUDE_DIRECTORIES( ../../include/)
Expand All @@ -27,5 +27,13 @@ SET(LIBRARYS_MY /usr/local/lib/libqingstor.so)
ENDIF()

ADD_EXECUTABLE(Sample_sdk_c ${SRC_LIST})

TARGET_LINK_LIBRARIES(Sample_sdk_c ${LIBRARYS_MY})

#If build with qingstor.a, the following content needs to be added
#SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../CMake" ${CMAKE_MODULE_PATH})
#FIND_PACKAGE(OpenSSL REQUIRED)
#FIND_PACKAGE(Curl REQUIRED)

#TARGET_LINK_LIBRARIES(Sample_sdk_cpp ${CURL_LIBRARIES})
#TARGET_LINK_LIBRARIES(Sample_sdk_cpp ${OPENSSL_SSL_LIBRARIES})
#TARGET_LINK_LIBRARIES(Sample_sdk_cpp ${OPENSSL_CRYPTO_LIBRARIES})
12 changes: 10 additions & 2 deletions samples/samples_sdk_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SET(SRC_LIST main.cpp)

IF (APPLE)
INCLUDE_DIRECTORIES( /usr/local/include/ )
SET(LIBRARYS_MY /usr/local/lib/libqingstor.dylib)
SET(LIBRARYS_MY /usr/local/lib/libqingstor.dylib)
ELSEIF(WIN32)
INCLUDE_DIRECTORIES(${VC_DIR}/include/)
INCLUDE_DIRECTORIES( ../../include/)
Expand All @@ -27,5 +27,13 @@ SET(LIBRARYS_MY /usr/local/lib/libqingstor.so)
ENDIF()

ADD_EXECUTABLE(Sample_sdk_cpp ${SRC_LIST})

TARGET_LINK_LIBRARIES(Sample_sdk_cpp ${LIBRARYS_MY})

#If build with qingstor.a, the following content needs to be added
#SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../CMake" ${CMAKE_MODULE_PATH})
#FIND_PACKAGE(OpenSSL REQUIRED)
#FIND_PACKAGE(Curl REQUIRED)

#TARGET_LINK_LIBRARIES(Sample_sdk_cpp ${CURL_LIBRARIES})
#TARGET_LINK_LIBRARIES(Sample_sdk_cpp ${OPENSSL_SSL_LIBRARIES})
#TARGET_LINK_LIBRARIES(Sample_sdk_cpp ${OPENSSL_CRYPTO_LIBRARIES})
16 changes: 13 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,20 @@ IF (WIN32)
_CRT_SECURE_NO_WARNINGS
DLL_EXPORTS
)

ELSE()
#On other platform ,generate dynamic library

#On other platform
IF(BUILD_STATICLIB) #generate static library
ADD_LIBRARY(libqingstor-static STATIC ${libqingstor_SOURCES})
SET_TARGET_PROPERTIES(libqingstor-static PROPERTIES OUTPUT_NAME "qingstor")
SET_TARGET_PROPERTIES(libqingstor-static PROPERTIES
VERSION ${libqingstor_VERSION_MAJOR}.${libqingstor_VERSION_MINOR}.${libqingstor_VERSION_PATCH}
SOVERSION ${libqingstor_VERSION_API})
# install lib files.
INSTALL(TARGETS libqingstor-static
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
ENDIF()
#generate dynamic library
ADD_LIBRARY(libqingstor-shared SHARED ${libqingstor_SOURCES})
TARGET_LINK_LIBRARIES(libqingstor-shared ${CURL_LIBRARIES})
TARGET_LINK_LIBRARIES(libqingstor-shared ${OPENSSL_SSL_LIBRARIES})
Expand Down

0 comments on commit d428891

Please sign in to comment.