diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4650f9d --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# CMake +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps diff --git a/CMakeLists.txt b/CMakeLists.txt index d07d1d7..752ee7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,36 @@ cmake_minimum_required(VERSION 3.14) -project(hmac-sha256) +set(CMAKE_C_STANDARD 99) -add_library(hmac-sha256 STATIC hmac_sha256.c sha256.c ) +# For "CMAKE_INSTALL_" standard installation directories +include(GNUInstallDirs) -install(TARGETS hmac-sha256 DESTINATION lib) -install(FILES hmac-sha256.h DESTINATION include) +project(hmac_sha256 LANGUAGES C CXX) + +option(HMAC_SHA256_TESTS "Build unit tests" FALSE) +option(HMAC_SHA256_EXAMPLES "Build the examples" FALSE) + +add_library(hmac_sha256 STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/sha256.c + ${CMAKE_CURRENT_SOURCE_DIR}/hmac_sha256.c +) +target_include_directories(hmac_sha256 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) + +install(TARGETS hmac_sha256 + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) + +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/hmac_sha256.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) + +if (HMAC_SHA256_TESTS) + enable_testing() + add_subdirectory(tests) +endif() + +if(HMAC_SHA256_EXAMPLES) + add_subdirectory(examples) +endif() diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..4650f9d --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,12 @@ +# CMake +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..081df23 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,13 @@ +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) + +add_executable(hmac_cxx_example + hmac_cxx_example.cpp +) + +add_executable(hmac_c_example + hmac_c_example.c +) + +target_link_libraries(hmac_cxx_example hmac_sha256) +target_link_libraries(hmac_c_example hmac_sha256) diff --git a/examples/simple_example.c b/examples/hmac_c_example.c similarity index 100% rename from examples/simple_example.c rename to examples/hmac_c_example.c diff --git a/examples/simple_example.cpp b/examples/hmac_cxx_example.cpp similarity index 100% rename from examples/simple_example.cpp rename to examples/hmac_cxx_example.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..5be3a59 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,7 @@ +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) + +add_executable(tests tests.cpp) +target_link_libraries(tests hmac_sha256) + +add_test(hmac_sha256-tests tests) diff --git a/examples/tests.cpp b/tests/tests.cpp similarity index 100% rename from examples/tests.cpp rename to tests/tests.cpp