Windows下编译PureMVC-C++

6 篇文章 2 订阅

PureMVC是一套轻量级的MVC开发框架,最初支持ActionScript 3语言,目前已经移植到18种编程语言,PureMVC包括两个版本:标准版和多核版。

由于PureMVC对应的VS构建项目仅支持到VS 2010,同时考虑到目前CMake已然成为跨平台软件构建的首选方案。因此,本文探讨在WIndows下使用CMake构建VS 2019项目。

一、下载代码

从GitHub上拉取puremvc-cpp-multicore-framework代码,

git clone https://github.com/PureMVC/puremvc-cpp-multicore-framework.git
git checkout -b 1.1.0 1.1.0

二、编译PureMVC

在puremvc-cpp-multicore-framework目录下新建CMakeLists.txt文件,添加以下内容,

# Helper to create filters in VS
MACRO(SOURCE_GROUP_BY_DIR source_files)
    IF(MSVC)
        SET(sgbd_cur_dir ${CMAKE_CURRENT_SOURCE_DIR})
        FOREACH(sgbd_file ${${source_files}})
            STRING(REGEX REPLACE ${sgbd_cur_dir}/\(.*\) \\1 sgbd_fpath ${sgbd_file})
            STRING(REGEX REPLACE "\(.*\)/.*" \\1 sgbd_group_name ${sgbd_fpath})
            STRING(COMPARE EQUAL ${sgbd_fpath} ${sgbd_group_name} sgbd_nogroup)
            STRING(REPLACE "/" "\\" sgbd_group_name ${sgbd_group_name})
            IF(sgbd_nogroup)
                set(sgbd_group_name "\\")
            ENDIF(sgbd_nogroup)
            SOURCE_GROUP(${sgbd_group_name} FILES ${sgbd_file})
        ENDFOREACH(sgbd_file)
    ENDIF(MSVC)
ENDMACRO(SOURCE_GROUP_BY_DIR)

# PureMVC
SET(LIB_NAME PureMVC)

# The include/PureMVC directory
SET(PureMVC_INCLUDE_DIR
	"include/PureMVC"
)

# The src/PureMVC directory
SET(PureMVC_SRC_DIR
	"src/PureMVC"
)

INCLUDE_DIRECTORIES(
	${CMAKE_CURRENT_SOURCE_DIR}
	${CMAKE_CURRENT_BINARY_DIR}
	"${CMAKE_CURRENT_SOURCE_DIR}/include"
)

LINK_DIRECTORIES(
	${CMAKE_LIBRARY_PATH}
	${PROJECT_BINARY_DIR}/lib
)

SET(PureMVC_LIBS
)

# Core
SET(PureMVC_Core_SRCS
	${PureMVC_INCLUDE_DIR}/Core/Controller.hpp
	${PureMVC_INCLUDE_DIR}/Core/Model.hpp
	${PureMVC_INCLUDE_DIR}/Core/View.hpp
	${PureMVC_SRC_DIR}/Core/Controller.cpp
	${PureMVC_SRC_DIR}/Core/Model.cpp
	${PureMVC_SRC_DIR}/Core/View.cpp		
)

# Interfaces
SET(PureMVC_Interfaces_SRCS
	${PureMVC_INCLUDE_DIR}/Interfaces/IAggregate.hpp
	${PureMVC_INCLUDE_DIR}/Interfaces/ICommand.hpp
	${PureMVC_INCLUDE_DIR}/Interfaces/IController.hpp
	${PureMVC_INCLUDE_DIR}/Interfaces/IFacade.hpp
	${PureMVC_INCLUDE_DIR}/Interfaces/IIterator.hpp
	${PureMVC_INCLUDE_DIR}/Interfaces/IMediator.hpp
	${PureMVC_INCLUDE_DIR}/Interfaces/IModel.hpp
	${PureMVC_INCLUDE_DIR}/Interfaces/INotification.hpp	
	${PureMVC_INCLUDE_DIR}/Interfaces/INotifier.hpp
	${PureMVC_INCLUDE_DIR}/Interfaces/IObserver.hpp
	${PureMVC_INCLUDE_DIR}/Interfaces/IProxy.hpp	
	${PureMVC_INCLUDE_DIR}/Interfaces/IView.hpp		
)

# Patterns
SET(PureMVC_Patterns_Command_SRCS
	${PureMVC_INCLUDE_DIR}/Patterns/Command/DelegateCommand.hpp
	${PureMVC_INCLUDE_DIR}/Patterns/Command/MacroCommand.hpp
	${PureMVC_INCLUDE_DIR}/Patterns/Command/SimpleCommand.hpp
	${PureMVC_SRC_DIR}/Patterns/Command/MacroCommand.cpp
	${PureMVC_SRC_DIR}/Patterns/Command/SimpleCommand.cpp	
)

SET(PureMVC_Patterns_Facade_SRCS
	${PureMVC_INCLUDE_DIR}/Patterns/Facade/Facade.hpp
	${PureMVC_SRC_DIR}/Patterns/Facade/Facade.cpp	
)

SET(PureMVC_Patterns_Iterator_SRCS
	${PureMVC_INCLUDE_DIR}/Patterns/Iterator/Iterator.hpp	
)

SET(PureMVC_Patterns_Mediator_SRCS	
	${PureMVC_INCLUDE_DIR}/Patterns/Mediator/Mediator.hpp		
	${PureMVC_SRC_DIR}/Patterns/Mediator/Mediator.cpp
)

SET(PureMVC_Patterns_Observer_SRCS
	${PureMVC_INCLUDE_DIR}/Patterns/Observer/Notification.hpp
	${PureMVC_INCLUDE_DIR}/Patterns/Observer/Notifier.hpp	
	${PureMVC_INCLUDE_DIR}/Patterns/Observer/Observer.hpp
	${PureMVC_SRC_DIR}/Patterns/Observer/Notification.cpp	
	${PureMVC_SRC_DIR}/Patterns/Observer/Notifier.cpp
)

SET(PureMVC_Patterns_Proxy_SRCS
	${PureMVC_INCLUDE_DIR}/Patterns/Proxy/Proxy.hpp
	${PureMVC_SRC_DIR}/Patterns/Proxy/Proxy.cpp
)

SET(PureMVC_Patterns_SRCS
	${PureMVC_Patterns_Command_SRCS}	
	${PureMVC_Patterns_Facade_SRCS}
	${PureMVC_Patterns_Iterator_SRCS}
	${PureMVC_Patterns_Mediator_SRCS}
	${PureMVC_Patterns_Observer_SRCS}	
	${PureMVC_Patterns_Proxy_SRCS}
)

# Resource Files
SET(PureMVC_RES_SRCS
	${PureMVC_SRC_DIR}/Resource/PureMVC.rc
)

SET(PureMVC_SRCS
	${PureMVC_Core_SRCS}
	${PureMVC_Interfaces_SRCS}
	${PureMVC_Patterns_SRCS}
	${PureMVC_RES_SRCS}
	${PureMVC_INCLUDE_DIR}/PureMVC.hpp
	${PureMVC_SRC_DIR}/PureMVC.cpp
	${PureMVC_SRC_DIR}/Common.hpp
)

source_group_by_dir(PureMVC_SRCS)


IF (MSVC)
    # Turn off deprecation warnings
    ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
    ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_WARNINGS)
	# Export PureMVC class symbols
	ADD_DEFINITIONS(-DPUREMVC_API_EXPORT)
ENDIF(MSVC)

ADD_LIBRARY(${LIB_NAME} STATIC ${PureMVC_SRCS})
TARGET_LINK_LIBRARIES(${LIB_NAME} ${PureMVC_LIBS})

IF (MSVC)
	# Runtime Library: -DMDd, -DMD
	ADD_LIBRARY(${LIB_NAME}dll SHARED ${PureMVC_SRCS})
	TARGET_LINK_LIBRARIES(${LIB_NAME}dll ${PureMVC_LIBS})

	SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES DEBUG_OUTPUT_NAME PureMVCd.dll  RELEASE_OUTPUT_NAME PureMVC.dll)
	SET_TARGET_PROPERTIES(${LIB_NAME}dll PROPERTIES DEBUG_OUTPUT_NAME PureMVCddll.dll  RELEASE_OUTPUT_NAME PureMVCdll.dll)
ENDIF(MSVC)

# Install
SET(INSTALL_INCDIR include)
SET(INSTALL_BINDIR bin)
IF(WIN32)
    SET(INSTALL_LIBDIR bin)
    SET(INSTALL_ARCHIVEDIR lib)
ELSE(WIN32)
    SET(INSTALL_LIBDIR lib${LIB_POSTFIX})
    SET(INSTALL_ARCHIVEDIR lib${LIB_POSTFIX})
ENDIF(WIN32)

INSTALL(
    TARGETS ${LIB_NAME}
    RUNTIME DESTINATION ${INSTALL_BINDIR}
    LIBRARY DESTINATION ${INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${INSTALL_ARCHIVEDIR}
)

INSTALL(
    FILES       ${HEADERS}
    DESTINATION ${INSTALL_INCDIR}/${LIB_NAME}
)

然后,使用CMake完成PureMVC的构建,在VS 2019中编译即可。

三、生成文档

下载并安装DoxgenMikTex,按照下述CMakeLists.txt构建PureMVC Doc项目,从而生成PureMVC文档。

# add a target to generate API documentation with Doxygen
#FIND_PACKAGE(Doxygen)
#OPTION(BUILD_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND})

IF(BUILD_DOCUMENTATION)
	FIND_PACKAGE(Doxygen)
    IF(NOT DOXYGEN_FOUND)
        MESSAGE(FATAL_ERROR "Doxygen is needed to build the documentation.")
    ENDIF()

    SET(DOXYGEN_IN ${CMAKE_CURRENT_LIST_DIR}/Doxyfile.in)
    SET(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

    # request to configure the file
    CONFIGURE_FILE(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)

    # note the option ALL which allows to build the docs together with the application
    ADD_CUSTOM_TARGET(Doc ALL
        COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Generating API documentation with Doxygen"
        VERBATIM)

    #INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
	INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION doc)
ENDIF()

参考资料

PureMVChttp://puremvc.org/

puremvc-cpp-multicore-frameworkhttps://github.com/PureMVC/puremvc-cpp-multicore-framework

 Doxygenhttps://www.doxygen.org/

MikTex http://www.miktex.org

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值