Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake and vcpkg support #532

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,6 @@ GTAGS
/nel
/nev
/fes

# Build dirs
*build*
134 changes: 134 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
cmake_minimum_required(VERSION 3.11)

project(vere VERSION 2.1.2 LANGUAGES C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED OFF)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_CXX_EXTENSIONS ON)

add_library("${PROJECT_NAME}_compiler_flags" INTERFACE)

if (NOT DEFINED CMAKE_SYSTEM_NAME)
set(CMAKE_SYSTEM_NAME "${CMAKE_HOST_SYSTEM_NAME}")
endif (NOT DEFINED CMAKE_SYSTEM_NAME)

if (NOT DEFINED MSVC_VERSION
OR MSVC_VERSION STRGREATER "1900" # 2015
OR NOT (CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom"))
target_compile_features(
"${PROJECT_NAME}_compiler_flags"
INTERFACE
"c_std_${CMAKE_C_STANDARD}"
)
endif ()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15")
# add compiler warning flags just when building this project via
# the BUILD_INTERFACE genex
set(gcc_like "$<COMPILE_LANG_AND_ID:C,CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
set(msvc "$<COMPILE_LANG_AND_ID:C,CXX,MSVC>")
target_compile_options(
"${PROJECT_NAME}_compiler_flags"
INTERFACE
"$<${gcc_like}:$<BUILD_INTERFACE:-Wshadow;-Wformat=2;-Wall;-Wno-zero-length-array;-Wno-gnu-statement-expression-from-macro-expansion;-Wno-gnu-binary-literal;-Wno-gnu-label-as-value;-Wno-gnu-pointer-arith;-pedantic>>"
"$<${msvc}:$<BUILD_INTERFACE:-W3;-WX;-Zi;-permissive->>"
)
endif (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15")
# Set the build directories
if (CMAKE_SYSTEM_NAME STREQUAL "Windows"
OR CMAKE_SYSTEM_NAME STREQUAL "CYGWIN"
OR CMAKE_SYSTEM_NAME MATCHES "MINGW.*")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
else ()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
endif ()

if (CMAKE_GENERATOR MATCHES "Visual Studio 8 2005.*")
set(COMPILE_LANG_AND_ID "MSVC")
else ()
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)

target_compile_features("${PROJECT_NAME}_compiler_flags" INTERFACE "c_std_${CMAKE_C_STANDARD}")

# add compiler warning flags just when building this project via
# the BUILD_INTERFACE genex
set(gcc_like "$<COMPILE_LANG_AND_ID:C,CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
set(msvc "$<COMPILE_LANG_AND_ID:C,CXX,MSVC>")
target_compile_options(
"${PROJECT_NAME}_compiler_flags"
INTERFACE
"$<${gcc_like}:$<BUILD_INTERFACE:-Wshadow;-Wformat=2;-Wall;-pedantic>>"
"$<${msvc}:$<BUILD_INTERFACE:-W3;-WX;-Zi;-permissive->>"
)
endif ()

include(CheckSymbolExists)
check_symbol_exists(BCryptGenRandom "windows.h;bcrypt.h" HAVE_BCRYPT)

# configure a header file to pass the version number and exist flags only
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in"
"${PROJECT_NAME}Config.h"
)

#===============================================================================
# 4. ADD SUB-TARGETS
# Doing this at the end so that all definitions and link/include paths are
# available for the sub-projects.
#===============================================================================
add_subdirectory("pkg")

###########
# Install #
###########

include(GNUInstallDirs)

install(
FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
include(InstallRequiredSystemLibraries)
set(CPACK_BUNDLE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "urbit/vere maintainers")
set(CPACK_PACKAGE_DESCRIPTION "The lowest layer of the Urbit stack.")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
if (APPLE)
set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Info.plist")
set(CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Info.plist")
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CustomVolumeIcon.icns")
endif (APPLE)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "${${PROJECT_NAME}_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${${PROJECT_NAME}_VERSION_MINOR}")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/cmake/README.txt")
set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Welcome.txt")
set(CPACK_PACKAGE_CONTACT "https://github.com/urbit/${PROJECT_NAME}")

include(CPack)
include(CMakePackageConfigHelpers)

# generate the config file that is includes the exports
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

# generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}"
COMPATIBILITY AnyNewerVersion
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
Binary file added cmake/BundleIcon.icns
Binary file not shown.
7 changes: 7 additions & 0 deletions cmake/CTestConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CTEST_PROJECT_NAME "bc")
set(CTEST_NIGHTLY_START_TIME "00:00:00 EST")

set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_SITE "my.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=vere")
set(CTEST_DROP_SITE_CDASH TRUE)
4 changes: 4 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

@PACKAGE_INIT@

include ( "${CMAKE_CURRENT_LIST_DIR}/vereTargets.cmake" )
Binary file added cmake/CustomVolumeIcon.icns
Binary file not shown.
14 changes: 14 additions & 0 deletions cmake/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>BundleGeneratorTest</string>
<key>CFBundleIconFile</key>
<string>BundleGeneratorTest.icns</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
</dict>
</plist>
6 changes: 6 additions & 0 deletions cmake/MultiCPackConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include("release/CPackConfig.cmake")

set(CPACK_INSTALL_CMAKE_PROJECTS
"debug;vere;ALL;/"
"release;vere;ALL;/"
)
3 changes: 3 additions & 0 deletions cmake/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vere

The lowest layer of the Urbit stack.
1 change: 1 addition & 0 deletions cmake/Welcome.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This installs vere.
9 changes: 9 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef VERE_CONFIG_H
#define VERE_CONFIG_H

#define VERE_VERSION_MAJOR @vere_VERSION_MAJOR@
#define VERE_VERSION_MINOR @vere_VERSION_MINOR@
#define VERE_VERSION_PATCH @vere_VERSION_PATCH@
#define VERE_VERSION "@vere_VERSION@"

#endif /* !VERE_CONFIG_H */
33 changes: 33 additions & 0 deletions pkg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set(installable_libs "c3" "ent" "ur" "noun" "urcrypt" "vere")

foreach (pkg ${installable_libs})
add_subdirectory("${pkg}")
endforeach (pkg ${installable_libs})

list(APPEND installable_libs "ge-additions")

#########
# Tests #
#########

# TODO

#################
# Install rules #
#################

include(GNUInstallDirs)

if (TARGET "${DEPENDANT_LIBRARY}")
list(APPEND installable_libs "${DEPENDANT_LIBRARY}")
endif ()
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13")
list(APPEND installable_libs "${PROJECT_NAME}_compiler_flags")
endif ()
install(TARGETS ${installable_libs}
EXPORT "${LIBRARY_NAME}Targets"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(EXPORT "${LIBRARY_NAME}Targets"
DESTINATION "${CMAKE_INSTALL_DATADIR}/${LIBRARY_NAME}")
65 changes: 65 additions & 0 deletions pkg/c3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
get_filename_component(LIBRARY_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME)

set(Header_Files "c3.h" "defs.h" "motes.h" "portable.h" "types.h")
source_group("Header Files" FILES "${Header_Files}")

set(Source_Files "defs.c")
source_group("Source Files" FILES "${Source_Files}")

add_library("${LIBRARY_NAME}" "${Header_Files}" "${Source_Files}")

if (LINUX)
target_compile_definitions("${LIBRARY_NAME}" PUBLIC -DU3_OS_linux=1)
elseif (APPLE)
target_compile_definitions("${LIBRARY_NAME}" PUBLIC -DU3_OS_osx=1)
elseif (BSD)
target_compile_definitions("${LIBRARY_NAME}" PUBLIC -DU3_OS_bsd=1)
else ()
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} unsupported. Port it!")
endif ()

if (CMAKE_VERSION VERSION_LESS "3.20")
include(TestBigEndian)
test_big_endian(CMAKE_C_BYTE_ORDER)
endif ()
if (CMAKE_C_BYTE_ORDER EQUAL 1)
target_compile_definitions("${LIBRARY_NAME}" PUBLIC -DU3_OS_ENDIAN_big=1)
else ()
target_compile_definitions("${LIBRARY_NAME}" PUBLIC -DU3_OS_ENDIAN_little=1)
endif ()

include(GNUInstallDirs)

target_link_libraries(
"${LIBRARY_NAME}"
PRIVATE
"${PROJECT_NAME}_compiler_flags"
)

target_include_directories(
"${LIBRARY_NAME}"
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

target_include_directories(
"${LIBRARY_NAME}"
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

###########
# Install #
###########

set_property(TARGET "${LIBRARY_NAME}" PROPERTY VERSION "${${PROJECT_NAME}_VERSION}")
set_property(TARGET "${LIBRARY_NAME}" PROPERTY SOVERSION "${${PROJECT_NAME}_VERSION_MAJOR}")

include(GenerateExportHeader)
set(_export_file "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}_export.h")
generate_export_header("${LIBRARY_NAME}" EXPORT_FILE_NAME "${_export_file}")

install(FILES ${Header_Files} "${_export_file}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
54 changes: 54 additions & 0 deletions pkg/ent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
get_filename_component(LIBRARY_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME)

set(Header_Files "ent.h")
source_group("Header Files" FILES "${Header_Files}")

set(Source_Files "ent.c")
source_group("Source Files" FILES "${Source_Files}")

# TODO: `add_test` for tests.c

add_library("${LIBRARY_NAME}" "${Header_Files}" "${Source_Files}")

if (DEFINED ENT_GETENTROPY_BCRYPTGENRANDOM)
target_compile_definitions("${LIBRARY_NAME}" PRIVATE ENT_GETENTROPY_BCRYPTGENRANDOM=1)
elseif (DEFINED ENT_DEV_URANDOM)
target_compile_definitions("${LIBRARY_NAME}" PRIVATE ENT_DEV_URANDOM=1)
elseif (DEFINED ENT_GETENTROPY_UNISTD)
target_compile_definitions("${LIBRARY_NAME}" PRIVATE ENT_GETENTROPY_UNISTD=1)
elseif (DEFINED ENT_GETENTROPY_SYSRANDOM)
target_compile_definitions("${LIBRARY_NAME}" PRIVATE ENT_GETENTROPY_SYSRANDOM=1)
elseif (DEFINED ENT_GETRANDOM_SYSCALL)
target_compile_definitions("${LIBRARY_NAME}" PRIVATE ENT_GETRANDOM_SYSCALL=1)
else ()
message(FATAL_ERROR "One of these must be set: ENT_GETENTROPY_BCRYPTGENRANDOM, ENT_DEV_URANDOM, ENT_GETENTROPY_UNISTD, ENT_GETENTROPY_SYSRANDOM, ENT_GETRANDOM_SYSCALL")
endif ()

include(GNUInstallDirs)

target_link_libraries(
"${LIBRARY_NAME}"
PRIVATE
"${PROJECT_NAME}_compiler_flags"
)

target_include_directories(
"${LIBRARY_NAME}"
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

###########
# Install #
###########

set_property(TARGET "${LIBRARY_NAME}" PROPERTY VERSION "${${PROJECT_NAME}_VERSION}")
set_property(TARGET "${LIBRARY_NAME}" PROPERTY SOVERSION "${${PROJECT_NAME}_VERSION_MAJOR}")

include(GenerateExportHeader)
set(_export_file "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}_export.h")
generate_export_header("${LIBRARY_NAME}" EXPORT_FILE_NAME "${_export_file}")

install(FILES ${Header_Files} "${_export_file}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
Loading