Skip to content

Commit

Permalink
🔨 asdhjsahd DO NOT BUILD
Browse files Browse the repository at this point in the history
- Add a flag to allow size_t(-1) and similar shenanigans (SOL_ALL_INTEGER_VALUES_FIT)
- Half-fix, but not fully, for #1183, #1072, #1038, #965
- Fix #1126
- Prepare for #1061
  • Loading branch information
ThePhD committed May 6, 2021
1 parent f56b3c6 commit 7aae1aa
Show file tree
Hide file tree
Showing 116 changed files with 2,127 additions and 925 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Mac OSX
name: Mac OS

on: [push]

Expand Down
51 changes: 6 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@

# # # # sol2
# # # Required minimum version statement
cmake_minimum_required(VERSION 3.15.0)
cmake_minimum_required(VERSION 3.16.0)
# # # Project Include - file that is included after project declaration is finished
set(CMAKE_PROJECT_INCLUDE "${CMAKE_SOURCE_DIR}/cmake/Includes/Project.cmake")

# # # project declaration
project(sol2 VERSION 4.0.0 LANGUAGES CXX C)

# # # Modules
# # Include modules useful to the project, whether locally made in our own cmake DIRECTORY
# # our from the standard cmake libraries
# Add home-rolled modules path to front of module path list
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" "${CMAKE_MODULE_PATH}")

if (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(SOL2_IS_TOP_LEVEL TRUE)
message(STATUS "sol2 is the top-level directory...")
Expand Down Expand Up @@ -78,23 +74,8 @@ CMAKE_DEPENDENT_OPTION(BUILD_LUA_AS_DLL "Build Lua as a DLL" ON
"SOL2_BUILD_LUA" OFF)


# # # Platform
# Detect x86 and x64 stuff
if (SOL2_PLATFORM MATCHES "i686" OR SOL2_PLATFORM STREQUAL "x86")
set(SOL2_IS_X86 TRUE)
elseif (SOL2_PLATFORM MATCHES "ARM64")
set(IS_ARM64 TRUE)
set(IS_X64 TRUE)
elseif (SOL2_PLATFORM MATCHES "ARM")
set(IS_ARM TRUE)
elseif (SOL2_PLATFORM MATCHES "x86_64" OR SOL2_PLATFORM STREQUAL "x64")
set(IS_X64 TRUE)
else()
set(IS_X64 TRUE)
endif()

if (SOL2_SYSTEM_INCLUDE)
set(--sol2-system-include SYSTEM)
set(sol2-system-include SYSTEM)
endif()

# # # sol2 Source Groups
Expand All @@ -112,7 +93,7 @@ set_target_properties(sol2
PROPERTIES
EXPORT_NAME sol2::sol2)

target_include_directories(sol2 ${--sol2-system-include} INTERFACE
target_include_directories(sol2 ${sol2-system-include} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

Expand Down Expand Up @@ -191,7 +172,7 @@ endif()
# # # Tests, Examples and other CI suites that come with sol2
if (SOL2_IS_TOP_LEVEL AND (SOL2_DO_TESTS OR SOL2_DO_EXAMPLES))
# # # General project output locations
if (SOL2_IS_X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4)
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/bin")
Expand All @@ -204,26 +185,6 @@ if (SOL2_IS_TOP_LEVEL AND (SOL2_DO_TESTS OR SOL2_DO_EXAMPLES))
# # # Libraries
# Here, we pull in all the necessary libraries for building examples and tests
# Find threading library
if (NOT MSVC)
if (SOL2_IS_X86)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
set(CMAKE_EXECUTABLE_LINKER_FLAGS "${CMAKE_EXECUTABLE_LINKER_FLAGS} -m32")
endif()
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
else()
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
if (BUILD_LUA_AS_DLL)
string(REGEX REPLACE "/MT" "/MD" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REGEX REPLACE "/MT" "/MD" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
else ()
string(REGEX REPLACE "/MD" "/MT" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
endif()
find_package(Threads REQUIRED)

string(TOLOWER ${SOL2_LUA_VERSION} NORMALIZED_LUA_VERSION)
Expand Down
77 changes: 77 additions & 0 deletions cmake/Includes/Project.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2021 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# # # # sol2 - cmake - basic project configuration

include_guard(DIRECTORY)

list(PREPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Packages")
list(PREPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MESSAGE_CONTEXT "${PROJECT_NAME}")

# # Standard Project version
if (NOT CMAKE_CXX_STANDARD GREATER_EQUAL 17)
set(CMAKE_CXX_STANDARD 17)
endif()

if (NOT CMAKE_C_STANDARD GREATER_EQUAL 11)
set(CMAKE_C_STANDARD 11)
endif()

# # CMake and sol2 Includes
# CMake
include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)
include(CheckIPOSupported)
include(CMakeDependentOption)
include(CMakePrintHelpers)
include(GNUInstallDirs)
include(FeatureSummary)
include(FetchContent)
include(CTest)
# sol2
include(CheckCompilerDiagnostic)
include(CheckCompilerFlag)
include(FindVersion)

# # Check environment/prepare generator expressions
# Basic/Normal flags
check_compiler_flag(disable-permissive MSVC /permissive- GCC -pedantic)
check_compiler_flag(utf8-literal-encoding MSVC /execution-charset:utf-8 GCC -fexec-charset=utf-8)
check_compiler_flag(utf8-source-encoding MSVC /source-charset:utf-8 GCC -finput-charset=utf-8)
check_compiler_flag(extra-constexpr-depth MSVC /constexpr:depth2147483647 GCC -fconstexpr-depth=2147483647 CLANG -fconstexpr-depth=2147483647)
check_compiler_flag(extra-constexpr-steps MSVC /constexpr:steps2147483647 GCC -fconstexpr-ops-limit=2147483647 CLANG -fconstexpr-steps=2147483647)
check_compiler_flag(template-debugging-mode GCC -ftemplate-backtrace-limit=0)
check_compiler_flag(big-obj MSVC /bigobj)
# Overall warning flags
check_compiler_flag(pedantic GCC -pedantic)
check_compiler_flag(warn-pedantic GCC -Wpedantic)
check_compiler_flag(warn-all MSVC /W4 GCC -Wall)
check_compiler_flag(warn-extra GCC -Wextra)
check_compiler_flag(warn-errors MSVC /WX GCC -Werror)
# Individual warnings/errors
check_compiler_diagnostic(unknown-warning)
check_compiler_diagnostic(unknown-warning-option)
check_compiler_diagnostic(microsoft-cast)
check_compiler_diagnostic(noexcept-type)
check_compiler_diagnostic(unreachable-code MSVC 4702)
93 changes: 93 additions & 0 deletions cmake/Modules/CheckCompilerDiagnostic.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2021 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# # # # sol2 - cmake - compiler diagnostic checking

include_guard(GLOBAL)

include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)

#[[
Given a diagnostic name and flag, like
check_cxx_compiler_diagnostic(pig MSVC 1312)
or
check_cxx_compiler_diagnostic(pig GCC acab)
we check if the given flag works C++ compiler. If it does, we then generate
a --warn, --allow, --deny, and --forbid prefixed set of variables. Users are
then free to simply apply them to targets at will.
]]
function (check_compiler_diagnostic diagnostic)
cmake_parse_arguments(diagnostic "" "GCC;MSVC;CLANG" "" ${ARGN})
if (NOT diagnostic_GCC)
set(diagnostic_GCC ${diagnostic})
endif()
if (NOT diagnostic_MSVC)
set(diagnostic_MSVC ${diagnostic})
endif()
if (NOT diagnostic_CLANG)
set(diagnostic_CLANG ${diagnostic_GCC})
endif()
string(MAKE_C_IDENTIFIER "${diagnostic}" suffix)
string(TOUPPER "${suffix}" suffix)
get_property(enabled-languages GLOBAL PROPERTY ENABLED_LANGUAGES)
if (CXX IN_LIST enabled-languages)
if (MSVC)
check_cxx_compiler_flag(-wo${diagnostic_MSVC} CXX_DIAGNOSTIC_${suffix})
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
check_cxx_compiler_flag(-W${diagnostic_CLANG} CXX_DIAGNOSTIC_${suffix})
else()
check_cxx_compiler_flag(-W${diagnostic_GCC} CXX_DIAGNOSTIC_${suffix})
endif()
endif()
if (C IN_LIST enabled-languages)
if (MSVC)
check_c_compiler_flag(-wo${diagnostic_MSVC} C_DIAGNOSTIC_${suffix})
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
check_c_compiler_flag(-W${diagnostic_CLANG} C_DIAGNOSTIC_${suffix})
else()
check_c_compiler_flag(-W${diagnostic_GCC} C_DIAGNOSTIC_${suffix})
endif()
endif()
string(CONCAT when $<OR:
$<AND:$<BOOL:${CXX_DIAGNOSTIC_${suffix}}>,$<COMPILE_LANGUAGE:CXX>>,
$<AND:$<BOOL:${C_DIAGNOSTIC_${suffix}}>,$<COMPILE_LANGUAGE:C>>
>)
string(CONCAT diagnostic_flag
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:${diagnostic_MSVC}>
$<$<COMPILE_LANG_AND_ID:C,MSVC>:${diagnostic_MSVC}>
$<$<COMPILE_LANG_AND_ID:CXX,GCC>:${diagnostic_GCC}>
$<$<COMPILE_LANG_AND_ID:C,GCC>:${diagnostic_GCC}>
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:${diagnostic_CLANG}>
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:${diagnostic_CLANG}>
)
set(forbid_prefix $<IF:$<BOOL:${MSVC}>,-we,-Werror=>)
set(allow_prefix $<IF:$<BOOL:${MSVC}>,-wd,-Wno->)
set(warn_prefix $<IF:$<BOOL:${MSVC}>,-w1,-W>)

set(--forbid-${diagnostic} $<${when}:${forbid_prefix}${diagnostic_flag}> PARENT_SCOPE)
set(--allow-${diagnostic} $<${when}:${allow_prefix}${diagnostic_flag}> PARENT_SCOPE)
# Set these warnings to level 1 warnings, so they appear by default
set(--warn-${diagnostic} $<${when}:${warn_prefix}${diagnostic_flag}> PARENT_SCOPE)

set(--deny-${diagnostic} ${--forbid-${diagnostic_flag}} PARENT_SCOPE)
endfunction()
83 changes: 83 additions & 0 deletions cmake/Modules/CheckCompilerFlag.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2021 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# # # # sol2 - cmake - compiler flag checking

include_guard(GLOBAL)

include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)

#[[
Given a flag name and the actual flag, like
check_cxx_compiler_flag(strict-conformance MSVC /permissive- GCC -pedantic)
we check if the given flag works C++ compiler. If it is, then
--strict-conformance will be the provided flag. MSVC and GCC are the 2 different
"style" of flags to be tested for.
]]
function (check_compiler_flag flag_name)
cmake_parse_arguments(PARSE_ARGV 1 flag "" "" "GCC;MSVC;CLANG")
if (NOT flag_MSVC)
set(flag_MSVC /${flag_name})
endif()
if (NOT flag_GCC)
set(flag_GCC ${flag_name})
endif()
if (NOT flag_CLANG)
set(flag_CLANG ${flag_GCC})
endif()
string(MAKE_C_IDENTIFIER "${flag_name}" suffix)
string(TOUPPER "${suffix}" suffix)
get_property(enabled-languages GLOBAL PROPERTY ENABLED_LANGUAGES)
if (CXX IN_LIST enabled-languages)
if (MSVC)
check_cxx_compiler_flag(${flag_MSVC} CXX_CHECK_FLAG_${suffix})
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
check_cxx_compiler_flag(${flag_CLANG} CXX_CHECK_FLAG_${suffix})
else()
check_cxx_compiler_flag(${flag_GCC} CXX_CHECK_FLAG_${suffix})
endif()
endif()
if (C IN_LIST enabled-languages)
if (MSVC)
check_c_compiler_flag(${flag_MSVC} C_CHECK_FLAG_${suffix})
elseif (CMAKE_C_COMPILER_ID MATCHES Clang)
check_c_compiler_flag(${flag_CLANG} C_CHECK_FLAG_${suffix})
else()
check_c_compiler_flag(${flag_GCC} C_CHECK_FLAG_${suffix})
endif()
endif()
string(CONCAT when $<OR:
$<AND:$<BOOL:${CXX_CHECK_FLAG_${suffix}}>,$<COMPILE_LANGUAGE:CXX>>,
$<AND:$<BOOL:${C_CHECK_FLAG_${suffix}}>,$<COMPILE_LANGUAGE:C>>
>)
string(CONCAT compiler_flag
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:${flag_MSVC}>
$<$<COMPILE_LANG_AND_ID:C,MSVC>:${flag_MSVC}>
$<$<COMPILE_LANG_AND_ID:CXX,GCC>:${flag_GCC}>
$<$<COMPILE_LANG_AND_ID:C,GCC>:${flag_GCC}>
$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:${flag_CLANG}>
$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:${flag_CLANG}>
)

set(--${flag_name} $<${when}:${compiler_flag}> PARENT_SCOPE)
endfunction()
Loading

0 comments on commit 7aae1aa

Please sign in to comment.