2021-03-06 23:14:48 +08:00
# # # # sol2
2017-12-20 17:58:32 +08:00
# The MIT License (MIT)
#
2021-03-06 14:03:23 +08:00
# Copyright (c) 2013-2021 Rapptz, ThePhD, and contributors
2017-12-20 17:58:32 +08:00
#
# 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.
2017-08-24 04:25:19 +08:00
2021-03-06 23:14:48 +08:00
# # # # sol2
2018-01-24 01:07:22 +08:00
# # # Required minimum version statement
2021-05-07 06:44:25 +08:00
cmake_minimum_required ( VERSION 3.16.0 )
# # # Project Include - file that is included after project declaration is finished
2021-05-18 16:45:48 +08:00
set ( CMAKE_PROJECT_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Includes/Project.cmake" )
2018-01-24 01:07:22 +08:00
# # # project declaration
2021-03-08 03:46:13 +08:00
project ( sol2 VERSION 4.0.0 LANGUAGES CXX C )
2017-08-24 04:25:19 +08:00
2021-09-15 15:24:47 +08:00
if ( sol2-is-top-level-project )
2021-03-08 02:43:56 +08:00
message ( STATUS "sol2 is the top-level directory..." )
endif ( )
2017-12-20 17:58:32 +08:00
# Include standard modules
include ( CMakePackageConfigHelpers )
2021-03-06 14:03:23 +08:00
include ( CheckCXXCompilerFlag )
include ( CMakeDependentOption )
include ( GNUInstallDirs )
include ( FetchContent )
2017-12-20 17:58:32 +08:00
# # # Configuration
# # Cached defines, strings, paths and options
2022-06-24 09:43:37 +08:00
set ( SOL2_LUA_VERSION "5.4.4" CACHE STRING "The version of Lua needed. Can be 5.1, 5.2, 5.3, 5.4, LuaJIT, or a more specific 3-part version number for a specifc Lua (e.g., 5.4.4 or luajit-2.0.5)" )
2018-12-20 12:17:15 +08:00
set ( SOL2_BUILD_LUA TRUE CACHE BOOL "Always build Lua, do not search for it in the system" )
set ( SOL2_PLATFORM "x64" CACHE STRING "Target platform to compile for when building binaries (x86, x64)" )
option ( SOL2_CI "Whether or not we are in continguous integration mode" OFF )
2021-03-08 03:46:13 +08:00
option ( SOL2_SYSTEM_INCLUDE "Whether or not sol2 should be considered a system include. This helps suppress errors for when the sol2 author is a big derp and doesn't fix every single warning, ever." ON )
2018-12-20 12:17:15 +08:00
option ( SOL2_TESTS "Enable build of tests" OFF )
option ( SOL2_EXAMPLES "Enable build of examples" OFF )
option ( SOL2_INTEROP_EXAMPLES "Enable build of interop examples" OFF )
option ( SOL2_DYNAMIC_LOADING_EXAMPLES "Enable build of interop examples" OFF )
2021-03-06 23:48:25 +08:00
option ( SOL2_SINGLE "Enable generation and build of single header files" OFF )
2018-12-20 12:17:15 +08:00
option ( SOL2_DOCS "Enable build of documentation" OFF )
2020-11-02 00:10:36 +08:00
option ( SOL2_ENABLE_INSTALL "Enable installation of Sol2" ON )
2018-01-10 21:40:37 +08:00
# Single tests and examples tests will only be turned on if both SINGLE and TESTS are defined
2018-12-20 12:17:15 +08:00
CMAKE_DEPENDENT_OPTION ( SOL2_TESTS_SINGLE "Enable build of tests using the premade single headers" ON
" S O L 2 _ S I N G L E ; S O L 2 _ T E S T S " O F F )
CMAKE_DEPENDENT_OPTION ( SOL2_EXAMPLES_SINGLE "Enable build of examples using the generated single headers" OFF
" S O L 2 _ S I N G L E ; S O L 2 _ E X A M P L E S " O F F )
CMAKE_DEPENDENT_OPTION ( SOL2_INTEROP_EXAMPLES_SINGLE "Enable build of interop examples using the generated single headers" OFF
" S O L 2 _ S I N G L E ; S O L 2 _ I N T E R O P _ E X A M P L E S " O F F )
CMAKE_DEPENDENT_OPTION ( SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE "Enable build of dynamic loading examples using the generated single headers" OFF
" S O L 2 _ S I N G L E ; S O L 2 _ D Y N A M I C _ L O A D I N G _ E X A M P L E S " O F F )
CMAKE_DEPENDENT_OPTION ( SOL2_TESTS_EXAMPLES "Enable build of examples as tests" ON
" S O L 2 _ E X A M P L E S " O F F )
CMAKE_DEPENDENT_OPTION ( SOL2_TESTS_INTEROP_EXAMPLES "Enable build of interop examples as tests" ON
" S O L 2 _ I N T E R O P _ E X A M P L E S " O F F )
CMAKE_DEPENDENT_OPTION ( SOL2_TESTS_DYNAMIC_LOADING_EXAMPLES "Enable build of dynamic loading examples as tests" ON
" S O L 2 _ D Y N A M I C _ L O A D I N G _ E X A M P L E S " O F F )
CMAKE_DEPENDENT_OPTION ( BUILD_LUA_AS_DLL "Build Lua as a DLL" ON
" S O L 2 _ B U I L D _ L U A " O F F )
2017-12-20 17:58:32 +08:00
2021-03-08 03:46:13 +08:00
if ( SOL2_SYSTEM_INCLUDE )
2021-05-07 06:44:25 +08:00
set ( sol2-system-include SYSTEM )
2021-03-08 03:46:13 +08:00
endif ( )
2018-12-20 12:17:15 +08:00
# # # sol2 Source Groups
# # Sources everyone is going to need
# Header files
2021-09-15 15:24:47 +08:00
file ( GLOB_RECURSE sol2-headers
L I S T _ D I R E C T O R I E S F A L S E
C O N F I G U R E _ D E P E N D S
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / i n c l u d e / s o l * . h p p
)
file ( GLOB_RECURSE sol2-sources
L I S T _ D I R E C T O R I E S F A L S E
C O N F I G U R E _ D E P E N D S
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s o u r c e / * *
)
2018-12-20 12:17:15 +08:00
2017-12-20 17:58:32 +08:00
# # # sol2 Library
# # Add a target for sol2's library to be included by external users
add_library ( sol2 INTERFACE )
2018-08-11 08:53:31 +08:00
add_library ( sol2::sol2 ALIAS sol2 )
2021-09-15 15:24:47 +08:00
target_include_directories ( sol2 ${ sol2-system-include }
I N T E R F A C E
2018-09-28 13:27:38 +08:00
$ < B U I L D _ I N T E R F A C E : $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / i n c l u d e >
2019-06-25 17:36:33 +08:00
$ < I N S T A L L _ I N T E R F A C E : i n c l u d e > )
2017-12-20 17:58:32 +08:00
# # Version configurations
configure_package_config_file (
c m a k e / s o l 2 - c o n f i g . c m a k e . i n
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / s o l 2 - c o n f i g . c m a k e "
I N S T A L L _ D E S T I N A T I O N l i b / c m a k e / s o l 2
N O _ C H E C K _ R E Q U I R E D _ C O M P O N E N T S _ M A C R O )
write_basic_package_version_file (
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / s o l 2 - c o n f i g - v e r s i o n . c m a k e "
C O M P A T I B I L I T Y A n y N e w e r V e r s i o n )
2021-09-15 15:24:47 +08:00
export ( TARGETS sol2
F I L E " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / s o l 2 - t a r g e t s . c m a k e " )
2017-12-20 17:58:32 +08:00
2020-11-02 00:10:36 +08:00
if ( SOL2_ENABLE_INSTALL )
install ( TARGETS sol2
E X P O R T s o l 2 )
2017-12-20 17:58:32 +08:00
2020-11-02 00:10:36 +08:00
install ( EXPORT sol2
F I L E s o l 2 - t a r g e t s . c m a k e
D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ L I B D I R } / c m a k e / s o l 2 " )
2018-02-17 13:23:54 +08:00
2020-11-02 00:10:36 +08:00
install ( DIRECTORY include/sol
D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ I N C L U D E D I R } " )
2017-12-20 17:58:32 +08:00
2020-11-02 00:10:36 +08:00
install ( FILES
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / s o l 2 - c o n f i g . c m a k e "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c m a k e / s o l 2 - c o n f i g - v e r s i o n . c m a k e "
D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ L I B D I R } / c m a k e / s o l 2 " )
endif ( )
2017-12-20 17:58:32 +08:00
2021-09-15 15:24:47 +08:00
# # # sol2 Library - Single header target
2021-03-06 23:48:25 +08:00
if ( SOL2_SINGLE )
2018-12-20 12:17:15 +08:00
message ( STATUS "sol2 adding single..." )
add_subdirectory ( single )
endif ( )
# # # documentation
# Generates the docs
if ( SOL2_DOCS )
message ( STATUS "sol2 adding docs..." )
2021-03-06 14:03:23 +08:00
add_subdirectory ( documentation )
2017-08-31 16:06:00 +08:00
endif ( )
2017-08-25 17:04:09 +08:00
2020-11-02 00:10:36 +08:00
if ( SOL2_ENABLE_INSTALL )
# pkg-config support, except on Windows
if ( NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows )
set ( PKGCONFIG_INSTALL_DIR
" $ { C M A K E _ I N S T A L L _ D A T A R O O T D I R } / p k g c o n f i g "
C A C H E P A T H " P a t h w h e r e s o l 2 . p c i s i n s t a l l e d " )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/sol2.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/sol2.pc" @ONLY )
install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/sol2.pc" DESTINATION "${PKGCONFIG_INSTALL_DIR}" )
endif ( )
2018-02-17 13:23:54 +08:00
endif ( )
2018-12-20 12:17:15 +08:00
if ( SOL2_CI )
2018-01-20 04:03:22 +08:00
message ( STATUS "sol2 Contiguous Integration is on" )
2017-12-26 00:44:04 +08:00
endif ( )
2018-12-20 12:17:15 +08:00
if ( SOL2_EXAMPLES OR SOL2_TESTS_EXAMPLES OR SOL2_EXAMPLES_SINGLE OR SOL2_INTEROP_EXAMPLES OR SOL2_TESTS_INTEROP_EXAMPLES OR SOL2_INTEROP_EXAMPLES_SINGLE OR SOL2_DYNAMIC_LOADING_EXAMPLES OR SOL2_TESTS_DYNAMIC_LOADING_EXAMPLES OR SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE )
2019-11-30 08:21:14 +08:00
set ( SOL2_DO_EXAMPLES TRUE )
2018-02-13 06:01:30 +08:00
else ( )
2019-11-30 08:21:14 +08:00
set ( SOL2_DO_EXAMPLES FALSE )
2018-02-13 06:01:30 +08:00
endif ( )
2018-12-20 12:17:15 +08:00
if ( SOL2_TESTS OR SOL2_TESTS_SINGLE )
2019-11-30 08:21:14 +08:00
set ( SOL2_DO_TESTS TRUE )
2018-02-13 06:01:30 +08:00
else ( )
2019-11-30 08:21:14 +08:00
set ( SOL2_DO_TESTS FALSE )
2018-02-13 06:01:30 +08:00
endif ( )
2017-12-24 09:34:34 +08:00
# # # Tests, Examples and other CI suites that come with sol2
2021-09-15 15:24:47 +08:00
if ( sol2-is-top-level-project )
2019-02-11 04:02:40 +08:00
# # # General project output locations
2021-05-07 06:44:25 +08:00
if ( CMAKE_SIZEOF_VOID_P EQUAL 4 )
2019-02-11 04:02:40 +08:00
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" )
else ( )
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/lib" )
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/bin" )
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/bin" )
endif ( )
2021-09-15 15:24:47 +08:00
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 ( )
2021-10-24 03:56:57 +08:00
# Build Flag Settings
# 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 )
check_compiler_diagnostic ( padding-from-alignment MSVC 4324 )
2017-12-24 09:34:34 +08:00
# # # Libraries
# Here, we pull in all the necessary libraries for building examples and tests
# Find threading library
2018-02-11 13:53:53 +08:00
find_package ( Threads REQUIRED )
2019-11-30 08:21:14 +08:00
2018-12-20 12:17:15 +08:00
string ( TOLOWER ${ SOL2_LUA_VERSION } NORMALIZED_LUA_VERSION )
2017-12-24 09:34:34 +08:00
# Find way to get Lua: build if requested, or attempt to build if no matching version is found
2018-12-20 12:17:15 +08:00
if ( SOL2_BUILD_LUA )
find_package ( LuaBuild REQUIRED COMPONENTS ${ SOL2_LUA_VERSION } )
elseif ( NOT SOL2_LUA_VERSION )
2018-01-24 01:07:22 +08:00
find_package ( LuaBuild REQUIRED )
2019-11-30 08:21:14 +08:00
else ( )
2018-01-01 10:15:43 +08:00
if ( NORMALIZED_LUA_VERSION MATCHES "5.1" )
2019-01-06 02:56:21 +08:00
set ( CREATE_LUALIB_TARGET TRUE )
2018-01-01 10:15:43 +08:00
find_package ( Lua 5.1 EXACT REQUIRED )
elseif ( NORMALIZED_LUA_VERSION MATCHES "5.2" )
2019-01-06 02:56:21 +08:00
set ( CREATE_LUALIB_TARGET TRUE )
2018-01-01 10:15:43 +08:00
find_package ( Lua 5.2 EXACT REQUIRED )
elseif ( NORMALIZED_LUA_VERSION MATCHES "5.3" )
2019-01-06 02:56:21 +08:00
set ( CREATE_LUALIB_TARGET TRUE )
2018-01-01 10:15:43 +08:00
find_package ( Lua 5.3 EXACT REQUIRED )
2018-12-20 12:17:15 +08:00
elseif ( NORMALIZED_LUA_VERSION MATCHES "5.4" )
2019-01-06 02:56:21 +08:00
set ( CREATE_LUALIB_TARGET TRUE )
2018-12-20 12:17:15 +08:00
find_package ( Lua 5.4 EXACT REQUIRED )
2018-01-01 10:15:43 +08:00
elseif ( NORMALIZED_LUA_VERSION MATCHES "luajit" )
2019-01-06 02:56:21 +08:00
set ( CREATE_LUALIB_TARGET TRUE )
2018-01-01 10:15:43 +08:00
find_package ( LuaJIT REQUIRED )
else ( )
2018-12-20 12:17:15 +08:00
find_package ( LuaBuild ${ SOL2_LUA_VERSION } REQUIRED )
2018-01-01 10:15:43 +08:00
endif ( )
2017-12-24 09:34:34 +08:00
endif ( )
2019-11-30 08:21:14 +08:00
2019-01-06 02:56:21 +08:00
if ( CREATE_LUALIB_TARGET AND LUA_FOUND )
set ( lualib lua_imported_lib_ ${ SOL2_LUA_VERSION } )
foreach ( lua_search_lib ${ LUA_LIBRARIES } )
get_filename_component ( lsl_fname ${ lua_search_lib } NAME )
if ( lsl_fname MATCHES "lua" OR lsl_fname MATCHES "Lua" OR lsl_fname MATCHES "LUA" )
if ( lsl_fname MATCHES "\.so|\.dylib|\.dll" )
set ( lualibtype SHARED )
set ( lualiblocation ${ lua_search_lib } )
else ( )
set ( lualibtype STATIC )
set ( lualiblocation ${ lua_search_lib } )
endif ( )
else ( )
set ( LUA_SEARCH_DEPENDENCY_LIBS ${ LUA_SEARCH_DEPENDENCY_LIBS } "${lua_search_lib}" )
endif ( )
endforeach ( )
add_library ( ${ lualib } ${ lualibtype } IMPORTED )
set_target_properties ( ${ lualib }
P R O P E R T I E S
I N T E R F A C E _ I N C L U D E _ D I R E C T O R I E S $ { L U A _ I N C L U D E _ D I R }
2021-10-28 05:37:55 +08:00
I N T E R F A C E _ L I N K _ L I B R A R I E S " $ { L U A _ S E A R C H _ D E P E N D E N C Y _ L I B S } $ { C M A K E _ D L _ L I B S } "
2019-01-06 02:56:21 +08:00
I M P O R T E D _ L I N K _ I N T E R F A C E _ L A N G U A G E S C
I M P O R T E D _ L O C A T I O N $ { l u a l i b l o c a t i o n } )
set ( LUA_LIBRARIES ${ lualib } )
endif ( )
2018-01-24 01:07:22 +08:00
if ( NOT LUA_FOUND AND NOT LUABUILD_FOUND )
2018-12-20 12:17:15 +08:00
message ( FATAL_ERROR "sol2 Lua \" ${ SOL2_LUA_VERSION } \" not found and could not be targeted for building " )
2017-12-24 09:34:34 +08:00
endif ( )
2018-08-11 08:53:31 +08:00
2018-01-20 04:03:22 +08:00
# # Enable test harness for regular, example or single tests
2019-11-30 08:21:14 +08:00
if ( SOL2_DO_TESTS OR ( SOL2_TESTS_EXAMPLES AND SOL2_DO_EXAMPLES ) )
2017-12-26 00:44:04 +08:00
# enable ctest
2019-11-30 08:21:14 +08:00
message ( STATUS "sol2 testing enabled..." )
2017-12-24 09:34:34 +08:00
enable_testing ( )
2017-12-26 00:44:04 +08:00
endif ( )
2018-08-11 08:53:31 +08:00
2018-01-20 04:03:22 +08:00
# # # Examples
# # Enable examples to be built against the library
2019-11-30 08:21:14 +08:00
if ( SOL2_DO_EXAMPLES )
2018-01-20 04:03:22 +08:00
# NOTE: will also add to tests if TESTS is defined
message ( STATUS "sol2 adding examples..." )
2021-09-15 15:24:47 +08:00
add_subdirectory ( examples )
2018-01-20 04:03:22 +08:00
endif ( )
2018-08-11 08:53:31 +08:00
2018-01-20 04:03:22 +08:00
# # # Tests
2017-12-26 00:44:04 +08:00
# # Add tests here
2019-11-30 08:21:14 +08:00
if ( SOL2_DO_TESTS )
2017-12-26 00:44:04 +08:00
# add subdir to get going
2018-01-20 04:03:22 +08:00
message ( STATUS "sol2 adding tests..." )
2021-09-15 15:24:47 +08:00
add_subdirectory ( tests )
2017-12-24 09:34:34 +08:00
endif ( )
2021-03-06 23:14:48 +08:00
# # # Scratch Space
# # Scratch space for diagnosing bugs and other shenanigans
if ( SOL2_SCRATCH )
message ( STATUS "sol2 adding scratch space..." )
add_subdirectory ( scratch )
endif ( )
2017-12-24 10:29:29 +08:00
endif ( )