diff --git a/CMakeLists.txt b/CMakeLists.txt index f713668f..4bb0e7ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,15 @@ set(CXX_FEATURES cxx_variadic_macros cxx_variadic_templates) +# # # +if (PLATFORM MATCHES "i686" OR PLATFORM STREQUAL "x86") + set(IS_X86 TRUE) +elseif (PLATFORM MATCHES "ARM") + set(IS_ARM TRUE) +else() + set(IS_X64 TRUE) +endif() + # # # General project flags if (MSVC) add_definitions(/DUNICODE /D_UNICODE /D_SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING /D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING /D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_DEPRECATE) @@ -62,6 +71,10 @@ if (MSVC) add_compile_options(/MP) endif() else() + if (IS_X86) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") + endif() add_compile_options(-Wno-unknown-warning -Wno-unknown-warning-option -Wall -Wextra -Wpedantic -pedantic -pedantic-errors) endif() @@ -208,6 +221,7 @@ if (TESTS OR TESTS_SINGLE OR TESTS_EXAMPLES OR TESTS_INTEROP_EXAMPLES OR EXAMPLE # Here, we pull in all the necessary libraries for building examples and tests # Find threading library if (NOT MSVC) + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) endif() find_package(Threads REQUIRED) diff --git a/appveyor.yml b/appveyor.yml index 8b5636f9..c34089b7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -121,6 +121,7 @@ init: - set logger= - set build_type= - set build_compiler= +- set lua_build_type=OFF - set vcvars_script="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 - if "%PLATFORM%"=="x64" (set arch= Win64) - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (set CMAKE_GENERATOR=Visual Studio 15 2017%arch%&&set parallelism=/maxcpucount&&set logger=/verbosity:quiet /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"&&set vcvars_script="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat") @@ -145,7 +146,7 @@ before_build: - if DEFINED LLVM_VERSION (call %vcvars_script% && cd C:\projects\sol2) - md build-sol2 - cd build-sol2 -- cmake .. -G "%CMAKE_GENERATOR%" %build_type% %build_compiler% -DLUA_VERSION="%LUA_VERSION%" -DCI=ON -DBUILD_LUA=ON -DBUILD_LUA_AS_DLL=OFF -DTESTS=ON -DEXAMPLES=ON -DSINGLE=ON -DTESTS_EXAMPLES=ON -DEXAMPLES_SINGLE=ON -DTESTS_SINGLE=ON +- cmake .. -G "%CMAKE_GENERATOR%" %build_type% %build_compiler% -DLUA_VERSION="%LUA_VERSION%" -DCI=ON -DBUILD_LUA=ON -DBUILD_LUA_AS_DLL=%lua_build_type% -DTESTS=ON -DEXAMPLES=ON -DSINGLE=ON -DTESTS_EXAMPLES=ON -DEXAMPLES_SINGLE=ON -DTESTS_SINGLE=ON # We do not build the debug versions because the compiler # generates too much debug info for MinGW to handle diff --git a/cmake/Modules/FindLuaBridgeBuild.cmake b/cmake/Modules/FindLuaBridgeBuild.cmake index 372be299..74e863ba 100644 --- a/cmake/Modules/FindLuaBridgeBuild.cmake +++ b/cmake/Modules/FindLuaBridgeBuild.cmake @@ -43,7 +43,7 @@ ExternalProject_Add(LUABRIDGE_BUILD_SOURCE # # Use Git to get what we need GIT_SHALLOW TRUE GIT_SUBMODULES "" - GIT_REPOSITORY https://github.com/vinniefalco/LuaBridge.git + GIT_REPOSITORY https://github.com/ThePhD/LuaBridge.git PREFIX ${luabridge_build_toplevel} SOURCE_DIR ${luabridge_build_toplevel} DOWNLOAD_DIR ${luabridge_build_toplevel} diff --git a/cmake/Modules/FindLuaBuild.cmake b/cmake/Modules/FindLuaBuild.cmake index c7e5319f..da1564b4 100644 --- a/cmake/Modules/FindLuaBuild.cmake +++ b/cmake/Modules/FindLuaBuild.cmake @@ -53,7 +53,6 @@ function(find_lua_build LUA_VERSION) set(LUA_BUILD_OBJECT_FILE_SUFFIX .o) endif() - # # # Options option(BUILD_LUA_AS_DLL ${LUA_BUILD_BUILD_DLL_DEFAULT} "Build Lua or LuaJIT as a Shared/Dynamic Link Library") diff --git a/cmake/Modules/FindLuaBuild/LuaJIT.cmake b/cmake/Modules/FindLuaBuild/LuaJIT.cmake index 19262957..40b6027a 100644 --- a/cmake/Modules/FindLuaBuild/LuaJIT.cmake +++ b/cmake/Modules/FindLuaBuild/LuaJIT.cmake @@ -236,6 +236,9 @@ elseif(LUA_JIT_NORMALIZED_LUA_VERSION MATCHES "latest") set(LUA_JIT_PULL_LATEST TRUE) endif() +set(LUA_JIT_BYPRODUCTS "${LUA_JIT_SOURCE_LUA_LIB}" "${LUA_JIT_SOURCE_LUA_LIB_EXP}" + "${LUA_JIT_SOURCE_LUA_DLL}" "${LUA_JIT_SOURCE_LUA_IMP_LIB}") + if (LUA_JIT_GIT_COMMIT OR LUA_JIT_PULL_LATEST) if (LUA_JIT_PULL_LATEST) MESSAGE(STATUS "Latest LuaJIT has been requested: pulling from git...") @@ -261,8 +264,7 @@ if (LUA_JIT_GIT_COMMIT OR LUA_JIT_PULL_LATEST) ${LUA_JIT_BUILD_COMMAND} INSTALL_COMMAND "" TEST_COMMAND "" - BUILD_BYPRODUCTS "${LUA_JIT_DESTINATION_LUA_LIB}" "${LUA_JIT_DESTINATION_LUA_LIB_EXP}" - "${LUA_JIT_DESTINATION_LUA_DLL}" "${LUA_JIT_DESTINATION_LUA_IMP_LIB}") + BUILD_BYPRODUCTS "${LUA_JIT_BYPRODUCTS}") else() ExternalProject_Add(LUA_JIT BUILD_IN_SOURCE TRUE @@ -282,50 +284,62 @@ else() ${LUA_JIT_BUILD_COMMAND} INSTALL_COMMAND "" TEST_COMMAND "" - BUILD_BYPRODUCTS "${LUA_JIT_DESTINATION_LUA_LIB}" "${LUA_JIT_DESTINATION_LUA_LIB_EXP}" - "${LUA_JIT_DESTINATION_LUA_DLL}" "${LUA_JIT_DESTINATION_LUA_IMP_LIB}") + BUILD_BYPRODUCTS "${LUA_JIT_BYPRODUCTS}") endif() # # Post-Build moving steps for necessary items # Add post-step to move library afterwards + +set(LUA_JIT_EXTERNAL_PROJECT_DEPS "") if (MSVC) ExternalProject_Add_Step(LUA_JIT postbuild.exp DEPENDEES build COMMENT "Libray - Moving \"${LUA_JIT_SOURCE_LUA_LIB_EXP}\" to \"${LUA_JIT_DESTINATION_LUA_LIB_EXP}\"..." - COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_LIB_EXP}" "${LUA_JIT_DESTINATION_LUA_LIB_EXP}" && echo Successfully moved!) + COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_LIB_EXP}" "${LUA_JIT_DESTINATION_LUA_LIB_EXP}" + BYPRODUCTS "${LUA_JIT_DESTINATION_LUA_LIB_EXP}") + ExternalProject_Add_StepTargets(LUA_JIT postbuild_exp) + list(APPEND LUA_JIT_EXTERNAL_PROJECT_DEPS "LUA_JIT-postbuild_exp") endif() if (BUILD_LUA_AS_DLL) if (MSVC) - MESSAGE(STATUS ${LUA_JIT_SOURCE_LUA_IMP_LIB}) - MESSAGE(STATUS ${LUA_JIT_DESTINATION_LUA_IMP_LIB}) ExternalProject_Add_Step(LUA_JIT - postbuild.import.lib + postbuild_import_lib DEPENDEES build COMMENT "Libray - Moving \"${LUA_JIT_SOURCE_LUA_IMP_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_IMP_LIB}\"..." COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_IMP_LIB}" "${LUA_JIT_DESTINATION_LUA_IMP_LIB}" - COMMAND echo Successfully moved!) + BYPRODUCTS "${LUA_JIT_DESTINATION_LUA_IMP_LIB}") + ExternalProject_Add_StepTargets(LUA_JIT postbuild_import_lib) + list(APPEND LUA_JIT_EXTERNAL_PROJECT_DEPS "LUA_JIT-postbuild_import_lib") endif() - MESSAGE(STATUS ${LUA_JIT_SOURCE_LUA_DLL}) - MESSAGE(STATUS ${LUA_JIT_DESTINATION_LUA_DLL}) - MESSAGE(STATUS ${LUA_JIT_DLL_FILE}) ExternalProject_Add_Step(LUA_JIT - postbuild.dll + postbuild_dll DEPENDEES build COMMENT "Dynamic Library - Moving \"${LUA_JIT_SOURCE_LUA_DLL}\" to \"${LUA_JIT_DESTINATION_LUA_DLL}\"..." - COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_DLL}" "${LUA_JIT_DESTINATION_LUA_DLL}" && echo Successfully moved!) + COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_DLL}" "${LUA_JIT_DESTINATION_LUA_DLL}" + BYPRODUCTS "${LUA_JIT_DESTINATION_LUA_DLL}") + ExternalProject_Add_StepTargets(LUA_JIT postbuild_dll) + list(APPEND LUA_JIT_EXTERNAL_PROJECT_DEPS "LUA_JIT-postbuild_dll") else() ExternalProject_Add_Step(LUA_JIT - postbuild.lib + postbuild_lib DEPENDEES build COMMENT "Library - Moving \"${LUA_JIT_SOURCE_LUA_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_LIB}\"..." - COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_LIB}" "${LUA_JIT_DESTINATION_LUA_LIB}" && echo Successfully moved!) + COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_LIB}" "${LUA_JIT_DESTINATION_LUA_LIB}" + BYPRODUCTS "${LUA_JIT_DESTINATION_LUA_LIB}") + ExternalProject_Add_StepTargets(LUA_JIT postbuild_lib) + list(APPEND LUA_JIT_EXTERNAL_PROJECT_DEPS "LUA_JIT-postbuild_lib") endif() + ExternalProject_Add_Step(LUA_JIT - postbuild.exe + postbuild_exe DEPENDEES build COMMENT "Library - Moving \"${LUA_JIT_SOURCE_LUA_INTERPRETER}\" to \"${LUA_JIT_DESTINATION_LUA_INTERPRETER}\"..." - COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_INTERPRETER}" "${LUA_JIT_DESTINATION_LUA_INTERPRETER}" && echo Successfully moved!) + COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_INTERPRETER}" "${LUA_JIT_DESTINATION_LUA_INTERPRETER}" + BYPRODUCTS "${LUA_JIT_DESTINATION_LUA_INTERPRETER}") +ExternalProject_Add_StepTargets(LUA_JIT postbuild_exe) +list(APPEND LUA_JIT_EXTERNAL_PROJECT_DEPS "LUA_JIT-postbuild_exe") + # # TODO: # Add additional post-build step to move all necessary headers/lua files # for now, we just point directly to the `src` directory... @@ -333,18 +347,15 @@ ExternalProject_Add_Step(LUA_JIT # # Lua Library add_library(${lualib} ${LUA_BUILD_LIBRARY_TYPE} IMPORTED) # make sure the library we export really does depend on Lua JIT's external project -add_dependencies(${lualib} LUA_JIT) +add_dependencies(${lualib} LUA_JIT ${LUA_JIT_EXTERNAL_PROJECT_DEPS}) if (BUILD_LUA_AS_DLL) if (MSVC) set_target_properties(${lualib} PROPERTIES IMPORTED_IMPLIB "${LUA_JIT_IMP_LIB_FILE}") endif() - MESSAGE(STATUS "${LUA_JIT_DLL_FILE}") - MESSAGE(STATUS "${LUA_JIT_DESTINATION_LUA_DLL}") set_target_properties(${lualib} PROPERTIES - #IMPORTED_SONAME "${LUA_BUILD_LIBNAME}" IMPORTED_LOCATION "${LUA_JIT_DLL_FILE}") else () set_target_properties(${lualib} diff --git a/cmake/Modules/FindLuaBuild/LuaVanilla.cmake b/cmake/Modules/FindLuaBuild/LuaVanilla.cmake index 5f373a04..ce1ac3c3 100644 --- a/cmake/Modules/FindLuaBuild/LuaVanilla.cmake +++ b/cmake/Modules/FindLuaBuild/LuaVanilla.cmake @@ -295,7 +295,7 @@ if (MSVC) PRIVATE /W1) else() target_compile_options(${liblua} - PRIVATE -w -Wno-implicit-fallthrough) + PRIVATE -w) endif() if (WIN32) #target_compile_definitions(${liblua} @@ -332,6 +332,9 @@ target_compile_definitions(${luainterpreter} if (MSVC) target_compile_options(${luainterpreter} PRIVATE /W1) +else() + target_compile_options(${luainterpreter} + PRIVATE -w) endif() if (WIN32) #target_compile_definitions(${luainterpreter} @@ -373,6 +376,9 @@ target_compile_definitions(${luacompiler} if (MSVC) target_compile_options(${luacompiler} PRIVATE /W1) +else() + target_compile_options(${luacompiler} + PRIVATE -w) endif() if (WIN32) #target_compile_definitions(${luacompiler} diff --git a/cmake/Modules/FindToLuappBuild.cmake b/cmake/Modules/FindToLuappBuild.cmake index 12502146..8c08b7b9 100644 --- a/cmake/Modules/FindToLuappBuild.cmake +++ b/cmake/Modules/FindToLuappBuild.cmake @@ -33,7 +33,7 @@ set(toluapp_build_toplevel "${CMAKE_BINARY_DIR}/vendor/toluapp_${toluapp_version set(toluapp_include_dirs "${toluapp_build_toplevel}/include") # # ToLua library sources -set(toluapp_sources tolua_event.c tolua_event.h tolua_is.c tolua_map.c tolua_push.c tolua_to.c) +set(toluapp_sources tolua_event.c tolua_event.h tolua_is.c tolua_map.c tolua_push.c tolua_to.c tolua_compat.h tolua_compat.c) prepend(toluapp_sources "${toluapp_build_toplevel}/src/lib/" ${toluapp_sources}) list(APPEND toluapp_sources "${toluapp_build_toplevel}/include/tolua++.h") @@ -44,7 +44,7 @@ ExternalProject_Add(TOLUAPP_BUILD_SOURCE # # Use Git to get what we need #GIT_SUBMODULES "" GIT_SHALLOW TRUE - GIT_REPOSITORY https://github.com/waltervn/toluapp.git + GIT_REPOSITORY https://github.com/ThePhD/toluapp PREFIX ${toluapp_build_toplevel} SOURCE_DIR ${toluapp_build_toplevel} DOWNLOAD_DIR ${toluapp_build_toplevel} @@ -65,7 +65,7 @@ set_target_properties(${toluapp_lib} PROPERTIES POSITION_INDEPENDENT_CODE TRUE) target_include_directories(${toluapp_lib} PUBLIC ${toluapp_include_dirs}) -target_link_libraries(${toluapp_lib} ${LUA_LIBRARIES}) +target_link_libraries(${toluapp_lib} PRIVATE ${LUA_LIBRARIES}) if (MSVC) target_compile_options(${toluapp_lib} PRIVATE /W1) @@ -77,6 +77,9 @@ else() INTERFACE -Wno-noexcept-type PUBLIC -Wno-ignored-qualifiers -Wno-unused-parameter) endif() +# add compatibility define +target_compile_definitions(${toluapp_lib} + PRIVATE COMPAT53_PREFIX=toluapp_compat53) # # Variables required by ToLuaBuild set(TOLUAPP_LIBRARIES ${toluapp_lib}) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d5f3648c..696477b3 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -22,11 +22,11 @@ # # # sol2 Examples -# # require_from_dll example -# just add the subdirectory -add_subdirectory(require_dll_example) - if (INTEROP_EXAMPLES) + # # require_from_dll example + # just add the subdirectory + add_subdirectory(require_dll_example) + # # interop examples add_subdirectory(interop/kaguya) add_subdirectory(interop/tolua) diff --git a/examples/interop/LuaBridge/CMakeLists.txt b/examples/interop/LuaBridge/CMakeLists.txt index 12fac8b7..6d973951 100644 --- a/examples/interop/LuaBridge/CMakeLists.txt +++ b/examples/interop/LuaBridge/CMakeLists.txt @@ -31,6 +31,9 @@ function (make_luabridge_interop_example target_library is_single) endif(is_single) add_executable(${example_name} LuaBridge.cpp) target_link_libraries(${example_name} PUBLIC ${LUA_LIBRARIES} PRIVATE ${LUABRIDGE_LIBRARIES} ${target_library}) + if (CMAKE_DL_LIBS) + target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS}) + endif() if (NOT MSVC) target_compile_options(${example_name} PRIVATE -Wno-noexcept-type -Wignored-qualifiers -Wunused-parameter) endif() diff --git a/examples/interop/kaguya/CMakeLists.txt b/examples/interop/kaguya/CMakeLists.txt index 254fd002..4e8c0914 100644 --- a/examples/interop/kaguya/CMakeLists.txt +++ b/examples/interop/kaguya/CMakeLists.txt @@ -31,6 +31,9 @@ function (make_kaguya_interop_example target_library is_single) endif(is_single) add_executable(${example_name} kaguya.cpp) target_link_libraries(${example_name} PUBLIC ${LUA_LIBRARIES} PRIVATE ${KAGUYA_LIBRARIES} ${target_library}) + if (CMAKE_DL_LIBS) + target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS}) + endif() if (NOT MSVC) target_compile_options(${example_name} PRIVATE -Wno-noexcept-type) endif() diff --git a/examples/interop/kaguya/kaguya.cpp b/examples/interop/kaguya/kaguya.cpp index 1849f5c8..627987e1 100644 --- a/examples/interop/kaguya/kaguya.cpp +++ b/examples/interop/kaguya/kaguya.cpp @@ -1,9 +1,9 @@ +#include + #define SOL_CHECK_ARGUMENTS 1 #define SOL_ENABLE_INTEROP 1 // MUST be defined to use interop features #include -#include - #include #include "../../assert.hpp" diff --git a/examples/interop/luwra/CMakeLists.txt b/examples/interop/luwra/CMakeLists.txt index 3ff36a4a..b264a461 100644 --- a/examples/interop/luwra/CMakeLists.txt +++ b/examples/interop/luwra/CMakeLists.txt @@ -31,6 +31,9 @@ function (make_luwra_interop_example target_library is_single) endif(is_single) add_executable(${example_name} luwra.cpp) target_link_libraries(${example_name} PUBLIC ${LUA_LIBRARIES} PRIVATE ${LUWRA_LIBRARIES} ${target_library}) + if (CMAKE_DL_LIBS) + target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS}) + endif() if (NOT MSVC) target_compile_options(${example_name} PRIVATE -Wno-noexcept-type) endif() diff --git a/examples/interop/tolua/CMakeLists.txt b/examples/interop/tolua/CMakeLists.txt index b1051dd4..71592723 100644 --- a/examples/interop/tolua/CMakeLists.txt +++ b/examples/interop/tolua/CMakeLists.txt @@ -31,6 +31,9 @@ function(make_tolua_interop_example target_library is_single) endif() add_executable(${example_name} tolua.cpp) target_link_libraries(${example_name} PUBLIC ${LUA_LIBRARIES} PRIVATE ${TOLUAPP_LIBRARIES} ${target_library}) + if (CMAKE_DL_LIBS) + target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS}) + endif() if (NOT MSVC) target_compile_options(${example_name} PRIVATE -Wno-noexcept-type -Wno-unused-function -Wno-pedantic) endif() diff --git a/examples/require_dll_example/CMakeLists.txt b/examples/require_dll_example/CMakeLists.txt index a2825674..30744e28 100644 --- a/examples/require_dll_example/CMakeLists.txt +++ b/examples/require_dll_example/CMakeLists.txt @@ -38,8 +38,9 @@ function(make_require_from_dll_example target_lib is_single) endif() # is the lua library a shared or static library? - get_target_property(lua_lib_type ${LUA_LIBRARIES} TYPE) - + list(GET LUA_LIBRARIES 0 lua_lib_target) + get_target_property(lua_lib_type ${lua_lib_target} TYPE) + # 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 @@ -83,7 +84,9 @@ function(make_require_from_dll_example target_lib is_single) target_link_libraries(${example_name} PRIVATE my_object ${target_lib}) # avoid multiply defined references due to linking in the same static library # twice over, and get "multiple definition" errors during linking - # target_link_libraries(${example_name} PRIVATE ${LUA_LIBRARIES}) + if (NOT lua_lib_type MATCHES "STATIC") + target_link_libraries(${example_name} PRIVATE ${LUA_LIBRARIES}) + endif() target_include_directories(${example_name} PRIVATE ${LUA_INCLUDE_DIRS}) if (TESTS_EXAMPLES)