Skip to content

Commit

Permalink
Feature/first working issue (#1)
Browse files Browse the repository at this point in the history
first working issue
set up basic presets for library developers to use
  • Loading branch information
doocman authored Aug 3, 2023
1 parent b55b13e commit e954cd7
Show file tree
Hide file tree
Showing 17 changed files with 848 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@
*.exe
*.out
*.app

# IDE-specifics
.idea

# common build out-folders:
out-*
cmake-build-*
build

CMakeUserPresets.json
77 changes: 77 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

cmake_minimum_required(VERSION 3.22...3.25)

project(DynamicLoad LANGUAGES CXX)

set(DYNLOAD_DEVELOP OFF CACHE BOOL "Turn ON during library development to get proper compiler warnings and testing")
set(DYNLOAD_USE_EXCEPTIONS ON CACHE BOOL "Standard C++ uses exceptions, thus, this is enabled by default. Turn off if no exceptions are allowed.")
set(DYNLOAD_IMPORT ON CACHE BOOL "Set to true if needing importing part of DYNLOAD")
set(DYNLOAD_EXPORT ON CACHE BOOL "Set to true if needing exporting part of DYNLOAD")
set(DYNLOAD_COMPILE_PLATFORM ON CACHE BOOL "If true, dynl will be automatically compiled for the target platform. Set to false if custom backend is needed.")

add_library(dynl_compile_opts INTERFACE)
add_library(dynl::compile_opts ALIAS dynl_compile_opts)
target_compile_options(dynl_compile_opts INTERFACE ${DYNL_COMPILE_FLAGS})

set(DYNLOAD_DEV_LINK dynl_compile_opts)
if (DYNLOAD_DEVELOP)
set(CMAKE_CXX_STANDARD 11)
enable_testing()
include(use_google_test.cmake)
add_subdirectory(tests)
endif ()

if (DYNLOAD_IMPORT)
add_library(dynl_headers INTERFACE)
add_library(dynl::dynl_headers ALIAS dynl_headers)
target_include_directories(dynl_headers INTERFACE
include
)
target_compile_features(dynl_headers INTERFACE cxx_std_20)

add_library(dynl_shared)
add_library(dynl::dynl_shared ALIAS dynl_shared)
target_link_libraries(dynl_shared PUBLIC
dynl::dynl_headers
${DYNLOAD_DEV_LINK}
)
target_sources(dynl_shared PRIVATE
src/dynl_shared.cpp
)
if (DYNLOAD_USE_EXCEPTIONS)
else ()
target_compile_definitions(dynl_shared PRIVATE
"DYNLOAD_NO_EXCEPTIONS=1"
)
endif ()


add_library(dynl)
add_library(dynl::dynl ALIAS dynl)
target_link_libraries(dynl PUBLIC
dynl::dynl_shared
${DYNLOAD_DEV_LINK}
)
if (DYNLOAD_COMPILE_PLATFORM)
if (WIN32)
target_sources(dynl PRIVATE
src/dynl_win32.cpp
)
elseif (UNIX)
target_sources(dynl PRIVATE
src/dynl_unix.cpp
)
else ()
message(SEND_ERROR "Dynload: no automatic backend available! Use custom defined source file")
endif ()
else ()
message(STATUS "Dynload: no automatic backend. Custom defined source-file(-s) for 'dynl' required")
endif ()
endif ()
if (DYNLOAD_EXPORT)
add_library(dynl_export INTERFACE)
add_library(dynl::dynl_export ALIAS dynl_export)
target_include_directories(dynl_export INTERFACE
export_include
)
endif ()
139 changes: 139 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 22,
"patch": 0
},
"configurePresets": [
{
"name": "dynl-dev",
"hidden": true,
"cacheVariables": {
"DYNLOAD_DEVELOP": true
}
},
{
"name": "msvc-warnings",
"hidden": true,
"cacheVariables": {
"DYNL_COMPILE_FLAGS": "/W4;/w14242;/w14254;/w14263;/w14265;/w14287;/we4289;/w14296;/w14311;/w14545;/w14546;/w14547;/w14549;/w14555;/w14619;/w14640;/w14826;/w14905;/w14906;/w14928;/permissive-;/wd4265"
}
},
{
"name": "clang-warnings",
"hidden": true,
"cacheVariables": {
"DYNL_COMPILE_FLAGS": "-Wall;-Wextra;-Wpedantic;-Wno-unknown-attributes"
}
},
{
"name": "gcc-warnings",
"hidden": true,
"cacheVariables": {
"DYNL_COMPILE_FLAGS": "-Wall;-Wextra;-Wpedantic"
}
},
{
"name": "windows-test-include",
"hidden": true,
"cacheVariables": {
"DYNLOAD_TEST_EXPORTS": "${sourceDir}/build/clang-release/tests/cross_tests/dynload.tests.cross_tests.export_this.dll;${sourceDir}/build/msvc22-debug/tests/cross_tests/dynload.tests.cross_tests.export_this.dll;${sourceDir}/build/msvc22-relwithdebinfo/tests/cross_tests/dynload.tests.cross_tests.export_this.dll"
}
},
{
"name": "linux-test-include",
"hidden": true,
"cacheVariables": {
"DYNLOAD_TEST_EXPORTS": "${sourceDir}/build/clang-release/tests/cross_tests/libdynload.tests.cross_tests.export_this.so;${sourceDir}/build/gcc-release/tests/cross_tests/libdynload.tests.cross_tests.export_this.so"
}
},
{
"name": "msvc-base",
"hidden": true,
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"inherits": ["msvc-warnings", "dynl-dev", "windows-test-include"],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_C_COMPILER": "cl"
},
"generator": "Ninja"
},
{
"name": "clang-base",
"hidden": true,
"inherits": ["clang-warnings", "dynl-dev"],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_C_COMPILER": "clang"
},
"generator": "Ninja"
},
{
"name": "gcc-base",
"hidden": true,
"inherits": ["gcc-warnings", "dynl-dev", "linux-test-include"],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_C_COMPILER": "gcc"
},
"generator": "Ninja"
},
{
"name": "crosscompile-base",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
},
"generator": "Ninja"
},
{
"name": "msvc22-debug",
"binaryDir": "${sourceDir}/build/msvc22-debug",
"inherits": [
"msvc-base"
],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"installDir": "${sourceDir}/install/msvc22-debug"
},
{
"name": "msvc22-reldeb",
"binaryDir": "${sourceDir}/build/msvc22-relwithdebinfo",
"inherits": [
"msvc-base"
],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
},
"installDir": "${sourceDir}/install/msvc22-relwithdebinfo"
},
{
"name": "clang-release",
"inherits": [
"clang-base"
],
"binaryDir": "${sourceDir}/build/clang-release",
"installDir": "${sourceDir}/install/clang-release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "gcc-release",
"inherits": [
"gcc-base"
],
"binaryDir": "${sourceDir}/build/gcc-release",
"installDir": "${sourceDir}/install/gcc-release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
]
}
4 changes: 4 additions & 0 deletions _clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

BasedOnStyle: LLVM
IndentRequires: true

17 changes: 17 additions & 0 deletions export_include/dynl/dynl_export.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Created by rvons on 2023-06-26.
//

#ifndef DYNAMICLOAD_DYNL_EXPORT_HPP
#define DYNAMICLOAD_DYNL_EXPORT_HPP

#ifdef _MSC_VER
#define DYNL_DECLATTR(X) __declspec(X)
#define DYNLOAD_EXPORT __declspec(dllexport)
#else
#define DYNL_DECLATTR(X) __attribute__((X))
#define DYNLOAD_EXPORT extern
#endif


#endif // DYNAMICLOAD_DYNL_EXPORT_HPP
Loading

0 comments on commit e954cd7

Please sign in to comment.