编写了一下cmakelists.txt文件
根目录
cmake_minimum_required(VERSION 2.8)
project (Test)
add_definitions( "/W3 /D_CRT_SECURE_NO_WARNINGS /wd4819 /MTd" )
if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
MESSAGE( "64 bits compiler detected" )
SET( EX_PLATFORM 64 )
SET( EX_PLATFORM_NAME "x64" )
else( )
MESSAGE( "32 bits compiler detected" )
SET( EX_PLATFORM 32 )
SET( EX_PLATFORM_NAME "x86" )
endif( )
IF( EX_PLATFORM EQUAL 64 )
MESSAGE( "Outputting to lib64 and bin64" )
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib64)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib64)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin64)
ELSE( )
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
ENDIF( )
include_directories ("${PROJECT_SOURCE_DIR}")
include_directories ("E:/_codes/boost_1_55_0/boost_1_55_0")
include_directories ("E:/Program Files/Lua/5.1/include")
IF( EX_PLATFORM EQUAL 64 )
ELSE( )
link_directories ("E:/Program Files/Lua/5.1/lib")
ENDIF( )
set(CMAKE_MSVCIDE_RUN_PATH "E:/Program Files/Lua/5.1/lib"
)
set (EXTRA_LIBS ${EXTRA_LIBS} lua51.lib
)
if(MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")
endif()
macro(copy_dll depdir dllname)
foreach(configuration ${CMAKE_CONFIGURATION_TYPES})
# 对应于不同的构建版本
set(dllpath "${depdir}/bin/${configuration}/${dllname}")
if(EXISTS ${dllpath})
configure_file(${dllpath} ${CMAKE_BINARY_DIR}/bin/${configuration}/${dllname} COPYONLY)
endif()
endforeach()
endmacro()
macro (create_test target)
add_test (NAME ${target} COMMAND $<TARGET_FILE:${target}>)
#set_tests_properties(${target} PROPERTIES ENVIRONMENT "PATH=${PATH};${PATH_ENV}")
#add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/Table.h"
# COMMAND set "PATH=${PATH_ENV};%PATH%"
# COMMAND $<TARGET_FILE:${target}> "${CMAKE_CURRENT_BINARY_DIR}/Table.h"
# DEPENDS $<TARGET_FILE:${target}>)
endmacro (create_test)
ENABLE_TESTING()
add_subdirectory (src)
add_subdirectory (test)
srfcMulu
cmake_minimum_required(VERSION 2.8)
#include_directories ("${CMAKE_CURRENT_LIST_DIR}/include")
add_library(luabind SHARED
class.cpp
class_info.cpp
class_registry.cpp
class_rep.cpp
create_class.cpp
error.cpp
exception_handler.cpp
function.cpp
inheritance.cpp
link_compatibility.cpp
object_rep.cpp
open.cpp
pcall.cpp
scope.cpp
stack_content_by_name.cpp
weak_ref.cpp
wrapper_base.cpp
)
target_compile_definitions(luabind PRIVATE LUABIND_DYNAMIC_LINK LUABIND_BUILDING)
target_link_libraries (luabind ${EXTRA_LIBS})
test目录
cmake_minimum_required(VERSION 2.8)
#include_directories ("${CMAKE_CURRENT_LIST_DIR}/include")
add_executable(testHello
#benchmark.cpp
main.cpp
test_abstract_base.cpp
)
target_compile_definitions(testHello PRIVATE LUABIND_DYNAMIC_LINK)
create_test(testHello)
target_link_libraries (testHello luabind ${EXTRA_LIBS})
file(GLOB_RECURSE SRC_CORE test*.cpp)
foreach(the_file ${SRC_CORE})
get_filename_component (NAME ${the_file} NAME_WE)
MESSAGE( "NAME " ${NAME} )
add_executable(${NAME} main.cpp ${the_file} )
target_compile_definitions(${NAME} PRIVATE LUABIND_DYNAMIC_LINK)
create_test(${NAME})
target_link_libraries (${NAME} luabind ${EXTRA_LIBS})
endforeach(the_file)