2017-12-20 17:58:32 +08:00
|
|
|
# # # # sol2
|
|
|
|
# The MIT License (MIT)
|
|
|
|
#
|
2019-03-13 17:18:06 +08:00
|
|
|
# Copyright (c) 2013-2019 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.
|
|
|
|
|
2018-02-08 13:40:34 +08:00
|
|
|
# # # sol2 Examples
|
2017-12-20 17:58:32 +08:00
|
|
|
|
2018-12-24 02:18:14 +08:00
|
|
|
if (SOL2_DYNAMIC_LOADING_EXAMPLES OR SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE OR SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE_GENERATED)
|
2018-02-12 16:55:14 +08:00
|
|
|
# # require_from_dll example
|
|
|
|
# just add the subdirectory
|
|
|
|
add_subdirectory(require_dll_example)
|
2018-12-20 12:17:15 +08:00
|
|
|
endif()
|
2018-02-13 06:01:30 +08:00
|
|
|
|
2018-12-24 02:18:14 +08:00
|
|
|
if (SOL2_INTEROP_EXAMPLES OR SOL2_INTEROP_EXAMPLES_SINGLE OR SOL2_INTEROP_EXAMPLES_SINGLE_GENERATED)
|
2018-02-11 13:53:53 +08:00
|
|
|
# # interop examples
|
|
|
|
add_subdirectory(interop/kaguya)
|
|
|
|
add_subdirectory(interop/tolua)
|
|
|
|
add_subdirectory(interop/LuaBridge)
|
|
|
|
add_subdirectory(interop/luwra)
|
2018-12-20 12:17:15 +08:00
|
|
|
endif()
|
2018-02-09 12:19:45 +08:00
|
|
|
|
2018-12-27 15:17:25 +08:00
|
|
|
# # Utility assert.hpp "library"
|
|
|
|
add_library(sol2_assert INTERFACE)
|
|
|
|
add_library(sol2::assert ALIAS sol2_assert)
|
|
|
|
set_target_properties(sol2_assert
|
|
|
|
PROPERTIES
|
2018-12-28 01:37:56 +08:00
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
2018-12-27 15:17:25 +08:00
|
|
|
if (SOL2_CI)
|
|
|
|
target_compile_definitions(sol2_assert
|
2018-12-28 01:41:43 +08:00
|
|
|
INTERFACE SOL2_CI)
|
2018-12-27 15:17:25 +08:00
|
|
|
endif()
|
|
|
|
|
2018-02-09 12:19:45 +08:00
|
|
|
# # single-source compilable examples
|
|
|
|
|
2018-12-20 12:17:15 +08:00
|
|
|
file(GLOB EXAMPLES_SRC source/*.cpp source/tutorials/quick_n_dirty/*.cpp source/docs/*.cpp)
|
2017-12-20 17:58:32 +08:00
|
|
|
source_group(examples FILES ${EXAMPLES_SRC})
|
|
|
|
|
2018-12-27 15:17:25 +08:00
|
|
|
function (MAKE_EXAMPLE example_source_file example_suffix target_sol)
|
2018-12-20 12:17:15 +08:00
|
|
|
|
2017-12-20 17:58:32 +08:00
|
|
|
get_filename_component(example_name ${example_source_file} NAME_WE)
|
|
|
|
file(RELATIVE_PATH example_source_file_relative ${CMAKE_SOURCE_DIR} ${example_source_file})
|
|
|
|
get_filename_component(example_output_relative_dir ${example_source_file_relative} DIRECTORY)
|
2017-12-25 01:32:23 +08:00
|
|
|
file(TO_CMAKE_PATH "${example_output_relative_dir}" example_output_relative_dir_name)
|
|
|
|
STRING(REGEX REPLACE "/" "." example_output_relative_dir_name "${example_output_relative_dir}")
|
2018-12-20 12:17:15 +08:00
|
|
|
set(example_name "${example_name}${example_suffix}")
|
|
|
|
|
2017-12-25 01:32:23 +08:00
|
|
|
if (example_output_relative_dir_name STREQUAL "")
|
|
|
|
set(example_output_name "${example_name}")
|
|
|
|
else()
|
|
|
|
set(example_output_name "${example_output_relative_dir_name}.${example_name}")
|
|
|
|
endif()
|
2017-12-24 09:34:34 +08:00
|
|
|
|
2018-12-27 15:17:25 +08:00
|
|
|
add_executable(${example_name} ${example_source_file})
|
2017-12-20 17:58:32 +08:00
|
|
|
set_target_properties(${example_name}
|
|
|
|
PROPERTIES
|
2018-12-20 14:18:07 +08:00
|
|
|
OUTPUT_NAME "${example_output_name}"
|
|
|
|
EXPORT_NAME sol2::${example_output_name})
|
2018-12-24 02:18:14 +08:00
|
|
|
|
|
|
|
if (MSVC)
|
|
|
|
target_compile_options(${example_name}
|
|
|
|
PRIVATE /std:c++latest /EHsc "$<$<CONFIG:Debug>:/MDd>"
|
|
|
|
"$<$<CONFIG:Release>:/MD>"
|
|
|
|
"$<$<CONFIG:RelWithDebInfo>:/MD>"
|
|
|
|
"$<$<CONFIG:MinSizeRel>:/MD>")
|
|
|
|
target_compile_definitions(${example_name}
|
2018-12-27 15:17:25 +08:00
|
|
|
PRIVATE UNICODE _UNICODE
|
|
|
|
_CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE )
|
2018-12-24 02:18:14 +08:00
|
|
|
else()
|
|
|
|
target_compile_options(${example_name}
|
2018-12-28 02:02:31 +08:00
|
|
|
PRIVATE -std=c++1z
|
2019-03-10 09:57:49 +08:00
|
|
|
-ftemplate-backtrace-limit=0
|
2019-03-23 04:28:17 +08:00
|
|
|
-Wno-unknown-warning -Wno-unknown-warning-option
|
2019-02-14 15:40:57 +08:00
|
|
|
-Wall -Wpedantic -Werror -pedantic -pedantic-errors
|
2019-03-23 04:28:17 +08:00
|
|
|
-Wno-noexcept-type)
|
|
|
|
|
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
# For another day, when C++ is not so crap
|
|
|
|
# and we have time to audit the entire lib
|
|
|
|
# for all uses of `detail::swallow`...
|
|
|
|
#target_compile_options(${example_name}
|
|
|
|
# PRIVATE -Wcomma)
|
|
|
|
endif()
|
2018-12-24 02:18:14 +08:00
|
|
|
endif()
|
|
|
|
|
2018-12-27 15:17:25 +08:00
|
|
|
target_link_libraries(${example_name}
|
|
|
|
PRIVATE ${target_sol} ${LUA_LIBRARIES} sol2::assert)
|
|
|
|
|
2017-12-24 09:34:34 +08:00
|
|
|
if(CMAKE_DL_LIBS)
|
2018-12-28 01:37:56 +08:00
|
|
|
target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS})
|
2017-12-24 09:34:34 +08:00
|
|
|
endif()
|
2018-02-17 23:44:55 +08:00
|
|
|
|
2018-12-27 15:17:25 +08:00
|
|
|
if (SOL2_TESTS_EXAMPLES)
|
2018-12-20 12:17:15 +08:00
|
|
|
add_test(NAME ${example_output_name} COMMAND ${example_name})
|
2017-12-24 09:34:34 +08:00
|
|
|
endif()
|
2017-12-25 01:32:23 +08:00
|
|
|
install(TARGETS ${example_name} RUNTIME DESTINATION bin)
|
2017-12-24 09:34:34 +08:00
|
|
|
endfunction(MAKE_EXAMPLE)
|
|
|
|
|
2018-12-20 12:17:15 +08:00
|
|
|
if (SOL2_EXAMPLES)
|
2017-12-26 12:27:22 +08:00
|
|
|
foreach(example_source_file ${EXAMPLES_SRC})
|
2018-12-27 15:17:25 +08:00
|
|
|
MAKE_EXAMPLE(${example_source_file} "" sol2::sol2)
|
2017-12-26 12:27:22 +08:00
|
|
|
endforeach()
|
2018-12-20 12:17:15 +08:00
|
|
|
endif()
|
2018-02-11 13:53:53 +08:00
|
|
|
|
2018-12-20 14:18:07 +08:00
|
|
|
if (SOL2_EXAMPLES_SINGLE)
|
2018-12-20 12:17:15 +08:00
|
|
|
foreach(example_source_file ${EXAMPLES_SRC})
|
2018-12-27 15:17:25 +08:00
|
|
|
MAKE_EXAMPLE(${example_source_file} ".single" sol2::sol2_single)
|
2018-12-20 12:17:15 +08:00
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
2018-12-20 14:18:07 +08:00
|
|
|
if (SOL2_EXAMPLES_SINGLE_GENERATED)
|
2018-12-20 12:17:15 +08:00
|
|
|
foreach(example_source_file ${EXAMPLES_SRC})
|
2018-12-27 15:17:25 +08:00
|
|
|
MAKE_EXAMPLE(${example_source_file} ".single.generated" sol2::sol2_single_generated)
|
2018-12-20 12:17:15 +08:00
|
|
|
endforeach()
|
2018-02-25 06:19:16 +08:00
|
|
|
endif()
|