Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
108 changes: 36 additions & 72 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ option(WITH_OPENSSL
"Build with OpenSSL. Setting this option to ON enables SSL-related features."
OFF)

option(BUILD_STATIC_LIB
"Build static library."
OFF)

option(BUILD_SHARED_LIB
option(BUILD_SHARED_LIBS
"Build shared library."
ON)

Expand All @@ -76,12 +72,6 @@ option(BUILD_EXAMPLES
"Build examples."
OFF)

# exit with an error message if none of BUILD_SHARED_LIB and BUILD_STATIC_LIB was set.
if ((NOT BUILD_SHARED_LIB) AND (NOT BUILD_STATIC_LIB))
message(FATAL_ERROR
"Set at least one of BUILD_SHARED_LIB and BUILD_STATIC_LIB to ON.")
endif ()

# find dependencies

# find Threads
Expand All @@ -103,66 +93,66 @@ if (WITH_OPENSSL)
endif ()


function(add_hazelcast_library name type)
function(add_hazelcast_library type)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess now that we work with a single type of library during the build, we can remove this function and put its contents in the global scope.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.

# add the library target
add_library(
${name}
${PROJECT_NAME}
${type}
${SOURCE_FILES} ${HEADER_FILES}
)

# set library's version and soversion
set_target_properties(
${name}
${PROJECT_NAME}
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION}
)

# library requires c++11
target_compile_features(
${name}
${PROJECT_NAME}
PUBLIC cxx_std_11
)

# links the library against the system's thread library
target_link_libraries(${name} PUBLIC Threads::Threads)
target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads)

# add Boost::thread and Boost::chrono as dependencies
target_link_libraries(
${name}
${PROJECT_NAME}
PUBLIC Boost::boost Boost::thread Boost::chrono
)
# set the Boost thread version
target_compile_definitions(
${name}
${PROJECT_NAME}
PUBLIC BOOST_THREAD_VERSION=5
)

# If building WITH_OPENSSL, add OpenSSL::SSL and OpenSSL::Crypto as dependencies
# Both we and the user defines HZ_BUILD_WITH_SSL.
if (WITH_OPENSSL)
target_compile_definitions(
${name}
${PROJECT_NAME}
PUBLIC HZ_BUILD_WITH_SSL
)
target_link_libraries(${name} PUBLIC OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(${PROJECT_NAME} PUBLIC OpenSSL::SSL OpenSSL::Crypto)
endif()

# MSVC-specific compiler flags
if (MSVC)
target_compile_options(${name} PRIVATE /bigobj)
target_compile_options(${PROJECT_NAME} PRIVATE /bigobj)
endif ()

# windows-specific compile flags
if (WIN32)
# speeds the build process
target_compile_definitions(${name} PRIVATE WIN32_LEAN_AND_MEAN)
target_compile_definitions(${PROJECT_NAME} PRIVATE WIN32_LEAN_AND_MEAN)
endif ()

# add include directories
target_include_directories(
${name}
${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hazelcast/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hazelcast/generated-sources/src>
Expand All @@ -172,21 +162,21 @@ function(add_hazelcast_library name type)

# add compile flags for version and git commit information
target_compile_definitions(
${name}
${PROJECT_NAME}
PRIVATE
HAZELCAST_VERSION="${PROJECT_VERSION}"
HAZELCAST_GIT_COMMIT_DATE=${GIT_COMMIT_DATE}
HAZELCAST_GIT_COMMIT_ID=${GIT_COMMIT_ID}
)

if (DISABLE_LOGGING)
target_compile_definitions(${name} PUBLIC HZ_LOGGING_DISABLED)
target_compile_definitions(${PROJECT_NAME} PUBLIC HZ_LOGGING_DISABLED)
endif ()

set_target_properties(${name} PROPERTIES DEFINE_SYMBOL HAZELCAST_EXPORTS)
set_target_properties(${PROJECT_NAME} PROPERTIES DEFINE_SYMBOL HAZELCAST_EXPORTS)

generate_export_header(
${name}
${PROJECT_NAME}
BASE_NAME hazelcast
EXPORT_MACRO_NAME HAZELCAST_API
EXPORT_FILE_NAME include/hazelcast/util/export.h
Expand All @@ -195,13 +185,13 @@ function(add_hazelcast_library name type)
)

if (type STREQUAL "STATIC")
target_compile_definitions(${name} PUBLIC HAZELCAST_USE_STATIC)
target_compile_definitions(${PROJECT_NAME} PUBLIC HAZELCAST_USE_STATIC)
endif()

# install library target
install(
TARGETS ${name}
EXPORT ${name}-targets
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand All @@ -210,15 +200,15 @@ function(add_hazelcast_library name type)

# install the -targets.cmake file
install(
EXPORT ${name}-targets
FILE ${name}-targets.cmake
NAMESPACE hazelcast::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${name}
EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}-targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

# configure -config-version.cmake file
write_basic_package_version_file(
${name}-config-version.cmake
${PROJECT_NAME}-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
Expand All @@ -228,41 +218,28 @@ function(add_hazelcast_library name type)
set(LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
configure_package_config_file(
cmake/config.cmake.in
${name}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${name}
${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
PATH_VARS INCLUDE_INSTALL_DIR LIBRARY_INSTALL_DIR
)

# install -config.cmake and -config-version.cmake files
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${name}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${name}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${name}
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
endfunction()

# the base name for shared and static libraries
set(BASE_LIBRARY_NAME hazelcastcxx)
# add the _ssl suffix to the base name if building WITH_OPENSSL
if (WITH_OPENSSL)
set(BASE_LIBRARY_NAME ${BASE_LIBRARY_NAME}_ssl)
endif()

# set the names for the shared and static libraries
set(SHARED_LIBRARY_NAME ${BASE_LIBRARY_NAME})
set(STATIC_LIBRARY_NAME ${BASE_LIBRARY_NAME}_static)

# add static library if requested
if (BUILD_STATIC_LIB)
add_hazelcast_library(${STATIC_LIBRARY_NAME} STATIC)
endif()

# add shared library if requested
if (BUILD_SHARED_LIB)
add_hazelcast_library(${SHARED_LIBRARY_NAME} SHARED)
# add library
if (BUILD_SHARED_LIBS)
set(LIB_TYPE SHARED)
else()
set(LIB_TYPE STATIC)
endif()

add_hazelcast_library(${LIB_TYPE})

# install header files, this applies both to the shared and the static library
install(
Expand All @@ -275,23 +252,10 @@ install(
FILES_MATCHING PATTERN "*.h"
)

# since shared and static libraries can be requested for the build at the same time,
# we need a default one to use for tests and examples.
# the static library is preferred to the shared library, because it is OFF by default.
if (BUILD_STATIC_LIB)
set(DEFAULT_LIBRARY_FOR_TESTS_AND_EXAMPLES ${STATIC_LIBRARY_NAME})
else ()
set(DEFAULT_LIBRARY_FOR_TESTS_AND_EXAMPLES ${SHARED_LIBRARY_NAME})
endif ()

if (BUILD_TESTS)
set(LIBRARY_FOR_TESTS ${DEFAULT_LIBRARY_FOR_TESTS_AND_EXAMPLES})

add_subdirectory(hazelcast/test)
endif ()

if (BUILD_EXAMPLES)
set(LIBRARY_FOR_EXAMPLES ${DEFAULT_LIBRARY_FOR_TESTS_AND_EXAMPLES})

add_subdirectory(examples)
endif ()
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,17 @@ You can provide additional configuration options using the `-DVARIABLE=VALUE` sy
Here are all the options that are supported:
* `WITH_OPENSSL` : Set to `ON` to build the library with SSL support.
This will require [OpenSSL](https://www.openssl.org) to be installed on your system. The default is `OFF`.
* `BUILD_STATIC_LIB` : Set to `ON` or `OFF` depending on whether you want the static library. The default is `OFF`.
* `BUILD_SHARED_LIB` : Set to `ON` or `OFF` depending on whether you want the shared library. The default is `ON`.
* `BUILD_SHARED_LIBS` : Set to `ON` or `OFF` depending on whether you want the shared(ON) or static(OFF) library. The default is `ON`.
* `DISABLE_LOGGING` : Setting this option to `ON` disables logging. The default is `OFF`.

##### 1.1.5.2.1 Example Configuration Commands
Build only the static library with SSL support:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since building both is not supported anymore, we may drop "only".

Suggested change
Build only the static library with SSL support:
Build the static library with SSL support:

```sh
cmake .. -DWITH_OPENSSL=ON -DBUILD_SHARED_LIB=OFF -DBUILD_STATIC_LIB=ON
cmake .. -DWITH_OPENSSL=ON -DBUILD_SHARED_LIBS=OFF
```
Build both the shared and static library without SSL support:
Build both the shared library without SSL support:

@yemreinci yemreinci Feb 18, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can delete this example, because it does the same with the default cmake .. (SSL is off by default).
The above example alone is explanatory enough.

You may also consider removing the section header "1.1.5.2.1" completely, and put the above example under "1.1.5.2".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deleted the line. Removed the section "1.1.5.2.1".

```sh
cmake .. -DWITH_OPENSSL=OFF -DBUILD_SHARED_LIB=ON -DBUILD_STATIC_LIB=ON
cmake .. -DWITH_OPENSSL=OFF
```

## 1.2. Starting Hazelcast IMDG Cluster
Expand Down Expand Up @@ -354,22 +353,17 @@ If you are not, then read the instructions specific to your platform:
A Hazelcast IMDG C++ client installation comes with package configuration files for CMake.
If your project is using CMake, you can easily find and link against the client library:
```cmake
find_package(hazelcastcxx)
find_package(hazelcast-cpp-client CONFIG REQUIRED)

target_link_libraries(mytarget PUBLIC hazelcast::hazelcastcxx)
```

The package name depends on the specific library type you want to use.
Options are `hazelcastcxx`, `hazelcastcxx_ssl`, `hazelcastcxx_static`, and `hazelcastcxx_ssl_static`.
target_link_libraries(mytarget PRIVATE hazelcast-cpp-client)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

namespace is missing.

Suggested change
target_link_libraries(mytarget PRIVATE hazelcast-cpp-client)
target_link_libraries(mytarget PRIVATE hazelcast-cpp-client::hazelcast-cpp-client)

```

Make sure you add the installation prefix of the client library to `CMAKE_PREFIX_PATH`
if you are using a custom installation location.

#### 1.3.2. Linux and MacOS Users
You can pass the `-lhazelcastcxx` or `-lhazelcastcxx_ssl` option to the compiler to link against
You can pass the `-lhazelcast-cpp-client` option to the compiler to link against
the client library. The name of library depends on how it was configured during build time.
Comment thread
ihsandemir marked this conversation as resolved.
Outdated
If the library was built with `-DWITH_OPENSSL=ON`, then the name is `hazelcastcxx_ssl`.
If it was built with `-DWITH_OPENSSL=OFF`, then the name is `hazelcastcxx`.

The client library depends on Boost.Thread and Boost.Chrono.
You should also link your program against these libraries using `-lboost_thread` and `-lboost_chrono`.
Expand All @@ -381,7 +375,7 @@ Here is how you can compile an example from the examples directory:
g++ -std=c++11 \
examples/path/to/example.cpp \
-DBOOST_THREAD_VERSION=5 \
-lhazelcastcxx -lboost_thread -lboost_chrono
-lhazelcast-cpp-client -lboost_thread -lboost_chrono
```

If a custom installation directory was used during installation, then you may also need to use the `-L` and `-I`
Expand All @@ -390,7 +384,7 @@ options to add the library and include paths to the compiler's search path.
g++ -std=c++11 \
examples/path/to/example.cpp \
-I /path/to/install/include -L /path/to/install/lib \
-lhazelcastcxx -lboost_thread -lboost_chrono
-lhazelcast-cpp-client -lboost_thread -lboost_chrono
```

#### 1.3.3. Windows Users
Expand All @@ -402,7 +396,7 @@ for necessary features such as futures and future continuations to be enabled.
The following is a command that can be used to compile an example from the examples directory.
```bat
cl.exe path\to\example.cpp ^
C:\path\to\hazelcast\lib\hazelcastcxx.lib ^
C:\path\to\hazelcast\lib\hazelcast-cpp-client.lib ^
C:\path\to\boost\lib\boost_thread.lib C:\path\to\boost\lib\boost_chrono.lib ^
/EHsc /DBOOST_THREAD_VERSION=5 ^
/I C:\path\to\hazelcast\include /I C:\path\to\boost\include
Expand Down Expand Up @@ -596,7 +590,7 @@ Let's manipulate a distributed map on a cluster using the client.
Save the following file as `IT.cpp` and compile it using a command similar to the following (Linux g++ compilation is used for demonstration):

```C++
g++ IT.cpp -o IT -lhazelcastcxx -lboost_thread -lboost_chrono -DBOOST_THREAD_VERSION=5
g++ IT.cpp -o IT -lhazelcast-cpp-client -lboost_thread -lboost_chrono -DBOOST_THREAD_VERSION=5
```
Then, you can run the application using the following command:

Expand Down Expand Up @@ -651,7 +645,7 @@ Now create a `Sales.cpp` file, compile and run it as shown below.
**Compile:**

```C++
g++ Sales.cpp -o Sales -lhazelcastcxx -lboost_thread -lboost_chrono -DBOOST_THREAD_VERSION=5
g++ Sales.cpp -o Sales -lhazelcast-cpp-client -lboost_thread -lboost_chrono -DBOOST_THREAD_VERSION=5
```
**Run**

Expand Down
10 changes: 5 additions & 5 deletions cmake/config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ if (@WITH_OPENSSL@)
find_dependency(OpenSSL)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/@name@-targets.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/hazelcast-cpp-client-targets.cmake)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@PROJECT_NAME@ can be used in this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed.


set_and_check(@name@_INCLUDE_DIRS @PACKAGE_INCLUDE_INSTALL_DIR@)
set_and_check(@name@_LIBRARY_DIRS @PACKAGE_LIBRARY_INSTALL_DIR@)
set(@name@_LIBRARIES hazelcast::@name@)
set_and_check(hazelcast-cpp-client_INCLUDE_DIRS @PACKAGE_INCLUDE_INSTALL_DIR@)
set_and_check(hazelcast-cpp-client_LIBRARY_DIRS @PACKAGE_LIBRARY_INSTALL_DIR@)
set(hazelcast-cpp-client_LIBRARIES hazelcast-cpp-client::hazelcast-cpp-client)

check_required_components(@name@)
check_required_components(hazelcast-cpp-client)
20 changes: 7 additions & 13 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,18 @@ project (hazelcast-cpp-client-examples
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (NOT LIBRARY_FOR_EXAMPLES)
message(FATAL_ERROR "Specify LIBRARY_FOR_EXAMPLES")
endif()

if (NOT TARGET ${LIBRARY_FOR_EXAMPLES})
message(STATUS "${LIBRARY_FOR_EXAMPLES} is not a valid target, using find_package to find it.")
find_package(${LIBRARY_FOR_EXAMPLES} REQUIRED)
# the found target will have the namespace hazelcast::
set(LIBRARY_FOR_EXAMPLES hazelcast::${LIBRARY_FOR_EXAMPLES})
if (NOT TARGET hazelcast-cpp-client)
message(STATUS "hazelcast-cpp-client is not a valid target, using find_package to find it.")
find_package(hazelcast-cpp-client REQUIRED)
link_libraries(hazelcast-cpp-client::hazelcast-cpp-client) # TODO find a better way to do this
else()
link_libraries(hazelcast-cpp-client) # TODO find a better way to do this
endif()

if (MSVC)
add_compile_options(/bigobj)
endif()

message(STATUS "Examples will be built with ${LIBRARY_FOR_EXAMPLES}")
link_libraries(${LIBRARY_FOR_EXAMPLES}) # TODO find a better way to do this

add_subdirectory(transactions)
add_subdirectory(spi)
add_subdirectory(serialization)
Expand All @@ -64,7 +58,7 @@ add_subdirectory(authentication)
add_subdirectory(cp)
add_subdirectory(soak-test)

if (${LIBRARY_FOR_EXAMPLES} MATCHES "_ssl")
if (${WITH_OPENSSL})
add_subdirectory(tls)
add_subdirectory(aws)
endif ()
Loading