From ec01cc9c08b2afc28475469658e80de814175d0b Mon Sep 17 00:00:00 2001 From: Lucas van Dijk Date: Mon, 10 Feb 2020 20:12:00 -0500 Subject: [PATCH 1/7] Use target_* functions to set compiler features This is more modern CMake, and makes it easier to include Bifrost in other CMake projects (as library for example). One of the big benefits of the new target_* API is that compiler options like -march=native now get propogated to any executable linking to bifrost_static of bifrost_dynamic. --- CMakeLists.txt | 3 --- src/CMakeLists.txt | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0ce4ca..63f1c7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,6 @@ project(Bifrost) # Can be replaced with a larger and appropriate number (a power of 2). Actual k-mer size is MAX_KMER_SIZE-1. set(MAX_KMER_SIZE "32") -set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c11 -march=native -DXXH_NAMESPACE=BIFROST_HASH_") -set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11 -march=native -DXXH_NAMESPACE=BIFROST_HASH_") - #set_property(SOURCE xxhash.c APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes -Wundef") set_property(SOURCE BlockedBloomFilter.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -funroll-loops") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8942301..982c67c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,8 @@ file(GLOB headers *.h *.hpp *.hh *.tcc) list(REMOVE_ITEM sources Bifrost.cpp) add_definitions(-DMAX_KMER_SIZE=${MAX_KMER_SIZE}) +set(BIFROST_COMPILER_FLAGS "-march=native") +set(BIFROST_COMPILER_DEFINITIONS "-DXXH_NAMESPACE=BIFROST_HASH_") add_library(bifrost_static STATIC ${sources} ${headers}) add_library(bifrost_dynamic SHARED ${sources} ${headers}) @@ -14,6 +16,15 @@ set_target_properties(bifrost_dynamic PROPERTIES OUTPUT_NAME "bifrost") target_include_directories(bifrost_static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(bifrost_dynamic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_features(bifrost_static PUBLIC cxx_std_11) +target_compile_features(bifrost_dynamic PUBLIC cxx_std_11) + +target_compile_options(bifrost_static PUBLIC "${BIFROST_COMPILER_FLAGS}") +target_compile_options(bifrost_dynamic PUBLIC "${BIFROST_COMPILER_FLAGS}") + +target_compile_definitions(bifrost_static PRIVATE "${BIFROST_COMPILER_DEFINITIONS}") +target_compile_definitions(bifrost_dynamic PRIVATE "${BIFROST_COMPILER_DEFINITIONS}") + add_executable(Bifrost Bifrost.cpp) #find_library(JEMALLOC_STATIC libjemalloc_pic.a) @@ -56,6 +67,9 @@ else() endif(ZLIB_FOUND) target_link_libraries(Bifrost bifrost_dynamic) +target_compile_features(Bifrost PUBLIC cxx_std_11) +target_compile_options(Bifrost PUBLIC "${BIFROST_COMPILER_FLAGS}") +target_compile_definitions(Bifrost PRIVATE "${BIFROST_COMPILER_DEFINITIONS}") install(TARGETS Bifrost DESTINATION bin) install(TARGETS bifrost_dynamic DESTINATION lib) From b02ab62d94acd8f1ae54a9e14979434a949b9775 Mon Sep 17 00:00:00 2001 From: Lucas van Dijk Date: Mon, 10 Feb 2020 20:20:30 -0500 Subject: [PATCH 2/7] Increase minimum CMake version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 63f1c7b..121cbe4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.12) project(Bifrost) From 55b9e60cd5b1f57c471c7fb206ae5bb26367324e Mon Sep 17 00:00:00 2001 From: Lucas van Dijk Date: Sun, 15 Mar 2020 14:49:33 -0400 Subject: [PATCH 3/7] Add 'Profile' CMake build type Should support single and multiple configuration generators. Profiling currently only supported on GCC. --- CMakeLists.txt | 32 +++++++++----------------------- src/CMakeLists.txt | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 121cbe4..cbf72f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,30 +1,16 @@ cmake_minimum_required(VERSION 3.12) +set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES};Profile") project(Bifrost) -# Can be replaced with a larger and appropriate number (a power of 2). Actual k-mer size is MAX_KMER_SIZE-1. -set(MAX_KMER_SIZE "32") - -#set_property(SOURCE xxhash.c APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes -Wundef") -set_property(SOURCE BlockedBloomFilter.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -funroll-loops") +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE} -pg") + set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE} -pg") + set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -pg") + set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -pg") +endif() -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Release") -endif(NOT CMAKE_BUILD_TYPE) - -if(CMAKE_BUILD_TYPE MATCHES Debug) - message("Debug mode") - add_compile_options(-g) -else(CMAKE_BUILD_TYPE MATCHES Debug) - if(CMAKE_BUILD_TYPE MATCHES Profile) - message("Profile mode") - add_compile_options(-pg) - set(CMAKE_SHARED_LINKER_FLAGS "-pg") - set(CMAKE_EXE_LINKER_FLAGS "-pg") - else(CMAKE_BUILD_TYPE MATCHES Profile) - message("Release mode") - add_compile_options(-O3) - endif(CMAKE_BUILD_TYPE MATCHES Profile) -endif(CMAKE_BUILD_TYPE MATCHES Debug) +# Can be replaced with a larger and appropriate number (a power of 2). Actual k-mer size is MAX_KMER_SIZE-1. +set(MAX_KMER_SIZE "32") add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 982c67c..3210828 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,8 +4,17 @@ file(GLOB headers *.h *.hpp *.hh *.tcc) list(REMOVE_ITEM sources Bifrost.cpp) add_definitions(-DMAX_KMER_SIZE=${MAX_KMER_SIZE}) -set(BIFROST_COMPILER_FLAGS "-march=native") -set(BIFROST_COMPILER_DEFINITIONS "-DXXH_NAMESPACE=BIFROST_HASH_") + +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # Make sure to add trailing space + set(PROFILE_FLAGS "$<$:-pg> ") +else() + set(PROFILE_FLAGS "") +endif() + +set(BIFROST_COMPILER_FLAGS "${PROFILE_FLAGS}-march=native") +set(BIFROST_LINKER_FLAGS "${PROFILE_FLAGS}") +set(BIFROST_COMPILER_DEFINITIONS "XXH_NAMESPACE=BIFROST_HASH_") add_library(bifrost_static STATIC ${sources} ${headers}) add_library(bifrost_dynamic SHARED ${sources} ${headers}) @@ -22,6 +31,9 @@ target_compile_features(bifrost_dynamic PUBLIC cxx_std_11) target_compile_options(bifrost_static PUBLIC "${BIFROST_COMPILER_FLAGS}") target_compile_options(bifrost_dynamic PUBLIC "${BIFROST_COMPILER_FLAGS}") +target_link_options(bifrost_static PUBLIC "${BIFROST_LINKER_FLAGS}") +target_link_options(bifrost_dynamic PUBLIC "${BIFROST_LINKER_FLAGS}") + target_compile_definitions(bifrost_static PRIVATE "${BIFROST_COMPILER_DEFINITIONS}") target_compile_definitions(bifrost_dynamic PRIVATE "${BIFROST_COMPILER_DEFINITIONS}") @@ -69,8 +81,11 @@ endif(ZLIB_FOUND) target_link_libraries(Bifrost bifrost_dynamic) target_compile_features(Bifrost PUBLIC cxx_std_11) target_compile_options(Bifrost PUBLIC "${BIFROST_COMPILER_FLAGS}") +target_link_options(Bifrost PUBLIC "${BIFROST_LINKER_FLAGS}") target_compile_definitions(Bifrost PRIVATE "${BIFROST_COMPILER_DEFINITIONS}") +set_property(SOURCE BlockedBloomFilter.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -funroll-loops") + install(TARGETS Bifrost DESTINATION bin) install(TARGETS bifrost_dynamic DESTINATION lib) install(TARGETS bifrost_static DESTINATION lib) From fdaf4236acf57641108e6abf5308e93197a44d1a Mon Sep 17 00:00:00 2001 From: Lucas van Dijk Date: Sun, 15 Mar 2020 15:00:30 -0400 Subject: [PATCH 4/7] Ignore .DS_Store files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1061147..6c9a91d 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ data/ core man/ example/output/ +.DS_Store From 6d8de5466888d78d0a49c300695c804d9ad35312 Mon Sep 17 00:00:00 2001 From: Lucas van Dijk Date: Wed, 8 Apr 2020 12:33:38 -0400 Subject: [PATCH 5/7] Improve CMakeLists.txt a bit - Make sure include directory for bifrost_dynamic is correct when installing - Use the right minimum cmake version - Give error when trying to enable profiling on a compiler other than GCC --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 37 +++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbf72f2..1fb3001 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.8) set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES};Profile") project(Bifrost) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a56222b..9905ea7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,7 +9,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # Make sure to add trailing space set(PROFILE_FLAGS "$<$:-pg> ") else() - set(PROFILE_FLAGS "") + if("${CONFIG}" STREQUAL "Profile" OR "${CMAKE_BUILD_TYPE}" STREQUAL "Profile") + message(FATAL_ERROR "Profiling is only supported with GCC") + endif() endif() set(BIFROST_COMPILER_FLAGS "${PROFILE_FLAGS}-march=native") @@ -23,10 +25,15 @@ set_target_properties(bifrost_static PROPERTIES OUTPUT_NAME "bifrost") set_target_properties(bifrost_dynamic PROPERTIES OUTPUT_NAME "bifrost") target_include_directories(bifrost_static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_include_directories(bifrost_dynamic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(bifrost_dynamic PUBLIC + $ + $ + ) target_compile_features(bifrost_static PUBLIC cxx_std_11) -target_compile_features(bifrost_dynamic PUBLIC cxx_std_11) +target_compile_features(bifrost_static PRIVATE c_std_11) +target_compile_features(bifrost_dynamic PUBLIC cxx_std_11 c_std_11) +target_compile_features(bifrost_dynamic PRIVATE c_std_11) target_compile_options(bifrost_static PUBLIC "${BIFROST_COMPILER_FLAGS}") target_compile_options(bifrost_dynamic PUBLIC "${BIFROST_COMPILER_FLAGS}") @@ -37,29 +44,31 @@ target_link_options(bifrost_dynamic PUBLIC "${BIFROST_LINKER_FLAGS}") target_compile_definitions(bifrost_static PRIVATE "${BIFROST_COMPILER_DEFINITIONS}") target_compile_definitions(bifrost_dynamic PRIVATE "${BIFROST_COMPILER_DEFINITIONS}") -add_executable(Bifrost Bifrost.cpp) - find_package(Threads REQUIRED) -target_link_libraries(bifrost_static ${CMAKE_THREAD_LIBS_INIT}) -target_link_libraries(bifrost_dynamic ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(bifrost_static PUBLIC ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(bifrost_dynamic PUBLIC ${CMAKE_THREAD_LIBS_INIT}) find_package(ZLIB REQUIRED) -target_link_libraries(bifrost_static ${ZLIB_LIBRARIES}) -target_link_libraries(bifrost_dynamic ${ZLIB_LIBRARIES}) +target_link_libraries(bifrost_static PUBLIC ${ZLIB_LIBRARIES}) +target_link_libraries(bifrost_dynamic PUBLIC ${ZLIB_LIBRARIES}) if (ZLIB_FOUND) - include_directories(${ZLIB_INCLUDE_DIRS}) + target_include_directories(bifrost_static PRIVATE ${ZLIB_INCLUDE_DIRS}) + target_include_directories(bifrost_dynamic PRIVATE ${ZLIB_INCLUDE_DIRS}) else() message(FATAL_ERROR "zlib not found. Required for to output files") endif(ZLIB_FOUND) -target_link_libraries(Bifrost bifrost_dynamic) -target_compile_features(Bifrost PUBLIC cxx_std_11) +add_executable(Bifrost Bifrost.cpp) +set_property(SOURCE BlockedBloomFilter.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -funroll-loops") + +target_include_directories(Bifrost PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + +target_compile_features(Bifrost PUBLIC cxx_std_11 c_std_11) target_compile_options(Bifrost PUBLIC "${BIFROST_COMPILER_FLAGS}") target_link_options(Bifrost PUBLIC "${BIFROST_LINKER_FLAGS}") target_compile_definitions(Bifrost PRIVATE "${BIFROST_COMPILER_DEFINITIONS}") - -set_property(SOURCE BlockedBloomFilter.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -funroll-loops") +target_link_libraries(Bifrost PUBLIC bifrost_dynamic) install(TARGETS Bifrost DESTINATION bin) install(TARGETS bifrost_dynamic DESTINATION lib) From ef4a9cd31a3135d5f1671a7c1a2eb66788871b54 Mon Sep 17 00:00:00 2001 From: Lucas van Dijk Date: Wed, 8 Apr 2020 12:43:02 -0400 Subject: [PATCH 6/7] Make Zlib include dirs and linking consistent --- src/CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9905ea7..b469188 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,12 +49,13 @@ target_link_libraries(bifrost_static PUBLIC ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(bifrost_dynamic PUBLIC ${CMAKE_THREAD_LIBS_INIT}) find_package(ZLIB REQUIRED) -target_link_libraries(bifrost_static PUBLIC ${ZLIB_LIBRARIES}) -target_link_libraries(bifrost_dynamic PUBLIC ${ZLIB_LIBRARIES}) if (ZLIB_FOUND) - target_include_directories(bifrost_static PRIVATE ${ZLIB_INCLUDE_DIRS}) - target_include_directories(bifrost_dynamic PRIVATE ${ZLIB_INCLUDE_DIRS}) + target_link_libraries(bifrost_static PUBLIC ${ZLIB_LIBRARIES}) + target_link_libraries(bifrost_dynamic PUBLIC ${ZLIB_LIBRARIES}) + + target_include_directories(bifrost_static PUBLIC ${ZLIB_INCLUDE_DIRS}) + target_include_directories(bifrost_dynamic PUBLIC ${ZLIB_INCLUDE_DIRS}) else() message(FATAL_ERROR "zlib not found. Required for to output files") endif(ZLIB_FOUND) From 6b03ccd2a11af5343188bf6175329098a7a5bb1d Mon Sep 17 00:00:00 2001 From: Lucas van Dijk Date: Wed, 8 Apr 2020 13:49:39 -0400 Subject: [PATCH 7/7] Increase min CMake version to 3.13 target_link_options was added in 3.13 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fb3001..0321c93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.13) set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES};Profile") project(Bifrost)