Skip to content

Commit

Permalink
Cleaned up cmake configs and added install instructions. Rel #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Syndace committed Nov 9, 2022
1 parent 0159786 commit 2309dcc
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 48 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ jobs:
- name: Rename the binaries
run: |
cd bin/
mv combined_static.lib libxeddsa-windows-amd64.lib
mv combined_dynamic.lib libxeddsa-windows-amd64.dll.lib
mv combined_dynamic.dll libxeddsa-windows-amd64.dll
mv static/libxeddsa.lib libxeddsa-windows-amd64.lib
mv dynamic/libxeddsa.lib libxeddsa-windows-amd64.dll.lib
mv dynamic/libxeddsa.dll libxeddsa-windows-amd64.dll
- name: Upload the binaries
uses: actions/[email protected]
Expand Down Expand Up @@ -85,8 +85,8 @@ jobs:
- name: Rename the binaries
run: |
cd bin/
mv libcombined_static.a libxeddsa-macos-amd64.a
mv libcombined_dynamic.dylib libxeddsa-macos-amd64.dylib
mv static/libxeddsa.a libxeddsa-macos-amd64.a
mv dynamic/libxeddsa.dylib libxeddsa-macos-amd64.dylib
- name: Upload the binaries
uses: actions/[email protected]
Expand Down Expand Up @@ -124,8 +124,8 @@ jobs:
- name: Rename the binaries
run: |
cd bin/
mv libcombined_static.a libxeddsa-macos-arm64.a
mv libcombined_dynamic.dylib libxeddsa-macos-arm64.dylib
mv static/libxeddsa.a libxeddsa-macos-arm64.a
mv dynamic/libxeddsa.dylib libxeddsa-macos-arm64.dylib
- name: Upload the binaries
uses: actions/[email protected]
Expand Down Expand Up @@ -163,8 +163,8 @@ jobs:
- name: Rename the binaries
run: |
cd bin/
mv libcombined_static.a libxeddsa-linux-amd64.a
mv libcombined_dynamic.so libxeddsa-linux-amd64.so
mv static/libxeddsa.a libxeddsa-linux-amd64.a
mv dynamic/libxeddsa.so libxeddsa-linux-amd64.so
- name: Upload the binaries
uses: actions/[email protected]
Expand Down
54 changes: 21 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ include(CTest)

add_subdirectory(ref10)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/static)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/dynamic)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/bin/static)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/bin/dynamic)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/bin)
endforeach ()

if (WIN32)
Expand Down Expand Up @@ -79,24 +79,8 @@ target_compile_definitions(xeddsa_objects PRIVATE SODIUM_DLL_EXPORT)
target_compile_definitions(xeddsa_objects PRIVATE BUILD)

add_library(xeddsa_static STATIC $<TARGET_OBJECTS:xeddsa_objects>)

if (NOT DEFINED EMSCRIPTEN)
add_library(xeddsa_dynamic SHARED $<TARGET_OBJECTS:xeddsa_objects>)

if (WIN32)
# Correct the import library.
set_target_properties(xeddsa_dynamic PROPERTIES IMPORT_PREFIX "")
set_target_properties(xeddsa_dynamic PROPERTIES IMPORT_SUFFIX ".lib")
endif (WIN32)
endif ()

####################
# combined library #
####################

add_library(combined_static STATIC CMakeLists.txt)
set_target_properties(combined_static PROPERTIES LINKER_LANGUAGE C)
target_link_libraries(combined_static PUBLIC
set_target_properties(xeddsa_static PROPERTIES OUTPUT_NAME xeddsa)
target_link_libraries(xeddsa_static PUBLIC
xeddsa_objects
crypto_sign_objects
crypto_hash_objects
Expand All @@ -110,10 +94,12 @@ target_link_libraries(combined_static PUBLIC
sodium_static
)

install(TARGETS xeddsa_static)

if (NOT DEFINED EMSCRIPTEN)
add_library(combined_dynamic SHARED CMakeLists.txt)
set_target_properties(combined_dynamic PROPERTIES LINKER_LANGUAGE C)
target_link_libraries(combined_dynamic PUBLIC
add_library(xeddsa_dynamic SHARED $<TARGET_OBJECTS:xeddsa_objects>)
set_target_properties(xeddsa_dynamic PROPERTIES OUTPUT_NAME xeddsa)
target_link_libraries(xeddsa_dynamic PUBLIC
xeddsa_objects
crypto_sign_objects
crypto_hash_objects
Expand All @@ -126,6 +112,14 @@ if (NOT DEFINED EMSCRIPTEN)
kernelrandombytes_objects
sodium_shared
)

if (WIN32)
# Correct the import library.
set_target_properties(xeddsa_dynamic PROPERTIES IMPORT_PREFIX "")
set_target_properties(xeddsa_dynamic PROPERTIES IMPORT_SUFFIX ".lib")
endif (WIN32)

install(TARGETS xeddsa_dynamic)
endif ()

##########################
Expand All @@ -147,24 +141,18 @@ target_include_directories(xeddsa_test_objects PRIVATE test)

add_executable(xeddsa_test_static $<TARGET_OBJECTS:xeddsa_test_objects>)
target_include_directories(xeddsa_test_static PRIVATE test)
target_link_libraries(xeddsa_test_static combined_static sodium_static)
target_link_libraries(xeddsa_test_static xeddsa_static sodium_static)

if (NOT DEFINED EMSCRIPTEN)
add_executable(xeddsa_test_dynamic $<TARGET_OBJECTS:xeddsa_test_objects>)
target_include_directories(xeddsa_test_dynamic PRIVATE test)
target_link_libraries(xeddsa_test_dynamic combined_dynamic sodium_shared)
target_link_libraries(xeddsa_test_dynamic xeddsa_dynamic sodium_shared)
endif ()

################
# DEPENDENCIES #
################

target_link_libraries(xeddsa_static crypto_sign_static sodium_static)

if (NOT DEFINED EMSCRIPTEN)
target_link_libraries(xeddsa_dynamic crypto_sign_dynamic sodium_shared)
endif ()

target_include_directories(xeddsa_objects PUBLIC
ref10/crypto_sign
ref10/crypto_hash
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where ``YourBuildEnv`` depends on your build environment. ``cmake --help`` lists

The next step is to build the library, which again depends on your build system. With MinGW for example, use ``mingw32-make``.

When the build is done, run ``ctest ..`` to run the tests.
When the build is done, run ``ctest -C Debug ..`` to run the tests in debug configuration, and ``ctest -C Release ..`` to run them in release configuration.

Emscripten
----------
Expand Down
28 changes: 24 additions & 4 deletions ref10/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ if (NOT (UNIX OR WIN32))
message(FATAL_ERROR "Unsupported operating system (neither UNIX nor Windows). CMake will exit.")
endif ()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/static)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/dynamic)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/bin/static)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/bin/dynamic)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${PROJECT_SOURCE_DIR}/bin)
endforeach ()

if (WIN32)
Expand Down Expand Up @@ -86,6 +86,8 @@ target_include_directories(crypto_core_objects PUBLIC crypto_core)

add_library(crypto_core_static STATIC $<TARGET_OBJECTS:crypto_core_objects>)
add_library(crypto_core_dynamic SHARED $<TARGET_OBJECTS:crypto_core_objects>)
set_target_properties(crypto_core_static PROPERTIES OUTPUT_NAME crypto_core)
set_target_properties(crypto_core_dynamic PROPERTIES OUTPUT_NAME crypto_core)

if (WIN32)
# Correct the import library.
Expand All @@ -109,6 +111,8 @@ target_include_directories(crypto_hash_objects PUBLIC crypto_hash)

add_library(crypto_hash_static STATIC $<TARGET_OBJECTS:crypto_hash_objects>)
add_library(crypto_hash_dynamic SHARED $<TARGET_OBJECTS:crypto_hash_objects>)
set_target_properties(crypto_hash_static PROPERTIES OUTPUT_NAME crypto_hash)
set_target_properties(crypto_hash_dynamic PROPERTIES OUTPUT_NAME crypto_hash)

if (WIN32)
# Correct the import library.
Expand All @@ -132,6 +136,8 @@ target_include_directories(crypto_hashblocks_objects PUBLIC crypto_hashblocks)

add_library(crypto_hashblocks_static STATIC $<TARGET_OBJECTS:crypto_hashblocks_objects>)
add_library(crypto_hashblocks_dynamic SHARED $<TARGET_OBJECTS:crypto_hashblocks_objects>)
set_target_properties(crypto_hashblocks_static PROPERTIES OUTPUT_NAME crypto_hashblocks)
set_target_properties(crypto_hashblocks_dynamic PROPERTIES OUTPUT_NAME crypto_hashblocks)

if (WIN32)
# Correct the import library.
Expand All @@ -155,6 +161,8 @@ target_include_directories(crypto_rng_objects PUBLIC crypto_rng)

add_library(crypto_rng_static STATIC $<TARGET_OBJECTS:crypto_rng_objects>)
add_library(crypto_rng_dynamic SHARED $<TARGET_OBJECTS:crypto_rng_objects>)
set_target_properties(crypto_rng_static PROPERTIES OUTPUT_NAME crypto_rng)
set_target_properties(crypto_rng_dynamic PROPERTIES OUTPUT_NAME crypto_rng)

if (WIN32)
# Correct the import library.
Expand Down Expand Up @@ -191,6 +199,8 @@ target_include_directories(crypto_scalarmult_objects PUBLIC crypto_scalarmult)

add_library(crypto_scalarmult_static STATIC $<TARGET_OBJECTS:crypto_scalarmult_objects>)
add_library(crypto_scalarmult_dynamic SHARED $<TARGET_OBJECTS:crypto_scalarmult_objects>)
set_target_properties(crypto_scalarmult_static PROPERTIES OUTPUT_NAME crypto_scalarmult)
set_target_properties(crypto_scalarmult_dynamic PROPERTIES OUTPUT_NAME crypto_scalarmult)

if (WIN32)
# Correct the import library.
Expand Down Expand Up @@ -252,6 +262,8 @@ target_include_directories(crypto_sign_objects PUBLIC crypto_sign)

add_library(crypto_sign_static STATIC $<TARGET_OBJECTS:crypto_sign_objects>)
add_library(crypto_sign_dynamic SHARED $<TARGET_OBJECTS:crypto_sign_objects>)
set_target_properties(crypto_sign_static PROPERTIES OUTPUT_NAME crypto_sign)
set_target_properties(crypto_sign_dynamic PROPERTIES OUTPUT_NAME crypto_sign)

if (WIN32)
# Correct the import library.
Expand All @@ -276,6 +288,8 @@ target_include_directories(crypto_stream_objects PUBLIC crypto_stream)

add_library(crypto_stream_static STATIC $<TARGET_OBJECTS:crypto_stream_objects>)
add_library(crypto_stream_dynamic SHARED $<TARGET_OBJECTS:crypto_stream_objects>)
set_target_properties(crypto_stream_static PROPERTIES OUTPUT_NAME crypto_stream)
set_target_properties(crypto_stream_dynamic PROPERTIES OUTPUT_NAME crypto_stream)

if (WIN32)
# Correct the import library.
Expand All @@ -299,6 +313,8 @@ target_include_directories(crypto_verify_objects PUBLIC crypto_verify)

add_library(crypto_verify_static STATIC $<TARGET_OBJECTS:crypto_verify_objects>)
add_library(crypto_verify_dynamic SHARED $<TARGET_OBJECTS:crypto_verify_objects>)
set_target_properties(crypto_verify_static PROPERTIES OUTPUT_NAME crypto_verify)
set_target_properties(crypto_verify_dynamic PROPERTIES OUTPUT_NAME crypto_verify)

if (WIN32)
# Correct the import library.
Expand All @@ -322,6 +338,8 @@ target_include_directories(fastrandombytes_objects PUBLIC fastrandombytes)

add_library(fastrandombytes_static STATIC $<TARGET_OBJECTS:fastrandombytes_objects>)
add_library(fastrandombytes_dynamic SHARED $<TARGET_OBJECTS:fastrandombytes_objects>)
set_target_properties(fastrandombytes_static PROPERTIES OUTPUT_NAME fastrandombytes)
set_target_properties(fastrandombytes_dynamic PROPERTIES OUTPUT_NAME fastrandombytes)

if (WIN32)
# Correct the import library.
Expand Down Expand Up @@ -396,6 +414,8 @@ target_include_directories(kernelrandombytes_objects PUBLIC kernelrandombytes)

add_library(kernelrandombytes_static STATIC $<TARGET_OBJECTS:kernelrandombytes_objects>)
add_library(kernelrandombytes_dynamic SHARED $<TARGET_OBJECTS:kernelrandombytes_objects>)
set_target_properties(kernelrandombytes_static PROPERTIES OUTPUT_NAME kernelrandombytes)
set_target_properties(kernelrandombytes_dynamic PROPERTIES OUTPUT_NAME kernelrandombytes)

if (WIN32)
# Correct the import library.
Expand Down
2 changes: 1 addition & 1 deletion ref10/kernelrandombytes/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main()
unsigned long long i;
unsigned long long j;

for (j = 0;j < 3;++j) {
for (j = 0;j < 10000;++j) {
kernelrandombytes(x,sizeof x);
for (i = 0;i < 256;++i) freq[i] = 0;
for (i = 0;i < sizeof x;++i) ++freq[255 & (int) x[i]];
Expand Down

0 comments on commit 2309dcc

Please sign in to comment.