-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Add CMake support for RHash #103
base: master
Are you sure you want to change the base?
Changes from 2 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(rhash) | ||
|
||
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/version.h" versionfile) | ||
string(REGEX MATCH "#define VERSION \"([0-9]*)\.([0-9]*)\.([0-9]*)\"" _ ${versionfile}) | ||
set(RHASH_VERSION_MAJOR ${CMAKE_MATCH_1}) | ||
set(RHASH_VERSION_MINOR ${CMAKE_MATCH_2}) | ||
set(RHASH_VERSION_PATCH ${CMAKE_MATCH_3}) | ||
set(RHASH_VERSION "${RHASH_VERSION_MAJOR}.${RHASH_VERSION_MINOR}.${RHASH_VERSION_PATCH}") | ||
|
||
option(USE_GETTEXT "Enable gettext (localization) support") | ||
|
||
set(SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/calc_sums.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/hash_print.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/common_func.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/hash_update.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/file.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/file_mask.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/file_set.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/find_file.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/hash_check.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/output.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/parse_cmdline.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/rhash_main.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/win_utils.c") | ||
|
||
set(HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/calc_sums.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/hash_print.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/common_func.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/hash_update.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/file.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/file_mask.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/file_set.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/find_file.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/hash_check.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/output.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/parse_cmdline.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/rhash_main.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/win_utils.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/platform.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/version.h") | ||
|
||
add_subdirectory("librhash") | ||
|
||
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES}) | ||
target_link_libraries(${CMAKE_PROJECT_NAME} librhash) | ||
|
||
if (USE_GETTEXT) | ||
find_package(Intl REQUIRED) | ||
target_link_libraries(${CMAKE_PROJECT_NAME} ${Intl_LIBRARIES}) | ||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${Intl_INCLUDE_DIRS}) | ||
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE USE_GETTEXT) | ||
endif() | ||
|
||
install(TARGETS ${CMAKE_PROJECT_NAME} | ||
RUNTIME DESTINATION bin) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(librhash LANGUAGES C) | ||
|
||
include(GNUInstallDirs) | ||
|
||
if(MSVC OR MSVC90 OR MSVC10) | ||
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. MSVC90/MSVC10 already imply MSVC |
||
set(MSVC ON) | ||
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. uneeded |
||
if(BUILD_SHARED_LIBS) | ||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
endif() | ||
endif() | ||
|
||
option(USE_OPENSSL "Enable OpenSSL (optimized hash functions) support") | ||
option(OPENSSL_RUNTIME "Load OpenSSL at runtime if present") | ||
|
||
set(SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/algorithms.c" | ||
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. same |
||
"${CMAKE_CURRENT_SOURCE_DIR}/byte_order.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/plug_openssl.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/rhash.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/rhash_timing.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/rhash_torrent.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/aich.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/crc32.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/ed2k.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/edonr.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/hex.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/md4.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/md5.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/sha1.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/sha256.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/sha512.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/sha3.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/ripemd-160.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/gost12.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/gost94.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/has160.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/snefru.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/tiger.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/tiger_sbox.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/tth.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/torrent.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/whirlpool.c" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/whirlpool_sbox.c") | ||
|
||
set(HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/algorithms.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/byte_order.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/plug_openssl.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/rhash.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/rhash_timing.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/rhash_torrent.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/aich.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/crc32.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/ed2k.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/edonr.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/hex.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/md4.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/md5.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/sha1.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/sha256.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/sha512.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/sha3.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/ripemd-160.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/gost12.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/gost94.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/has160.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/snefru.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/tiger.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/tth.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/torrent.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/ustd.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/util.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/whirlpool.h") | ||
|
||
add_library(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES}) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "${CMAKE_PROJECT_NAME}") | ||
|
||
if(USE_OPENSSL) | ||
find_package(OpenSSL REQUIRED) | ||
target_link_libraries(${PROJECT_NAME} OpenSSL::Crypto) | ||
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_OPENSSL) | ||
endif() | ||
|
||
if(OPENSSL_RUNTIME) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_DL_LIBS}) | ||
target_compile_definitions(${PROJECT_NAME} PRIVATE OPENSSL_RUNTIME) | ||
endif() | ||
|
||
if(MSVC) | ||
target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_DEPRECATE) | ||
endif() | ||
|
||
set_target_properties(${PROJECT_NAME} PROPERTIES | ||
COMPILE_DEFINITIONS IN_RHASH | ||
DEFINE_SYMBOL RHASH_EXPORTS | ||
PREFIX "" | ||
IMPORT_PREFIX "" | ||
VERSION ${RHASH_VERSION} | ||
SOVERSION ${RHASH_VERSION_MAJOR}) | ||
|
||
export(TARGETS ${PROJECT_NAME} | ||
NAMESPACE ${CMAKE_PROJECT_NAME}:: | ||
FILE "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake") | ||
|
||
install(TARGETS ${PROJECT_NAME} | ||
EXPORT ${CMAKE_PROJECT_NAME}Config | ||
RUNTIME DESTINATION bin | ||
LIBRARY DESTINATION 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. if you use gnuinstalldirs then you can use CMAKE_INSTALL_LIBDIR/BINDIR/INCLUDEDIR |
||
ARCHIVE DESTINATION lib) | ||
|
||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/rhash.h" "${CMAKE_CURRENT_SOURCE_DIR}/rhash_torrent.h" | ||
DESTINATION include) | ||
|
||
install(EXPORT ${CMAKE_PROJECT_NAME}Config | ||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${CMAKE_PROJECT_NAME}/cmake" | ||
NAMESPACE ${CMAKE_PROJECT_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.
no need for CMAKE_CURRENT_SOURCE_DIR, files are always relative to the source dir