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_minimum_required(VERSION 3.11)
cmake_policy(SET CMP0077 NEW)
# set the project name # set the project name
project(norm VERSION 1.5.8) project(norm VERSION 1.5.8)
set(COMMON src/common) set(COMMON src/common)
option(NORM_BUILD_EXAMPLES "Enables building of the examples in /examples." OFF) 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) include(CheckCXXSymbolExists)
check_cxx_symbol_exists(dirfd "dirent.h" HAVE_DIRFD) check_cxx_symbol_exists(dirfd "dirent.h" HAVE_DIRFD)
@ -23,19 +24,45 @@ if(HAVE_FLOCK)
list(APPEND PLATFORM_DEFINITIONS HAVE_FLOCK) list(APPEND PLATFORM_DEFINITIONS HAVE_FLOCK)
endif() endif()
# Check for libraries if(NOT NORM_CUSTOM_PROTOLIB_VERSION)
find_package(protokit QUIET) find_package(Git)
if(NOT protokit_FOUND) if(Git_FOUND)
include(FetchContent) message("Git found: ${GIT_EXECUTABLE}")
FetchContent_Declare( execute_process(
protokit COMMAND
GIT_REPOSITORY https://github.com/USNavalResearchLaboratory/protolib.git ${GIT_EXECUTABLE} ls-tree HEAD
GIT_TAG origin/master RESULT_VARIABLE
) GIT_SUBMODULE_STATUS
FetchContent_MakeAvailable(protokit) 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() 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 header files
list(APPEND PUBLIC_HEADER_FILES list(APPEND PUBLIC_HEADER_FILES
include/galois.h include/galois.h
@ -87,14 +114,15 @@ include(GNUInstallDirs)
# Setup target # Setup target
add_library(norm ${PLATFORM_SOURCE_FILES} ${COMMON_SOURCE_FILES} ${PUBLIC_HEADER_FILES}) 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_definitions(norm PUBLIC ${PLATFORM_DEFINITIONS})
target_compile_options(norm PUBLIC ${PLATFORM_FLAGS}) target_compile_options(norm PUBLIC ${PLATFORM_FLAGS})
target_include_directories(norm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(norm PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(norm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>) target_include_directories(norm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
# Install target # Install target
install( TARGETS norm EXPORT normTargets install( TARGETS norm protokit EXPORT normTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

View File

@ -3,8 +3,5 @@ include(GNUInstallDirs)
include(CMakeFindDependencyMacro) include(CMakeFindDependencyMacro)
# Same syntax as find_package
find_dependency(protokit REQUIRED)
# Add the targets file # Add the targets file
include("${CMAKE_CURRENT_LIST_DIR}/normTargets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/normTargets.cmake")

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