2018-09-28 13:27:38 +08:00
# # # # sol3
2017-12-20 17:58:32 +08:00
# The MIT License (MIT)
#
2018-04-13 01:58:25 +08:00
# Copyright (c) 2013-2018 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
2018-09-28 13:27:38 +08:00
# # # # sol3
2018-01-24 01:07:22 +08:00
# # # Required minimum version statement
2017-12-20 17:58:32 +08:00
cmake_minimum_required ( VERSION 3.5.0 )
2018-01-24 01:07:22 +08:00
# # # project declaration
2018-12-20 12:17:15 +08:00
project ( sol2 VERSION 3.0.0 LANGUAGES CXX C )
2017-08-24 04:25:19 +08:00
2018-02-17 13:23:54 +08:00
include ( GNUInstallDirs )
2017-12-20 17:58:32 +08:00
# # # General Project Requirements
# Set general standard requirements here
2018-09-28 15:55:47 +08:00
set ( CMAKE_CXX_STANDARD 17 )
2017-08-24 04:25:19 +08:00
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
2017-12-20 17:58:32 +08:00
# Features a C++ compiler must have to be used to compile sol2
# This list is not *complete* as CMake does not support features for
# all of the advanced features utilized.
set ( CXX_FEATURES
c x x _ a u t o _ t y p e
c x x _ c o n s t e x p r
c x x _ d e c l t y p e
c x x _ d e c l t y p e _ a u t o
c x x _ d e f a u l t _ f u n c t i o n _ t e m p l a t e _ a r g s
c x x _ f i n a l
c x x _ l a m b d a s
c x x _ n o e x c e p t
c x x _ n u l l p t r
c x x _ o v e r r i d e
c x x _ r a n g e _ f o r
c x x _ r e t u r n _ t y p e _ d e d u c t i o n
c x x _ r i g h t _ a n g l e _ b r a c k e t s
c x x _ s t a t i c _ a s s e r t
c x x _ s t r o n g _ e n u m s
c x x _ v a r i a d i c _ m a c r o s
c x x _ v a r i a d i c _ t e m p l a t e s )
2017-08-24 04:25:19 +08:00
2018-02-12 16:55:14 +08:00
# # #
2018-12-20 12:17:15 +08:00
if ( SOL2_PLATFORM MATCHES "i686" OR SOL2_PLATFORM STREQUAL "x86" )
2018-02-12 16:55:14 +08:00
set ( IS_X86 TRUE )
2018-12-20 12:17:15 +08:00
elseif ( SOL2_PLATFORM MATCHES "ARM64" )
2018-02-13 06:01:30 +08:00
set ( IS_ARM64 TRUE )
set ( IS_X64 TRUE )
2018-12-20 12:17:15 +08:00
elseif ( SOL2_PLATFORM MATCHES "ARM" )
2018-02-12 16:55:14 +08:00
set ( IS_ARM TRUE )
2018-12-20 12:17:15 +08:00
elseif ( SOL2_PLATFORM MATCHES "x86_64" OR SOL2_PLATFORM STREQUAL "x64" )
2018-02-13 06:01:30 +08:00
set ( IS_X64 TRUE )
2018-02-12 16:55:14 +08:00
else ( )
set ( IS_X64 TRUE )
endif ( )
2017-12-25 01:32:23 +08:00
# # # General project flags
if ( MSVC )
2018-02-17 13:18:26 +08:00
add_definitions ( /DUNICODE /D_UNICODE /D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_DEPRECATE )
2017-12-27 09:42:40 +08:00
# Warning level, exceptions
2018-12-20 12:17:15 +08:00
add_compile_options ( /EHsc )
2018-03-02 11:08:27 +08:00
add_compile_options ( "$<$<CONFIG:Debug>:/MDd>"
" $ < $ < C O N F I G : R e l e a s e > : / M D > "
" $ < $ < C O N F I G : R e l W i t h D e b I n f o > : / M D > "
" $ < $ < C O N F I G : M i n S i z e R e l > : / M D > " )
2018-01-10 21:40:37 +08:00
if ( NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
2017-12-27 09:42:40 +08:00
add_compile_options ( /MP )
endif ( )
2017-12-25 01:32:23 +08:00
else ( )
2017-12-26 00:44:04 +08:00
add_compile_options ( -Wno-unknown-warning -Wno-unknown-warning-option -Wall -Wextra -Wpedantic -pedantic -pedantic-errors )
2018-01-20 04:03:22 +08:00
endif ( )
2017-12-25 01:32:23 +08:00
# # # General project output locations
2018-02-13 06:01:30 +08:00
if ( IS_X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4 )
2018-02-17 13:18:26 +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" )
2017-12-25 01:32:23 +08:00
else ( )
2018-02-17 13:18:26 +08:00
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" )
2017-12-25 01:32:23 +08:00
endif ( )
# # # Modules
# # Include modules useful to the project, whether locally made in our own cmake DIRECTORY
# # our from the standard cmake libraries
2017-12-20 17:58:32 +08:00
# Add home-rolled modules path to front of module path list
2017-08-30 06:17:05 +08:00
set ( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" "${CMAKE_MODULE_PATH}" )
2017-12-20 17:58:32 +08:00
# Include standard modules
include ( CMakeDependentOption )
include ( CMakePackageConfigHelpers )
# # # Configuration
# # Cached defines, strings, paths and options
2018-12-20 12:17:15 +08:00
set ( SOL2_LUA_VERSION "5.3.5" 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.3.4 or luajit-2.0.5)" )
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 )
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 )
option ( SOL2_GENERATE_SINGLE "Enable generation and build of single header files" OFF )
option ( SOL2_SINGLE "Enable use of prepackaged single header files" OFF )
option ( SOL2_DOCS "Enable build of documentation" OFF )
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_TESTS_SINGLE_GENERATED "Enable build of tests using the generated single headers" ON
" S O L 2 _ G E N E R A T E _ 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_EXAMPLES_SINGLE_GENERATED "Enable build of examples using the premade single headers" OFF
" S O L 2 _ G E N E R A T E _ 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_INTEROP_EXAMPLES_SINGLE_GENERATED "Enable build of interop examples using the generated single headers" OFF
" S O L 2 _ G E N E R A T E _ 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_DYNAMIC_LOADING_EXAMPLES_SINGLE_GENERATED "Enable build of dynamic loading examples using the generated single headers" OFF
" S O L 2 _ G E N E R A T E _ 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
2018-12-20 12:17:15 +08:00
# # # sol2 Source Groups
# # Sources everyone is going to need
# Header files
file ( GLOB SOL2_HEADER_SOURCES ${ CMAKE_CURRENT_SOURCE_DIR } /include/sol*.hpp )
source_group ( sol2 FILES ${ SOL2_HEADER_SOURCES } )
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 )
2018-12-20 12:17:15 +08:00
target_sources ( sol2 INTERFACE ${ SOL2_SINGLE_HEADER_SOURCES } )
2018-08-11 08:53:31 +08:00
set_target_properties ( sol2
P R O P E R T I E S
E X P O R T _ N A M E s o l 2 : : s o l 2 )
2017-12-20 17:58:32 +08:00
target_include_directories ( sol2 INTERFACE
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 >
2018-12-20 12:17:15 +08:00
$ < I N S T A L L _ I N T E R F A C E : s o l / 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 )
export ( TARGETS sol2 FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-targets.cmake" )
2018-02-17 13:23:54 +08:00
install ( TARGETS sol2
2017-12-20 17:58:32 +08:00
E X P O R T s o l 2 )
install ( EXPORT sol2
F I L E s o l 2 - t a r g e t s . c m a k e
2018-02-17 13:23:54 +08:00
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-12-20 12:17:15 +08:00
install ( DIRECTORY include/
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 } / s o l / i n c l u d e " )
2017-12-20 17:58:32 +08:00
2018-01-10 21:40:37 +08:00
install ( FILES
2017-12-20 17:58:32 +08:00
" $ { 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 "
2018-02-17 13:23:54 +08:00
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 " )
2017-12-20 17:58:32 +08:00
2017-12-24 09:34:34 +08:00
# # # Single header target
2017-12-20 17:58:32 +08:00
# Find Python3 for single header / forward header generation
2018-12-20 12:17:15 +08:00
if ( SOL2_GENERATE_SINGLE OR SOL2_SINGLE )
message ( STATUS "sol2 adding single..." )
add_subdirectory ( single )
endif ( )
# # # documentation
# Generates the docs
if ( SOL2_DOCS )
message ( STATUS "sol2 adding docs..." )
add_subdirectory ( docs )
2017-08-31 16:06:00 +08:00
endif ( )
2017-08-25 17:04:09 +08:00
2018-02-17 13:23:54 +08:00
# pkg-config support, except on Windows
if ( NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows )
2018-08-11 08:53:31 +08:00
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}" )
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 )
2018-02-13 06:01:30 +08:00
set ( DO_EXAMPLES TRUE )
else ( )
set ( DO_EXAMPLES FALSE )
endif ( )
2018-12-20 12:17:15 +08:00
if ( SOL2_TESTS OR SOL2_TESTS_SINGLE )
2018-02-13 06:01:30 +08:00
set ( DO_TESTS TRUE )
else ( )
set ( DO_TESTS FALSE )
endif ( )
2018-12-20 12:17:15 +08:00
if ( DO_TESTS OR SOL2_TESTS_EXAMPLES OR SOL2_TESTS_INTEROP_EXAMPLES OR SOL2_TESTS_DYNAMIC_LOADING_EXAMPLES )
2018-02-13 06:01:30 +08:00
set ( ENABLE_TESTING TRUE )
else ( )
set ( ENABLE_TESTING FALSE )
endif ( )
2017-12-24 09:34:34 +08:00
# # # Tests, Examples and other CI suites that come with sol2
2018-02-13 06:01:30 +08:00
if ( DO_TESTS OR DO_EXAMPLES )
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
2017-12-27 20:42:37 +08:00
if ( NOT MSVC )
2018-04-13 01:58:25 +08:00
if ( 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" )
2018-02-17 23:44:55 +08:00
endif ( )
2018-02-12 16:55:14 +08:00
set ( CMAKE_THREAD_PREFER_PTHREAD TRUE )
2018-02-11 14:13:42 +08:00
set ( THREADS_PREFER_PTHREAD_FLAG TRUE )
2017-12-27 20:42:37 +08:00
endif ( )
2018-02-11 13:53:53 +08:00
find_package ( Threads REQUIRED )
2018-08-11 08:53:31 +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 )
2017-12-24 09:34:34 +08:00
else ( )
2018-01-01 10:15:43 +08:00
if ( NORMALIZED_LUA_VERSION MATCHES "5.1" )
find_package ( Lua 5.1 EXACT REQUIRED )
elseif ( NORMALIZED_LUA_VERSION MATCHES "5.2" )
find_package ( Lua 5.2 EXACT REQUIRED )
elseif ( NORMALIZED_LUA_VERSION MATCHES "5.3" )
find_package ( Lua 5.3 EXACT REQUIRED )
2018-12-20 12:17:15 +08:00
elseif ( NORMALIZED_LUA_VERSION MATCHES "5.4" )
find_package ( Lua 5.4 EXACT REQUIRED )
2018-01-01 10:15:43 +08:00
elseif ( NORMALIZED_LUA_VERSION MATCHES "luajit" )
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 ( )
2018-08-11 08:53:31 +08:00
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
2018-02-13 06:01:30 +08:00
if ( ENABLE_TESTING )
2017-12-26 00:44:04 +08:00
# enable ctest
2018-01-20 04:03:22 +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
2018-02-13 06:01:30 +08:00
if ( 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..." )
add_subdirectory ( examples "${CMAKE_BINARY_DIR}/examples" )
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
2018-02-13 06:01:30 +08:00
if ( 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..." )
2017-12-24 09:34:34 +08:00
add_subdirectory ( tests "${CMAKE_BINARY_DIR}/tests" )
endif ( )
2017-12-24 10:29:29 +08:00
endif ( )