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 30e5dfab53.

* Revert "Revert "Only depend on protolib when it is not build with norm""

This reverts commit facc70ce29.

* 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
pull/18/head
mjvankampen 2021-01-18 16:26:06 +01:00 committed by GitHub
parent 6444f236b8
commit 1008f83092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 19 deletions

View File

@ -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 NORM_CUSTOM_PROTOLIB_VERSION)
find_package(Git)
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(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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
# 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}

View File

@ -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")

@ -1 +1 @@
Subproject commit 32223710e0b8021bc027c1ad2248158d6550369b
Subproject commit 49197511df68e26176313a49cef9e39b3eda3134