Skip to content
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

Rework of CMakeLists and Better Detection of LibSodium #4

Merged
merged 2 commits into from
Aug 25, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 37 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,55 @@ if(CYGWIN)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
endif()

if(SODIUMPP_MACPORTS)
include_directories("/opt/local/include")
link_directories("/opt/local/lib")
if(APPLE)
set(CMAKE_INSTALL_NAME_DIR @rpath)
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sodiumpp/include)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(Sodium REQUIRED)

include_directories(SYSTEM
${SODIUM_INCLUDE_DIR}
)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/sodiumpp/include
)

set(cxx-sources
sodiumpp/sodiumpp.cpp
sodiumpp/z85/z85.c
sodiumpp/z85/z85_impl.cpp
sodiumpp/locked_string.cpp
)

file(GLOB cxx-headers
"${CMAKE_CURRENT_SOURCE_DIR}/sodiumpp/include/*.h"
)

set(MODULE_NAME sodiumpp)


if(SODIUMPP_STATIC)
add_library(sodiumpp STATIC sodiumpp/sodiumpp.cpp sodiumpp/z85/z85.c sodiumpp/z85/z85_impl.cpp sodiumpp/locked_string.cpp)
find_library(SODIUMLIB libsodium.a)
add_library(${MODULE_NAME} STATIC ${cxx-sources} ${cxx-headers})
else()
add_library(sodiumpp SHARED sodiumpp/sodiumpp.cpp sodiumpp/z85/z85.c sodiumpp/z85/z85_impl.cpp sodiumpp/locked_string.cpp)
target_link_libraries(sodiumpp sodium)
find_library(SODIUMLIB sodium)
add_library(${MODULE_NAME} SHARED ${cxx-sources} ${cxx-headers})

Choose a reason for hiding this comment

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

headers?

endif()

target_link_libraries(sodiumpp
PUBLIC
${SODIUM_LIBRARY}
)

if(SODIUMPP_EXAMPLE)
add_executable(example sodiumpp/example.cpp)
target_link_libraries(example sodiumpp ${SODIUMLIB})
add_executable(example sodiumpp/example.cpp)
target_link_libraries(example ${MODULE_NAME} ${SODIUMLIB})
endif()

if(SODIUMPP_TEST)
add_executable(tests sodiumpp/test.cpp)
target_link_libraries(tests sodiumpp ${SODIUMLIB})
target_link_libraries(tests ${MODULE_NAME} ${SODIUMLIB})
endif()

install(DIRECTORY sodiumpp/include/sodiumpp DESTINATION include)
install_targets(/lib sodiumpp)
install_targets(/lib ${MODULE_NAME})
23 changes: 23 additions & 0 deletions cmake/FindSodium.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# from: https://github.com/kostko/libcurvecpr-asio/blob/master/cmake/FindSodium.cmake
# aa358c98dec8fd0f31e7bab7a585571d5f8bfae3
#
# - Find Sodium
# Find the native libsodium includes and library.
# Once done this will define
#
# SODIUM_INCLUDE_DIR - where to find libsodium header files, etc.
# SODIUM_LIBRARY - List of libraries when using libsodium.
# SODIUM_FOUND - True if libsodium found.
#

FIND_LIBRARY(SODIUM_LIBRARY NAMES sodium libsodium HINTS ${SODIUM_ROOT_DIR}/lib)
find_path(SODIUM_INCLUDE_DIR NAMES sodium.h HINTS ${SODIUM_ROOT_DIR}/include)

# handle the QUIETLY and REQUIRED arguments and set SODIUM_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sodium REQUIRED_VARS SODIUM_LIBRARY SODIUM_INCLUDE_DIR)

MARK_AS_ADVANCED(SODIUM_LIBRARY SODIUM_INCLUDE_DIR)