sol2/examples/CMakeLists.txt

119 lines
4.4 KiB
CMake
Raw Normal View History

# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 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.
# # # sol2 Examples
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)
# # require_from_dll example
# just add the subdirectory
add_subdirectory(require_dll_example)
endif()
2018-12-24 02:18:14 +08:00
if (SOL2_INTEROP_EXAMPLES OR SOL2_INTEROP_EXAMPLES_SINGLE OR SOL2_INTEROP_EXAMPLES_SINGLE_GENERATED)
# # interop examples
add_subdirectory(interop/kaguya)
add_subdirectory(interop/tolua)
add_subdirectory(interop/LuaBridge)
add_subdirectory(interop/luwra)
endif()
# # single-source compilable examples
file(GLOB EXAMPLES_SRC source/*.cpp source/tutorials/quick_n_dirty/*.cpp source/docs/*.cpp)
source_group(examples FILES ${EXAMPLES_SRC})
function (MAKE_EXAMPLE example_source_file example_suffix target_sol example_test_var)
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}")
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()
add_executable(${example_name} ${example_source_file} source/assert.hpp)
set_target_properties(${example_name}
PROPERTIES
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}
PRIVATE /DUNICODE /D_UNICODE
/D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_DEPRECATE)
else()
target_compile_options(${example_name}
PRIVATE -std=c++1z -Wno-unknown-warning -Wno-unknown-warning-option
-Wall -Wextra -Wpedantic -pedantic -pedantic-errors)
endif()
target_link_libraries(${example_name} ${target_sol})
target_link_libraries(${example_name} ${LUA_LIBRARIES})
if(CMAKE_DL_LIBS)
target_link_libraries(${example_name} ${CMAKE_DL_LIBS})
endif()
if (SOL2_CI)
target_compile_definitions(${example_name}
PRIVATE SOL2_CI)
endif()
if (MSVC)
else()
target_compile_options(${example_name}
PRIVATE -Wno-noexcept-type)
endif()
if (${example_test_var})
add_test(NAME ${example_output_name} COMMAND ${example_name})
endif()
2017-12-25 01:32:23 +08:00
install(TARGETS ${example_name} RUNTIME DESTINATION bin)
endfunction(MAKE_EXAMPLE)
if (SOL2_EXAMPLES)
foreach(example_source_file ${EXAMPLES_SRC})
MAKE_EXAMPLE(${example_source_file} "" sol2::sol2 SOL2_TESTS_EXAMPLES)
endforeach()
endif()
if (SOL2_EXAMPLES_SINGLE)
foreach(example_source_file ${EXAMPLES_SRC})
MAKE_EXAMPLE(${example_source_file} ".single" sol2::sol2_single SOL2_TESTS_EXAMPLES)
endforeach()
endif()
if (SOL2_EXAMPLES_SINGLE_GENERATED)
foreach(example_source_file ${EXAMPLES_SRC})
MAKE_EXAMPLE(${example_source_file} ".single.generated" sol2::sol2_single_generated SOL2_TESTS_EXAMPLES)
endforeach()
endif()