2017-12-20 17:58:32 +08:00
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2017 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.
2017-08-24 04:25:19 +08:00
2017-12-20 17:58:32 +08:00
# # # # sol2
cmake_minimum_required ( VERSION 3.5.0 )
2017-12-24 09:34:34 +08:00
project ( sol2 VERSION 2.19.0 LANGUAGES CXX C )
2017-08-24 04:25:19 +08:00
2017-12-20 17:58:32 +08:00
# # # General Project Requirements
# Set general standard requirements here
2017-08-24 04:25:19 +08:00
set ( CMAKE_CXX_STANDARD 14 )
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
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
2017-12-24 09:34:34 +08:00
set ( LUA_VERSION "5.3.4" CACHE STRING "The version of Lua needed. Can be 5.1, 5.2, 5.3, LuaJIT, or a more specific 3-part version number for a specifc Lua (e.g., 5.3.4 or luajit-2.0.5)" )
2017-12-20 17:58:32 +08:00
set ( BUILD_LUA TRUE CACHE BOOL "Always build Lua, do not search for it in the system" )
2017-12-24 09:34:34 +08:00
set ( BUILD_LUAJIT FALSE CACHE BOOL "Always build LuaJIT, do not search for it in the system" )
2017-12-20 17:58:32 +08:00
option ( TESTS "Enable build of tests" OFF )
option ( EXAMPLES "Enable build of examples" OFF )
option ( SINGLE "Enable build of single header files" ON )
# Single tests will only be turned on if both SINGLE and TESTS are defined
CMAKE_DEPENDENT_OPTION ( TESTS_SINGLE "Enable build of tests using the generated single headers" ON
" S I N G L E ; T E S T S " O F F )
2017-12-24 09:34:34 +08:00
CMAKE_DEPENDENT_OPTION ( TESTS_EXAMPLES "Enable build of examples as tests" ON
" T E S T S ; E X A M P L E S " O N )
2017-12-20 17:58:32 +08:00
option ( DOCS "Enable build of documentation" OFF )
# # # sol2 Library
# # Add a target for sol2's library to be included by external users
add_library ( sol2 INTERFACE )
target_include_directories ( sol2 INTERFACE
$ < 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 S T A L L _ I N T E R F A C E : i n c l u d e / s o l > )
# # 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" )
install ( TARGETS sol2
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
D E S T I N A T I O N l i b / c m a k e / s o l 2 )
install ( DIRECTORY include/sol2
D E S T I N A T I O N i n c l u d e )
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 l i b / c m a k e / s o l 2 )
# # # Source Groups
# # Sources everyone is going to need
# Header files
file ( GLOB SOL2_HEADER_SOURCES sol*.hpp )
source_group ( headers FILES ${ SOL2_HEADER_SOURCES } )
# single header files
file ( GLOB SOL2_SINGLE_HEADER_SOURCES single/sol/sol_forward.hpp single/sol/sol.hpp )
source_group ( headers FILES ${ SOL2_SINGLE_HEADER_SOURCES } )
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
find_package ( PythonInterp 3 )
2017-12-24 09:34:34 +08:00
set ( SOL2_SINGLE_HEADER_FOUND FALSE )
2017-12-20 17:58:32 +08:00
if ( PYTHONINTERP_FOUND )
if ( SINGLE )
2017-12-24 09:34:34 +08:00
set ( SOL2_SINGLE_FOUND TRUE )
2017-12-20 17:58:32 +08:00
add_custom_command ( OUTPUT "${CMAKE_BINARY_DIR}/single/sol/sol.hpp" "${CMAKE_BINARY_DIR}/single/sol/sol_forward.hpp"
C O M M A N D $ { P Y T H O N _ E X E C U T A B L E } " $ { C M A K E _ S O U R C E _ D I R } / s i n g l e . p y " - - o u t p u t " $ { C M A K E _ B I N A R Y _ D I R } / s i n g l e / s o l / s o l . h p p "
2017-12-24 09:34:34 +08:00
D E P E N D S $ { S O L 2 _ H E A D E R _ S O U R C E S } )
add_custom_target ( sol2_single_header
2017-12-20 17:58:32 +08:00
D E P E N D S " $ { C M A K E _ B I N A R Y _ D I R } / s i n g l e / s o l / s o l . h p p " " $ { C M A K E _ B I N A R Y _ D I R } / s i n g l e / s o l / s o l _ f o r w a r d . h p p " )
2017-12-24 09:34:34 +08:00
set_target_properties ( sol2_single_header
2017-12-20 17:58:32 +08:00
P R O P E R T I E S
I N C L U D E _ D I R E C T O R I E S " $ { C M A K E _ B I N A R Y _ D I R } / s i n g l e / s o l " )
install ( FILES "${CMAKE_BINARY_DIR}/single/sol/sol.hpp" "${CMAKE_BINARY_DIR}/single/sol/sol_forward.hpp"
D E S T I N A T I O N i n c l u d e / s o l )
endif ( )
if ( DOCS )
2017-12-24 10:29:29 +08:00
set ( SOL2_DOCS_FOUND TRUE )
2017-12-20 17:58:32 +08:00
add_custom_command ( OUTPUT documentation COMMAND "make html" WORKING_DIRECTORY ${ CMAKE_SOURCE_DIR } /docs )
add_custom_target ( docs DEPENDS documentation )
install ( DIRECTORY "${CMAKE_SOURCE_DIR}/docs/build/html" DESTINATION bin/docs )
endif ( )
else ( )
if ( SINGLE )
2017-12-24 10:29:29 +08:00
set ( SOL2_SINGLE_FOUND FALSE )
2017-12-20 17:58:32 +08:00
message ( STATUS "single_header cannot be generated as python 3 has not been found." )
endif ( )
if ( DOCS )
2017-12-24 10:29:29 +08:00
set ( SOL2_DOCS_FOUND FALSE )
2017-12-20 17:58:32 +08:00
message ( STATUS "documentation cannot be generated as python 3 has not been found." )
endif ( )
2017-08-31 16:06:00 +08:00
endif ( )
2017-08-25 17:04:09 +08:00
2017-12-24 09:34:34 +08:00
# # # Tests, Examples and other CI suites that come with sol2
2017-12-24 10:29:29 +08:00
if ( TESTS OR TESTS_SINGLE OR EXAMPLES OR TESTS_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
find_package ( Threads )
# Find way to get Lua: build if requested, or attempt to build if no matching version is found
string ( TOLOWER ${ LUA_VERSION } NORMALIZED_LUA_VERSION )
if ( BUILD_LUA OR BUILD_LUAJIT )
include ( LuaBuild )
elseif ( 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 )
elseif ( NORMALIZED_LUA_VERSION MATCHES "luajit" )
find_package ( LuaJIT REQUIRED )
else ( )
include ( LuaBuild )
endif ( )
2017-08-25 17:04:09 +08:00
2017-12-24 09:34:34 +08:00
if ( NOT LUA_FOUND )
message ( FATAL_ERROR "Lua ${LUA_VERSION} not found and could not be targeted for building." )
endif ( )
# # # Tests
# # Enable test harness for regular or single tests
if ( TESTS OR TESTS_SINGLE )
# enable ctest and add subdir to get going
enable_testing ( )
add_subdirectory ( tests "${CMAKE_BINARY_DIR}/tests" )
endif ( )
# # # Examples
# # Enable examples to be built against the library
2017-12-24 10:29:29 +08:00
if ( EXAMPLES OR TESTS_EXAMPLES )
2017-12-24 09:34:34 +08:00
# NOTE: will also add to tests if TESTS is defined
add_subdirectory ( examples "${CMAKE_BINARY_DIR}/examples" )
endif ( )
2017-12-24 10:29:29 +08:00
endif ( )