2017-08-24 04:25:19 +08:00
|
|
|
cmake_minimum_required(VERSION 3.0)
|
|
|
|
|
|
|
|
project(sol2)
|
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
include_directories(.)
|
|
|
|
|
2017-08-30 06:17:05 +08:00
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" "${CMAKE_MODULE_PATH}")
|
|
|
|
|
2017-08-30 06:25:46 +08:00
|
|
|
set(LUA_VERSION "5.3" CACHE STRING "The version of Lua needed (5.1, 5.2, 5.3, luaJIT)")
|
2017-08-24 21:32:16 +08:00
|
|
|
if (LUA_VERSION MATCHES "5.1")
|
2017-08-25 15:27:26 +08:00
|
|
|
find_package(Lua 5.1 EXACT REQUIRED)
|
2017-08-24 21:32:16 +08:00
|
|
|
elseif(LUA_VERSION MATCHES "5.2")
|
2017-08-25 15:27:26 +08:00
|
|
|
find_package(Lua 5.2 EXACT REQUIRED)
|
2017-08-24 22:15:25 +08:00
|
|
|
elseif(LUA_VERSION MATCHES "5.3")
|
2017-08-25 15:27:26 +08:00
|
|
|
find_package(Lua 5.3 EXACT REQUIRED)
|
|
|
|
elseif(LUA_VERSION MATCHES "LuaJIT")
|
|
|
|
find_package(LuaJIT REQUIRED)
|
2017-08-24 22:15:25 +08:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "${LUA_VERSION} is not a supported version for lua.")
|
2017-08-24 21:32:16 +08:00
|
|
|
endif()
|
2017-08-24 04:25:19 +08:00
|
|
|
|
2017-08-25 15:27:26 +08:00
|
|
|
include_directories(${LUA_INCLUDE_DIR})
|
2017-08-24 21:32:16 +08:00
|
|
|
|
2017-08-30 06:17:05 +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 cxx_auto_type
|
|
|
|
cxx_constexpr
|
|
|
|
cxx_decltype
|
|
|
|
cxx_decltype_auto
|
|
|
|
cxx_default_function_template_args
|
|
|
|
cxx_final
|
|
|
|
cxx_lambdas
|
|
|
|
cxx_noexcept
|
|
|
|
cxx_nullptr
|
|
|
|
cxx_override
|
|
|
|
cxx_range_for
|
|
|
|
cxx_return_type_deduction
|
|
|
|
cxx_right_angle_brackets
|
|
|
|
cxx_static_assert
|
|
|
|
cxx_strong_enums
|
|
|
|
cxx_variadic_macros
|
2017-08-30 06:25:46 +08:00
|
|
|
cxx_variadic_templates)
|
2017-08-30 06:17:05 +08:00
|
|
|
|
2017-08-30 07:15:50 +08:00
|
|
|
file(GLOB HEADER_SRCS sol/*.hpp)
|
|
|
|
set(HEADER_SRCS sol.hpp ${HEADER_SRCS})
|
2017-08-25 16:22:27 +08:00
|
|
|
|
2017-08-25 17:04:09 +08:00
|
|
|
if (NOT MSVC)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning -Wno-unknown-warning-option -Wall -Wextra -Wpedantic -pedantic -pedantic-errors -Wno-noexcept-type -ftemplate-depth=1024")
|
|
|
|
endif()
|
|
|
|
|
2017-08-30 07:15:50 +08:00
|
|
|
file(GLOB EXAMPLES_SRC examples/*.cpp)
|
2017-08-30 06:25:46 +08:00
|
|
|
source_group(examples FILES ${EXAMPLES_SRC})
|
2017-08-25 17:04:09 +08:00
|
|
|
foreach(example_source_file ${EXAMPLES_SRC})
|
|
|
|
get_filename_component(example_name ${example_source_file} NAME_WE)
|
2017-08-30 06:25:46 +08:00
|
|
|
set(example_name "example-${example_name}")
|
2017-08-25 17:04:09 +08:00
|
|
|
add_executable(${example_name} ${example_source_file} ${HEADER_SRCS})
|
|
|
|
target_link_libraries(${example_name} ${LUA_LIBRARIES})
|
2017-08-30 06:17:05 +08:00
|
|
|
target_compile_features(${example_name} PUBLIC ${CXX_FEATURES})
|
2017-08-25 17:04:09 +08:00
|
|
|
install(TARGETS ${example_name} RUNTIME DESTINATION bin/examples)
|
|
|
|
endforeach()
|
|
|
|
|
2017-08-30 07:15:50 +08:00
|
|
|
file(GLOB TEST_SRC test*.cpp)
|
2017-08-30 06:25:46 +08:00
|
|
|
source_group(tests FILES ${TEST_SRC})
|
2017-08-25 17:04:09 +08:00
|
|
|
|
|
|
|
add_executable(tests ${TEST_SRC} ${HEADER_SRCS})
|
|
|
|
target_include_directories(tests PRIVATE ./Catch/include/)
|
|
|
|
|
|
|
|
find_package(Threads)
|
|
|
|
target_link_libraries(tests Threads::Threads ${LUA_LIBRARIES})
|
|
|
|
install(TARGETS tests RUNTIME DESTINATION bin)
|
|
|
|
|
2017-08-25 16:33:50 +08:00
|
|
|
find_package(PythonInterp 3)
|
2017-08-25 16:30:56 +08:00
|
|
|
if (PYTHONINTERP_FOUND)
|
2017-08-25 17:48:56 +08:00
|
|
|
add_custom_command(OUTPUT single/sol/sol.hpp COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/single.py --output ${CMAKE_CURRENT_SOURCE_DIR}/single/sol/sol.hpp DEPENDS ${HEADER_SRCS})
|
|
|
|
add_custom_target(single_sol DEPENDS single/sol/sol.hpp)
|
2017-08-30 06:25:46 +08:00
|
|
|
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/single/sol/sol.hpp" DESTINATION include/sol)
|
2017-08-25 16:39:11 +08:00
|
|
|
message(STATUS "single_sol can be generated as python 3 has been found.")
|
|
|
|
else()
|
|
|
|
message(STATUS "single_sol cannot be generated as python 3 has not been found.")
|
2017-08-25 16:30:56 +08:00
|
|
|
endif()
|