From 1008f83092269d89facf66cc9c4d95f46f48cabb Mon Sep 17 00:00:00 2001 From: mjvankampen Date: Mon, 18 Jan 2021 16:26:06 +0100 Subject: [PATCH] Adds option to force a build of protokit and select a specific commit (#15) * Adds option to force a build of protokit and select a specific commit * Only depend on protolib when it is not build with norm * Revert "Only depend on protolib when it is not build with norm" This reverts commit 30e5dfab5372f7996efe28b420b86f0f7a9a1f87. * Revert "Revert "Only depend on protolib when it is not build with norm"" This reverts commit facc70ce29e52cbb85a1787d0ff0d438a6054879. * Adds policy to allow norm to set option * Updates git protokit git hash * Removes protokit as external dep * Updates git tag * Get git submodule target hash for fetch_content * Updates submodule * Adds way to specify custom protolib version (such as origin/master) * Adds option to build from local ./protolib folder * Makes logic somewhat nicer --- CMakeLists.txt | 56 +++++++++++++++++++++++++++++---------- cmake/normConfig.cmake.in | 5 +--- protolib | 2 +- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a65c3d9..58a95d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 3.11) - +cmake_policy(SET CMP0077 NEW) # set the project name project(norm VERSION 1.5.8) set(COMMON src/common) option(NORM_BUILD_EXAMPLES "Enables building of the examples in /examples." OFF) +set(NORM_CUSTOM_PROTOLIB_VERSION OFF CACHE STRING "Set a custom protolib version to use, ./protolib to use the local version") include(CheckCXXSymbolExists) check_cxx_symbol_exists(dirfd "dirent.h" HAVE_DIRFD) @@ -23,19 +24,45 @@ if(HAVE_FLOCK) list(APPEND PLATFORM_DEFINITIONS HAVE_FLOCK) endif() -# Check for libraries -find_package(protokit QUIET) - -if(NOT protokit_FOUND) - include(FetchContent) - FetchContent_Declare( - protokit - GIT_REPOSITORY https://github.com/USNavalResearchLaboratory/protolib.git - GIT_TAG origin/master - ) - FetchContent_MakeAvailable(protokit) +if(NOT NORM_CUSTOM_PROTOLIB_VERSION) + find_package(Git) + + if(Git_FOUND) + message("Git found: ${GIT_EXECUTABLE}") + execute_process( + COMMAND + ${GIT_EXECUTABLE} ls-tree HEAD + RESULT_VARIABLE + GIT_SUBMODULE_STATUS + OUTPUT_VARIABLE + GIT_SUBMODULE + WORKING_DIRECTORY + ${CMAKE_CURRENT_LIST_DIR} + ) + string(REGEX MATCH "commit[ \t\r\n]*([a-z0-9]+)[ \t\r\n]*protolib" GIT_SUBMODULE_HASH_MATCH ${GIT_SUBMODULE}) + if(GIT_SUBMODULE_HASH_MATCH) + set(NORM_PROTOKIT_GIT_TAG ${CMAKE_MATCH_1}) + endif() + endif() +elseif(NOT NORM_CUSTOM_PROTOLIB_VERSION STREQUAL "./protolib") + set(NORM_PROTOKIT_GIT_TAG ${NORM_CUSTOM_PROTOLIB_VERSION}) endif() +if(NORM_PROTOKIT_GIT_TAG) + message(STATUS "Building protokit from ${NORM_PROTOKIT_GIT_TAG}") + include(FetchContent) + FetchContent_Declare( + protokit + GIT_REPOSITORY https://github.com/USNavalResearchLaboratory/protolib.git + GIT_TAG ${NORM_PROTOKIT_GIT_TAG} + ) + FetchContent_MakeAvailable(protokit) +else() + message(STATUS "Building protokit from ${NORM_CUSTOM_PROTOLIB_VERSION}") + add_subdirectory(protolib) +endif() + + # List header files list(APPEND PUBLIC_HEADER_FILES include/galois.h @@ -87,14 +114,15 @@ include(GNUInstallDirs) # Setup target add_library(norm ${PLATFORM_SOURCE_FILES} ${COMMON_SOURCE_FILES} ${PUBLIC_HEADER_FILES}) -target_link_libraries(norm PRIVATE ${PLATFORM_LIBS} protokit::protokit) +target_link_libraries(norm PRIVATE protokit::protokit) +target_link_libraries(norm PUBLIC ${PLATFORM_LIBS}) target_compile_definitions(norm PUBLIC ${PLATFORM_DEFINITIONS}) target_compile_options(norm PUBLIC ${PLATFORM_FLAGS}) target_include_directories(norm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(norm PUBLIC $ $) # Install target -install( TARGETS norm EXPORT normTargets +install( TARGETS norm protokit EXPORT normTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/cmake/normConfig.cmake.in b/cmake/normConfig.cmake.in index a9f7552..af437d0 100644 --- a/cmake/normConfig.cmake.in +++ b/cmake/normConfig.cmake.in @@ -3,8 +3,5 @@ include(GNUInstallDirs) include(CMakeFindDependencyMacro) -# Same syntax as find_package -find_dependency(protokit REQUIRED) - # Add the targets file -include("${CMAKE_CURRENT_LIST_DIR}/normTargets.cmake") \ No newline at end of file +include("${CMAKE_CURRENT_LIST_DIR}/normTargets.cmake") diff --git a/protolib b/protolib index 3222371..4919751 160000 --- a/protolib +++ b/protolib @@ -1 +1 @@ -Subproject commit 32223710e0b8021bc027c1ad2248158d6550369b +Subproject commit 49197511df68e26176313a49cef9e39b3eda3134