2019-05-22 07:17:31 +08:00
|
|
|
# # # # sol3
|
2018-02-08 13:40:34 +08:00
|
|
|
# The MIT License (MIT)
|
|
|
|
#
|
2020-08-13 22:42:37 +08:00
|
|
|
# Copyright (c) 2013-2020 Rapptz, ThePhD, and contributors
|
2018-02-08 13:40:34 +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.
|
|
|
|
|
2019-05-22 07:17:31 +08:00
|
|
|
# # # sol3 Examples - require_from_dll
|
2018-02-08 13:40:34 +08:00
|
|
|
|
|
|
|
# # Reusable function to call for single target
|
|
|
|
# # Also hides variables from directory/global scope
|
2018-12-24 02:18:14 +08:00
|
|
|
function(make_require_from_dll_example target_lib example_lib_name_suffix)
|
2018-02-08 13:40:34 +08:00
|
|
|
# define sources
|
2018-12-27 15:17:25 +08:00
|
|
|
set(my_object_sources source/my_object.cpp)
|
|
|
|
set(require_from_dll_sources source/require_from_dll.cpp)
|
2018-02-08 13:40:34 +08:00
|
|
|
|
|
|
|
# define names
|
|
|
|
set(example_lib_name my_object)
|
|
|
|
set(example_name require_from_dll)
|
2018-12-24 02:18:14 +08:00
|
|
|
set(example_lib_name "${example_lib_name}${example_lib_name_suffix}")
|
|
|
|
set(example_name "${example_name}${example_lib_name_suffix}")
|
|
|
|
|
2018-02-08 13:40:34 +08:00
|
|
|
# add library target my_object for the require_from_dll program
|
|
|
|
add_library(${example_lib_name} SHARED ${my_object_sources})
|
|
|
|
set_target_properties(${example_lib_name} PROPERTIES
|
|
|
|
PREFIX "")
|
2018-12-24 02:18:14 +08:00
|
|
|
|
2018-12-27 15:17:25 +08:00
|
|
|
target_include_directories(${example_lib_name}
|
|
|
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
|
|
|
target_compile_definitions(${example_lib_name}
|
|
|
|
PUBLIC MY_OBJECT_DLL
|
|
|
|
PRIVATE MY_OBJECT_BUILD)
|
|
|
|
target_link_libraries(${example_lib_name}
|
|
|
|
PUBLIC ${target_lib} ${LUA_LIBRARIES} sol2::assert)
|
|
|
|
target_include_directories(${example_lib_name}
|
|
|
|
PUBLIC "${LUA_INCLUDE_DIRS}")
|
2018-12-24 02:18:14 +08:00
|
|
|
|
|
|
|
if (MSVC)
|
|
|
|
target_compile_options(${example_lib_name}
|
|
|
|
PRIVATE /std:c++latest /EHsc "$<$<CONFIG:Debug>:/MDd>"
|
|
|
|
"$<$<CONFIG:Release>:/MD>"
|
|
|
|
"$<$<CONFIG:RelWithDebInfo>:/MD>"
|
|
|
|
"$<$<CONFIG:MinSizeRel>:/MD>")
|
|
|
|
target_compile_definitions(${example_lib_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_lib_name}
|
2018-12-28 02:02:31 +08:00
|
|
|
PRIVATE -std=c++1z
|
2019-03-23 04:28:17 +08:00
|
|
|
-Wno-unknown-warning -Wno-unknown-warning-option
|
2019-02-11 04:02:40 +08:00
|
|
|
-Wall -Wextra -Wpedantic -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(${test_target_name}
|
|
|
|
# PRIVATE -Wcomma)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2018-12-27 15:17:25 +08:00
|
|
|
if (IS_X86)
|
|
|
|
target_compile_options(${example_lib_name} BEFORE PRIVATE -m32)
|
|
|
|
endif()
|
2018-12-24 02:18:14 +08:00
|
|
|
endif()
|
|
|
|
|
2018-02-08 13:40:34 +08:00
|
|
|
if(CMAKE_DL_LIBS)
|
2018-02-09 12:19:45 +08:00
|
|
|
target_link_libraries(${example_lib_name} PUBLIC ${CMAKE_DL_LIBS})
|
2018-02-08 13:40:34 +08:00
|
|
|
endif()
|
2018-12-24 02:18:14 +08:00
|
|
|
|
2018-02-08 13:40:34 +08:00
|
|
|
# add executable target that represents require_from_dll program
|
|
|
|
add_executable(${example_name} ${require_from_dll_sources})
|
2018-12-27 15:17:25 +08:00
|
|
|
target_link_libraries(${example_name}
|
|
|
|
PRIVATE my_object ${LUA_LIBRARIES} ${target_lib})
|
|
|
|
target_include_directories(${example_name}
|
|
|
|
PRIVATE ${LUA_INCLUDE_DIRS})
|
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}
|
|
|
|
PRIVATE -std=c++1z
|
2019-03-23 04:28:17 +08:00
|
|
|
-Wno-unknown-warning -Wno-unknown-warning-option
|
2019-02-11 04:02:40 +08:00
|
|
|
-Wall -Wextra -Wpedantic -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(${test_target_name}
|
|
|
|
# PRIVATE -Wcomma)
|
|
|
|
endif()
|
2018-12-24 02:18:14 +08:00
|
|
|
endif()
|
|
|
|
|
2018-02-08 13:40:34 +08:00
|
|
|
if(CMAKE_DL_LIBS)
|
|
|
|
target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS})
|
|
|
|
endif()
|
2018-12-24 02:18:14 +08:00
|
|
|
|
|
|
|
if (SOL2_TESTS_DYNAMIC_LOADING_EXAMPLES)
|
|
|
|
get_target_property(example_working_dir ${example_name} RUNTIME_OUTPUT_DIRECTORY)
|
|
|
|
add_test(NAME ${example_name} COMMAND ${example_name} WORKING_DIRECTORY "${example_working_dir}")
|
2018-02-08 13:40:34 +08:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2018-12-27 15:17:25 +08:00
|
|
|
list(GET LUA_LIBRARIES 0 lua_lib_target)
|
|
|
|
get_target_property(lua_lib_type ${lua_lib_target} TYPE)
|
|
|
|
if (lua_lib_type MATCHES "STATIC")
|
|
|
|
# avoid multiply defined references due to linking in the same static library
|
|
|
|
# twice over, and get "multiple definition" errors during linking
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2018-12-24 02:18:14 +08:00
|
|
|
if (SOL2_DYNAMIC_LOADING_EXAMPLES)
|
|
|
|
make_require_from_dll_example(sol2::sol2 "")
|
|
|
|
endif()
|
|
|
|
if (SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE)
|
|
|
|
make_require_from_dll_example(sol2::sol2_single ".single")
|
|
|
|
endif()
|
|
|
|
if (SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE_GENERATED)
|
|
|
|
make_require_from_dll_example(sol2::sol2_single_generated ".single.generated")
|
|
|
|
endif()
|