From 4c6037001de7c1f31bbd516397137d3d4e064b92 Mon Sep 17 00:00:00 2001 From: Simon Gene Gottlieb Date: Tue, 23 Jul 2024 16:35:42 +0200 Subject: [PATCH 1/4] fix, cmake: scope all variables into SDSL_ namespace --- CMakeLists.txt | 16 +++++++++++++--- CMakeModules/CompilerFlags.cmake | 4 ++-- extras/CMakeLists.txt | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01decefb..6dd6b954 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,14 @@ set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") ## (1) Read and set library version include (ParseVersionFile) +# check if this is the main iproject +# This can be removed if cmake 3.21 is used +# https://cmake.org/cmake/help/latest/variable/PROJECT_IS_TOP_LEVEL.html +set(PROJECT_IS_TOP_LEVEL FALSE) +if (NOT DEFINED PROJECT_NAME) + set(PROJECT_IS_TOP_LEVEL TRUE) +endif () + ## (2) CREATE PROJECT cmake_policy (SET CMP0048 NEW) # no more project version warnings project (sdsl @@ -18,10 +26,10 @@ if (NOT CMAKE_BUILD_TYPE) endif () ## (5) Options -option (CODE_COVERAGE "Set ON to add code coverage compile options" OFF) +option (SDSL_CODE_COVERAGE "Set ON to add code coverage compile options" OFF) option (SDSL_HEADER_TEST "Set ON to run header tests only" OFF) -option (GENERATE_DOC "Set ON to genrate doxygen API reference in build/doc directory" OFF) -option (USE_LIBCPP "Use the LLVM libc++ instead of GCC libstdc++ on OS X" ON) +option (SDSL_GENERATE_DOC "Set ON to genrate doxygen API reference in build/doc directory" OFF) +option (SDSL_USE_LIBCPP "Use the LLVM libc++ instead of GCC libstdc++ on OS X" ON) ## (6) Compiler requirements and compile options include (CompilerFlags) @@ -29,10 +37,12 @@ include (CompilerFlags) ## (7) Configure scripts configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/Make.helper.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/Make.helper" @ONLY) + enable_testing () # (8) main library target set (gtest_dir ${CMAKE_CURRENT_LIST_DIR}/external/googletest) + add_subdirectory (external) add_subdirectory (lib) diff --git a/CMakeModules/CompilerFlags.cmake b/CMakeModules/CompilerFlags.cmake index aa6859c5..00f0bbee 100644 --- a/CMakeModules/CompilerFlags.cmake +++ b/CMakeModules/CompilerFlags.cmake @@ -32,12 +32,12 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") add_definitions ("/DMSVC_COMPILER") endif () -if (CODE_COVERAGE) +if (SDSL_CODE_COVERAGE) checkandappendcompilerflags ("Debug" "-g -fprofile-arcs -ftest-coverage -lgcov") endif () if (APPLE) - if (USE_LIBCPP AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$")) + if (SDSL_USE_LIBCPP AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$")) checkandappendcompilerflags (${CMAKE_BUILD_TYPE} "-stdlib=libc++") endif () endif () diff --git a/extras/CMakeLists.txt b/extras/CMakeLists.txt index 369f6621..ea258dc1 100644 --- a/extras/CMakeLists.txt +++ b/extras/CMakeLists.txt @@ -1,7 +1,7 @@ include (Colors) # (1) generate docs -if (GENERATE_DOC) +if (SDSL_GENERATE_DOC) find_package (Doxygen) if (DOXYGEN_FOUND) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) @@ -11,7 +11,7 @@ if (GENERATE_DOC) COMMENT "Generating API documentation with Doxygen" VERBATIM) endif (DOXYGEN_FOUND) -endif (GENERATE_DOC) +endif (SDSL_GENERATE_DOC) ## (2) Add 'uninstall' target ## configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/../CMakeModules/cmake_uninstall.cmake.in" From 2ed35bec3b5bc9ad133ee750305cdf6a22cbec1a Mon Sep 17 00:00:00 2001 From: Simon Gene Gottlieb Date: Tue, 23 Jul 2024 16:37:03 +0200 Subject: [PATCH 2/4] feat, cmake: add SDSL_BUILD_TESTS command --- CMakeLists.txt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dd6b954..cbbb59ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ endif () ## (5) Options option (SDSL_CODE_COVERAGE "Set ON to add code coverage compile options" OFF) option (SDSL_HEADER_TEST "Set ON to run header tests only" OFF) +option (SDSL_BUILD_TESTS "Set ON to build tests" ${PROJECT_IS_TOP_LEVEL}) option (SDSL_GENERATE_DOC "Set ON to genrate doxygen API reference in build/doc directory" OFF) option (SDSL_USE_LIBCPP "Use the LLVM libc++ instead of GCC libstdc++ on OS X" ON) @@ -38,10 +39,12 @@ include (CompilerFlags) configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/Make.helper.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/Make.helper" @ONLY) -enable_testing () +if (SDSL_BUILD_TESTS) + enable_testing () -# (8) main library target -set (gtest_dir ${CMAKE_CURRENT_LIST_DIR}/external/googletest) + # (8) main library target + set (gtest_dir ${CMAKE_CURRENT_LIST_DIR}/external/googletest) +endif() add_subdirectory (external) add_subdirectory (lib) @@ -55,7 +58,9 @@ if (SDSL_HEADER_TEST) add_subdirectory (test/header) return () endif () -add_subdirectory (test) +if (SDSL_BUILD_TESTS) + add_subdirectory (test) +endif() # (10) perform extra tasks such as doxygen / packaging and uninstall target add_subdirectory (extras) From 1e7aad12e45548304abb2b5cbadc09808ffbb765 Mon Sep 17 00:00:00 2001 From: Simon Gene Gottlieb Date: Tue, 23 Jul 2024 16:42:22 +0200 Subject: [PATCH 3/4] feat, cmake add cmake options for building tutorial and examples --- CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbbb59ce..15700128 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,8 @@ endif () option (SDSL_CODE_COVERAGE "Set ON to add code coverage compile options" OFF) option (SDSL_HEADER_TEST "Set ON to run header tests only" OFF) option (SDSL_BUILD_TESTS "Set ON to build tests" ${PROJECT_IS_TOP_LEVEL}) +option (SDSL_BUILD_TUTORIAL "Set ON to build tutorials" ${PROJECT_IS_TOP_LEVEL}) +option (SDSL_BUILD_EXAMPLES "Set ON to build examples" ${PROJECT_IS_TOP_LEVEL}) option (SDSL_GENERATE_DOC "Set ON to genrate doxygen API reference in build/doc directory" OFF) option (SDSL_USE_LIBCPP "Use the LLVM libc++ instead of GCC libstdc++ on OS X" ON) @@ -65,5 +67,9 @@ endif() # (10) perform extra tasks such as doxygen / packaging and uninstall target add_subdirectory (extras) -add_subdirectory (tutorial) -add_subdirectory (examples) +if (SDSL_BUILD_TUTORIAL) + add_subdirectory (tutorial) +endif() +if (SDSL_BUILD_EXAMPLES) + add_subdirectory (examples) +endif() From 5a6719e39a51694e0eb604949d7ea1fb12d339a6 Mon Sep 17 00:00:00 2001 From: Simon Gene Gottlieb Date: Tue, 23 Jul 2024 16:44:55 +0200 Subject: [PATCH 4/4] feat: add sdsl-lite::sdsl-lite target --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 15700128..61aaf226 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,10 @@ set (sdsl_include_directory "${CMAKE_CURRENT_SOURCE_DIR}/include") file (GLOB HEADERS "${sdsl_include_directory}/sdsl/*.hpp") add_custom_target (sdsl SOURCES ${HEADERS}) +add_library(sdsl-lite INTERFACE) +target_include_directories(sdsl-lite INTERFACE SYSTEM ${sdsl_include_directory}) +add_library(sdsl-lite::sdsl-lite ALIAS sdsl-lite) + # (9) test targets if (SDSL_HEADER_TEST) add_subdirectory (test/header)