![Alexandre Bouvier](/assets/img/avatar_default.png)
1401fb85 Fix `a label can only be part of a statement` warning (#61) 5f650a18 CMake: Enable `CMAKE_MSVC_RUNTIME_LIBRARY` (MSVC) 6c958cfe Fix no-libc build on "other" platforms (#58) 59819206 Bump version to v1.4.0 4bc563f6 Fix build-system to better work with vcpkg (#56) 4a8b5e2a CMake: rename target `doc` -> `ZycoreDoc` a754e112 Bump version to 1.3.0 3e95307d Add support for ppc(64) and riscv64 (#52) 8f39333a build: only enable CXX if needed 7bd75696 build: add doc target 7c33e13e Fix `ZYAN_TRUE`/`ZYAN_FALSE` signedness a0feec7f Fix warning `C4668` bdbd3ff4 Bump version to v1.2 60b6ef1c Fix for dynamic libraries too 310f362c Adding ARCHIVE DESTINATION to fix CMake error b01063b8 Improved logic for enabling LTO c58d7fb5 Don't enable C11 for MSVC ee784564 Switch minimum C standard supported to C11 5c341bf1 Implement an initial set of cross-compiler atomic operations b4949ccc Minor fixes 9a305f6a Add CI workflow dd2211a0 Get rid of CMake export headers f0fb3f78 Fix `ZYAN_VECTOR_FOREACH_MUTABLE` macro 3f263290 format: handle encoding on wasm 95d7fb6c format: handle hex encoding on wasm 0d37fc54 defines: add wasm/wasi detection 8983325b build: use -pthread when possible 3de49d41 build: use system GTest when available 8d46cb58 test: make tests runnable with ctest 636bb299 Remove `float`s from the project (kernel mode compatibility) (#36) e2b37b10 Assert to ensure sane growth factors 94185407 Added limits for integer types 767719d9 build(cmake): export and install zyan_* functions (#33) 6c93d9a3 build(cmake): add version and soversion to the library fc2798d4 build(cmake): fix PUBLIC include dir of installed lib 22ce9c2d Add `ZYAN_FORCE_ASSERTS` CMake option 9a301424 Remove disabling source files in no-libc mode in CMake 3be54fca Thread.c: add missing SDK prototypes for old versions of Windows d7fc85fd Exclude API/Memory.c and API/Process.c from compilation in no-libc mode 8da0001a Add back #ifdef guards to "API" headers/sources for no-libc mode f6a48866 Fix cmake config files (#27) 4f3746fa Merge pull request #26 from Tsn0w/master a9bb54ad Replace fallthrough attribute to __fallthrough__ 99a74acb Add `ZYDIS_NOINLINE` macro git-subtree-dir: externals/zycore git-subtree-split: 1401fb85ac313f6605ec795c52bf99ea3f292a69
294 lines
11 KiB
CMake
294 lines
11 KiB
CMake
if (TARGET Zycore)
|
|
return()
|
|
endif ()
|
|
|
|
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
|
|
|
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15")
|
|
# Enable runtime library selection via CMAKE_MSVC_RUNTIME_LIBRARY
|
|
cmake_policy(SET CMP0091 NEW)
|
|
endif ()
|
|
|
|
project(Zycore VERSION 1.4.0.0 LANGUAGES C)
|
|
|
|
include(GNUInstallDirs)
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
# =============================================================================================== #
|
|
# Overridable options #
|
|
# =============================================================================================== #
|
|
|
|
# Global configuration
|
|
option(ZYAN_WHOLE_PROGRAM_OPTIMIZATION
|
|
"Enable whole program optimization (all targets)"
|
|
OFF)
|
|
option(ZYAN_NO_LIBC
|
|
"Don't use any C standard library functions (for exotic build-envs like kernel drivers)"
|
|
OFF)
|
|
option(ZYAN_DEV_MODE
|
|
"Enable developer mode (-Wall, -Werror, ...)"
|
|
OFF)
|
|
option(ZYAN_FORCE_ASSERTS
|
|
"Forces asserts in release builds."
|
|
OFF)
|
|
|
|
# Build configuration
|
|
option(ZYCORE_BUILD_SHARED_LIB
|
|
"Build shared library"
|
|
OFF)
|
|
option(ZYCORE_BUILD_EXAMPLES
|
|
"Build examples"
|
|
OFF)
|
|
option(ZYCORE_BUILD_TESTS
|
|
"Build tests"
|
|
OFF)
|
|
|
|
# =============================================================================================== #
|
|
# Forced assertions hack #
|
|
# =============================================================================================== #
|
|
|
|
# The code for this is adapted from how LLVM forces asserts.
|
|
if (ZYAN_FORCE_ASSERTS)
|
|
set(vars
|
|
CMAKE_CXX_FLAGS_RELEASE
|
|
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
|
CMAKE_CXX_FLAGS_MINSIZEREL
|
|
CMAKE_C_FLAGS_RELEASE
|
|
CMAKE_C_FLAGS_RELWITHDEBINFO
|
|
CMAKE_C_FLAGS_MINSIZEREL)
|
|
|
|
foreach (var ${vars})
|
|
string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " "${var}" "${${var}}")
|
|
set("${var}" "${${var}} -UNDEBUG" CACHE STRING "" FORCE)
|
|
endforeach()
|
|
endif ()
|
|
|
|
# =============================================================================================== #
|
|
# GoogleTest #
|
|
# =============================================================================================== #
|
|
|
|
# Search for GoogleTest, and fallback to downloading it if not found
|
|
if (ZYCORE_BUILD_TESTS)
|
|
find_package(GTest QUIET)
|
|
if (GTest_FOUND)
|
|
# CMake 3.20 and upstream GTestConfig.cmake
|
|
if (TARGET GTest::gtest)
|
|
add_library(gtest ALIAS GTest::gtest)
|
|
# Older FindGTest
|
|
else ()
|
|
add_library(gtest ALIAS GTest::GTest)
|
|
endif ()
|
|
else ()
|
|
if (NOT DEFINED ZYCORE_DOWNLOADED_GTEST)
|
|
configure_file("CMakeLists.txt.in" "${CMAKE_BINARY_DIR}/gtest/download/CMakeLists.txt")
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
|
RESULT_VARIABLE result
|
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/gtest/download")
|
|
if (result)
|
|
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
|
endif()
|
|
execute_process(COMMAND ${CMAKE_COMMAND} --build .
|
|
RESULT_VARIABLE result
|
|
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/gtest/download")
|
|
if (result)
|
|
message(FATAL_ERROR "Build step for googletest failed: ${result}")
|
|
endif()
|
|
|
|
set(ZYCORE_DOWNLOADED_GTEST TRUE CACHE BOOL "")
|
|
mark_as_advanced(ZYCORE_DOWNLOADED_GTEST)
|
|
endif ()
|
|
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
|
|
add_subdirectory("${CMAKE_BINARY_DIR}/gtest/src" "${CMAKE_BINARY_DIR}/gtest/build"
|
|
EXCLUDE_FROM_ALL)
|
|
endif ()
|
|
endif ()
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
include(zyan-functions)
|
|
|
|
# =============================================================================================== #
|
|
# Library configuration #
|
|
# =============================================================================================== #
|
|
|
|
if (ZYCORE_BUILD_SHARED_LIB)
|
|
add_library("Zycore" SHARED)
|
|
else ()
|
|
add_library("Zycore" STATIC)
|
|
target_compile_definitions("Zycore" PUBLIC "ZYCORE_STATIC_BUILD")
|
|
endif ()
|
|
|
|
set_target_properties("Zycore" PROPERTIES
|
|
LINKER_LANGUAGE C
|
|
VERSION "${Zycore_VERSION}"
|
|
SOVERSION "${Zycore_VERSION_MAJOR}.${Zycore_VERSION_MINOR}"
|
|
DEFINE_SYMBOL "ZYCORE_SHOULD_EXPORT")
|
|
target_include_directories("Zycore"
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
PRIVATE "src")
|
|
target_compile_definitions("Zycore" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
|
zyan_set_common_flags("Zycore")
|
|
zyan_maybe_enable_wpo("Zycore")
|
|
|
|
if (ZYAN_NO_LIBC)
|
|
target_compile_definitions("Zycore" PUBLIC "ZYAN_NO_LIBC")
|
|
if (UNIX)
|
|
set_target_properties("Zycore" PROPERTIES LINK_FLAGS "-nostdlib -nodefaultlibs")
|
|
endif ()
|
|
endif ()
|
|
|
|
target_sources("Zycore"
|
|
PRIVATE
|
|
# API
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/API/Memory.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/API/Process.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/API/Synchronization.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/API/Terminal.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/API/Thread.h"
|
|
# Common
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Allocator.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/ArgParse.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Atomic.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Bitset.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Comparison.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Defines.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Format.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/LibC.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/List.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Object.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Status.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/String.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Types.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Vector.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Zycore.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Internal/AtomicGNU.h"
|
|
"${CMAKE_CURRENT_LIST_DIR}/include/Zycore/Internal/AtomicMSVC.h"
|
|
# API
|
|
"src/API/Memory.c"
|
|
"src/API/Process.c"
|
|
"src/API/Synchronization.c"
|
|
"src/API/Terminal.c"
|
|
"src/API/Thread.c"
|
|
# Common
|
|
"src/Allocator.c"
|
|
"src/ArgParse.c"
|
|
"src/Bitset.c"
|
|
"src/Format.c"
|
|
"src/List.c"
|
|
"src/String.c"
|
|
"src/Vector.c"
|
|
"src/Zycore.c")
|
|
|
|
if (ZYCORE_BUILD_SHARED_LIB AND WIN32)
|
|
target_sources("Zycore" PRIVATE "resources/VersionInfo.rc")
|
|
endif ()
|
|
|
|
zyan_set_source_group("Zycore")
|
|
|
|
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT ZYAN_NO_LIBC)
|
|
target_compile_definitions("Zycore" PRIVATE "_GNU_SOURCE")
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
find_package(Threads REQUIRED)
|
|
target_link_libraries("Zycore" Threads::Threads)
|
|
endif ()
|
|
|
|
configure_package_config_file(cmake/zycore-config.cmake.in
|
|
"${CMAKE_CURRENT_BINARY_DIR}/zycore-config.cmake"
|
|
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/zycore"
|
|
)
|
|
write_basic_package_version_file(
|
|
"${CMAKE_CURRENT_BINARY_DIR}/zycore-config-version.cmake"
|
|
COMPATIBILITY SameMajorVersion
|
|
)
|
|
install(FILES
|
|
"cmake/zyan-functions.cmake"
|
|
"${CMAKE_CURRENT_BINARY_DIR}/zycore-config.cmake"
|
|
"${CMAKE_CURRENT_BINARY_DIR}/zycore-config-version.cmake"
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/zycore"
|
|
)
|
|
|
|
install(TARGETS "Zycore" EXPORT "zycore-targets"
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
)
|
|
|
|
install(EXPORT "zycore-targets"
|
|
NAMESPACE "Zycore::"
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/zycore")
|
|
install(DIRECTORY "include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
# =============================================================================================== #
|
|
# Doxygen documentation #
|
|
# =============================================================================================== #
|
|
|
|
find_package(Doxygen)
|
|
if (DOXYGEN_FOUND)
|
|
doxygen_add_docs(ZycoreDoc "include/Zycore/" ALL)
|
|
install(
|
|
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/"
|
|
DESTINATION "${CMAKE_INSTALL_DOCDIR}/api"
|
|
COMPONENT Documentation
|
|
)
|
|
endif()
|
|
|
|
# =============================================================================================== #
|
|
# Developer mode #
|
|
# =============================================================================================== #
|
|
|
|
if (ZYAN_DEV_MODE)
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
endif ()
|
|
|
|
# =============================================================================================== #
|
|
# Examples #
|
|
# =============================================================================================== #
|
|
|
|
if (ZYCORE_BUILD_EXAMPLES)
|
|
add_executable("String" "examples/String.c")
|
|
zyan_set_common_flags("String" "Zycore")
|
|
target_link_libraries("String" "Zycore")
|
|
set_target_properties("String" PROPERTIES FOLDER "Examples")
|
|
target_compile_definitions("String" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
|
zyan_maybe_enable_wpo("String")
|
|
|
|
add_executable("Vector" "examples/Vector.c")
|
|
zyan_set_common_flags("Vector" "Zycore")
|
|
target_link_libraries("Vector" "Zycore")
|
|
set_target_properties("Vector" PROPERTIES FOLDER "Examples")
|
|
target_compile_definitions("Vector" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
|
zyan_maybe_enable_wpo("Vector")
|
|
endif ()
|
|
|
|
# =============================================================================================== #
|
|
# Tests #
|
|
# =============================================================================================== #
|
|
|
|
function (zyan_add_test test)
|
|
add_executable("Test${test}" "tests/${test}.cpp")
|
|
target_link_libraries("Test${test}" "Zycore" "gtest")
|
|
set_target_properties("Test${test}" PROPERTIES
|
|
LANGUAGE CXX
|
|
CXX_STANDARD 17
|
|
CXX_EXTENSIONS OFF
|
|
CXX_STANDARD_REQUIRED ON
|
|
FOLDER "Tests"
|
|
)
|
|
target_compile_definitions("Test${test}" PRIVATE "_CRT_SECURE_NO_WARNINGS")
|
|
zyan_maybe_enable_wpo("Test${test}")
|
|
add_test("${test}" "Test${test}")
|
|
endfunction ()
|
|
|
|
if (ZYCORE_BUILD_TESTS)
|
|
enable_language(CXX)
|
|
enable_testing()
|
|
zyan_add_test("String")
|
|
zyan_add_test("Vector")
|
|
zyan_add_test("ArgParse")
|
|
endif ()
|
|
|
|
# =============================================================================================== #
|