|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10) |
|
|
project(md5sum LANGUAGES CXX) |
|
|
project(md5sum LANGUAGES CXX) |
|
|
|
|
|
|
|
|
if ("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.13") |
|
|
if ("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.13") |
|
|
cmake_policy(SET CMP0077 NEW) |
|
|
cmake_policy(SET CMP0077 NEW) |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------------ # |
|
|
# ------------------------------------------------------------------------------------ # |
|
@ -17,14 +17,14 @@ option(MD5_ENABLE_BENCHMARK "Enable benchmark of the md5sum library." OFF) |
|
|
|
|
|
|
|
|
set(CXX_STANDARDS) |
|
|
set(CXX_STANDARDS) |
|
|
foreach (CXX_FEATURE ${CMAKE_CXX_COMPILE_FEATURES}) |
|
|
foreach (CXX_FEATURE ${CMAKE_CXX_COMPILE_FEATURES}) |
|
|
if (CXX_FEATURE MATCHES "^cxx_std_[0-9]+$") |
|
|
if (CXX_FEATURE MATCHES "^cxx_std_[0-9]+$") |
|
|
string(REGEX MATCH "[0-9]+$" CXX_STANDARD ${CXX_FEATURE}) |
|
|
string(REGEX MATCH "[0-9]+$" CXX_STANDARD ${CXX_FEATURE}) |
|
|
list(APPEND CXX_STANDARDS ${CXX_STANDARD}) # supported c++ standards |
|
|
list(APPEND CXX_STANDARDS ${CXX_STANDARD}) # supported c++ standards |
|
|
endif() |
|
|
endif() |
|
|
endforeach() |
|
|
endforeach() |
|
|
|
|
|
|
|
|
if (NOT 17 IN_LIST CXX_STANDARDS) |
|
|
if (NOT 17 IN_LIST CXX_STANDARDS) |
|
|
message(FATAL_ERROR "MD5 project require at least C++17.") |
|
|
message(FATAL_ERROR "MD5 project require at least C++17.") |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
|
|
|
list(GET CXX_STANDARDS -1 MD5_CXX_STANDARD) # select the latest C++ standard |
|
|
list(GET CXX_STANDARDS -1 MD5_CXX_STANDARD) # select the latest C++ standard |
|
@ -34,27 +34,41 @@ set(CMAKE_CXX_STANDARD ${MD5_CXX_STANDARD}) |
|
|
# ------------------------------------------------------------------------------------ # |
|
|
# ------------------------------------------------------------------------------------ # |
|
|
|
|
|
|
|
|
if (NOT CMAKE_BUILD_TYPE) |
|
|
if (NOT CMAKE_BUILD_TYPE) |
|
|
set(CMAKE_BUILD_TYPE Release) # using release build in default |
|
|
set(CMAKE_BUILD_TYPE Release) # using release build in default |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
|
|
|
add_compile_options(-Wall -Wextra -Werror) |
|
|
if (MSVC) |
|
|
if (MD5_ENABLE_LTO) |
|
|
add_compile_options(/W4) # TODO: add `/WX` after fix MSVC warnings |
|
|
|
|
|
if (MD5_ENABLE_LTO) |
|
|
|
|
|
add_compile_options(/GL) |
|
|
|
|
|
add_link_options(/LTCG) |
|
|
|
|
|
endif() |
|
|
|
|
|
else() |
|
|
|
|
|
add_compile_options(-Wall -Wextra -Werror) |
|
|
|
|
|
if (MD5_ENABLE_LTO) |
|
|
add_compile_options(-flto=auto) |
|
|
add_compile_options(-flto=auto) |
|
|
|
|
|
endif() |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------------ # |
|
|
|
|
|
|
|
|
file(GLOB MD5_SRC src/impl/*.cc) |
|
|
file(GLOB MD5_SRC src/impl/*.cc) |
|
|
if (NOT MD5_SHARED_LIB) |
|
|
if (NOT MD5_SHARED_LIB) |
|
|
add_library(md5sum STATIC ${MD5_SRC}) |
|
|
add_library(md5sum STATIC ${MD5_SRC}) |
|
|
else() |
|
|
else() |
|
|
add_library(md5sum SHARED ${MD5_SRC}) |
|
|
add_library(md5sum SHARED ${MD5_SRC}) |
|
|
|
|
|
if (NOT MSVC) |
|
|
target_compile_options(md5sum PRIVATE -fvisibility=hidden) |
|
|
target_compile_options(md5sum PRIVATE -fvisibility=hidden) |
|
|
|
|
|
endif() |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
|
|
|
set(MD5_COMPILE_OPTIONS |
|
|
if (MSVC) |
|
|
-fno-rtti |
|
|
set(MD5_COMPILE_OPTIONS /GR-) |
|
|
-fno-exceptions |
|
|
else() |
|
|
-fno-unwind-tables |
|
|
set(MD5_COMPILE_OPTIONS |
|
|
-fno-asynchronous-unwind-tables) |
|
|
-fno-rtti -fno-exceptions |
|
|
|
|
|
-fno-unwind-tables -fno-asynchronous-unwind-tables) |
|
|
|
|
|
endif() |
|
|
|
|
|
|
|
|
target_compile_options(md5sum PRIVATE ${MD5_COMPILE_OPTIONS}) |
|
|
target_compile_options(md5sum PRIVATE ${MD5_COMPILE_OPTIONS}) |
|
|
target_include_directories(md5sum PUBLIC src/) |
|
|
target_include_directories(md5sum PUBLIC src/) |
|
@ -64,9 +78,9 @@ add_library(md5sum::md5 ALIAS md5sum) |
|
|
# ------------------------------------------------------------------------------------ # |
|
|
# ------------------------------------------------------------------------------------ # |
|
|
|
|
|
|
|
|
if (MD5_BUILD_DEMO) |
|
|
if (MD5_BUILD_DEMO) |
|
|
add_executable(md5_demo demo.cc) |
|
|
add_executable(md5_demo demo.cc) |
|
|
target_link_libraries(md5_demo PRIVATE md5sum) |
|
|
target_link_libraries(md5_demo PRIVATE md5sum) |
|
|
target_compile_options(md5_demo PRIVATE ${MD5_COMPILE_OPTIONS}) |
|
|
target_compile_options(md5_demo PRIVATE ${MD5_COMPILE_OPTIONS}) |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------------ # |
|
|
# ------------------------------------------------------------------------------------ # |
|
@ -74,17 +88,17 @@ endif() |
|
|
include(third_party/ThirdParty.cmake) |
|
|
include(third_party/ThirdParty.cmake) |
|
|
|
|
|
|
|
|
if (MD5_ENABLE_TESTING) |
|
|
if (MD5_ENABLE_TESTING) |
|
|
enable_testing() |
|
|
enable_testing() |
|
|
file(GLOB MD5_TEST_SRC test/*.cc) |
|
|
file(GLOB MD5_TEST_SRC test/*.cc) |
|
|
add_executable(md5_test ${MD5_TEST_SRC}) |
|
|
add_executable(md5_test ${MD5_TEST_SRC}) |
|
|
target_link_libraries(md5_test PRIVATE md5sum GTest::gtest_main) |
|
|
target_link_libraries(md5_test PRIVATE md5sum GTest::gtest_main) |
|
|
add_test(NAME md5_test COMMAND md5_test) |
|
|
add_test(NAME md5_test COMMAND md5_test) |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
|
|
|
if (MD5_ENABLE_BENCHMARK) |
|
|
if (MD5_ENABLE_BENCHMARK) |
|
|
add_executable(md5_benchmark benchmark.cc) |
|
|
add_executable(md5_benchmark benchmark.cc) |
|
|
target_link_libraries(md5_benchmark PRIVATE md5sum benchmark::benchmark_main) |
|
|
target_link_libraries(md5_benchmark PRIVATE md5sum benchmark::benchmark_main) |
|
|
target_compile_options(md5_benchmark PRIVATE ${MD5_COMPILE_OPTIONS}) |
|
|
target_compile_options(md5_benchmark PRIVATE ${MD5_COMPILE_OPTIONS}) |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------------ # |
|
|
# ------------------------------------------------------------------------------------ # |
|
|