# # This is a CMake makefile. CMake is a tool that helps you build C++ programs. # You can download CMake from http://www.cmake.org. This CMakeLists.txt file # you are reading builds dlib's example programs. # # To compile this program all you need to do is ask cmake. You would type # these commands from within the directory containing this CMakeLists.txt # file: # mkdir build # cd build # cmake .. # cmake --build . --config Release # # The cmake .. command looks in the parent folder for a file named # CMakeLists.txt, reads it, and sets up everything needed to build program. # Also, note that CMake can generate Visual Studio or XCode project files. So # if instead you had written: # cd build # cmake .. -G Xcode # # You would be able to open the resulting Xcode project and compile and edit # the example programs within the Xcode IDE. CMake can generate a lot of # different types of IDE projects. Run the cmake -h command to see a list of # arguments to -G to see what kinds of projects cmake can generate for you. It # probably includes your favorite IDE in the list. cmake_minimum_required (VERSION 3.8) project(RvcFramework) set(CMAKE_CXX_STANDARD 11) option(BUILD_TESTING "Build the project tests." ON) option(INSTALL_INCLUDE_FILES "Enable installation of include header file or third_party" OFF) set(BUILD_NUMBER 0) if ($ENV{BUILD_NUMBER}) set(BUILD_NUMBER $ENV{BUILD_NUMBER}) endif() set(RVC_COMPANY "CMB" CACHE STRING "China Merchants Bank") set(RVC_PRODUCT "VTM") set(RVC_AUTHOR "CCDG") set(RVC_COPYRIGHT "Copyright (C) 2020") set(RVC_DESCRIPTION "2020.01") set(RAW_VERSION_STRING "0.0.1-dev1") string(STRIP ${RAW_VERSION_STRING} RAW_VERSION_STRING) set(VERSION_REGEX "^.?([0-9]+)\\.([0-9]+)\\.([0-9]+)-?(.*)") string(REGEX REPLACE "${VERSION_REGEX}" "\\1" RVC_VERSION_MAJOR "${RAW_VERSION_STRING}") string(REGEX REPLACE "${VERSION_REGEX}" "\\2" RVC_VERSION_MINOR "${RAW_VERSION_STRING}") string(REGEX REPLACE "${VERSION_REGEX}" "\\3" RVC_VERSION_REVISION "${RAW_VERSION_STRING}") string(REGEX REPLACE "${VERSION_REGEX}" "\\4" RVC_VERSION_SUFFIX "${RAW_VERSION_STRING}") set(RVC_VERSION_BUILD "${BUILD_NUMBER}") set(RVC_API_VERSION "${RVC_VERSION_MAJOR}") set(RVC_VERSION "${RVC_VERSION_MAJOR}.${RVC_VERSION_MINOR}.${RVC_VERSION_REVISION}.${RVC_VERSION_BUILD}") set(RVC_FRAMEWORK_VERSION "${RVC_VERSION_MAJOR}.${RVC_VERSION_MINOR}.${RVC_VERSION_REVISION}") if (RVC_VERSION_SUFFIX) set(RVC_VERSION_FULL "${RVC_VERSION}-${RVC_VERSION_SUFFIX}") else() set(RVC_VERSION_FULL "${RVC_VERSION}") endif() message("RVC_VERSION=${RVC_VERSION_FULL}") configure_file("${PROJECT_SOURCE_DIR}/version.h.in" "${PROJECT_BINARY_DIR}/version.h") include_directories(${PROJECT_BINARY_DIR}) # 设置生成文件的存放路径 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) if(BUILD_TESTING) include(CTest) message(STATUS "build the tests.") enable_testing() set(GTEST_ROOT "${CMAKE_SOURCE_DIR}/third_party/gtest/googletest/include") set(GMOCK_ROOT "${CMAKE_SOURCE_DIR}/third_party/gtest/googlemock/include") if(MSVC) set(TESTING_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") else() set(TESTING_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Testing") endif() endif() # specifies what build type (configuration) will be built in this build tree if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Debug") endif() # Turn on solution folders (2.8.4+) set_property(GLOBAL PROPERTY USE_FOLDERS ON) # 在 Windows 下用 "/" 会报错 STRING(REGEX REPLACE "^([A-Z]*.)([/\\].*)" "\\1" CURRENT_DISK "${CMAKE_CURRENT_SOURCE_DIR}") # message(STATUS "current disk: ${CURRENT_DISK}") set(OUTPUT_VERSION_PATH "${CURRENT_DISK}\\run\\version\\${RVC_VERSION}") # message(STATUS "current OUTPUT_VERSION_PATH: ${OUTPUT_VERSION_PATH}") # 如果使用绝对路径,会导致 CPack 因 CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION 失败 # set(RVC_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/include") # set(RVC_LIBRARY_PATH "${CMAKE_INSTALL_LIBDIR}") # set(RVC_RUNTIME_PATH "${CMAKE_INSTALL_BINDIR}") # set(RVC_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/bin") set(RVC_INCLUDE_PATH "include") set(RVC_LIBRARY_PATH "lib") set(RVC_RUNTIME_PATH "bin") set(RVC_MODULE_PATH "mod") set(RVC_CONFIG_PATH "cfg") set(RVC_VENDOR_PATH "dep") # set(RVC_MODULE_LIBRARY_PATH "${CMAKE_BINARY_DIR}/mod") macro(copy_output_on_build module_name output_subdir) set(target_name ${module_name}) set(output_dir ${OUTPUT_VERSION_PATH}\\${output_subdir}) if(NOT EXISTS ${output_dir} OR NOT IS_DIRECTORY ${output_dir}) # nothing to do. endif() add_custom_command(TARGET ${target_name} PRE_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E make_directory ${output_dir}) add_custom_command(TARGET ${target_name} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${OUTPUT_VERSION_PATH}/${output_subdir} ) endmacro(copy_output_on_build) if (CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_CONFIGURATION_TYPES STREQUAL Debug) message(STATUS "debug type") set(BUILD_TYPE_NAME "Debug") else() set(BUILD_TYPE_NAME "Release") endif() string(TOLOWER ${BUILD_TYPE_NAME} BUILD_TYPE_NAME_lower) if(${CMAKE_GENERATOR} MATCHES "Visual Studio*") if(NOT CMAKE_GENERATOR_PLATFORM) message(STATUS "set win32 platform default") set(CMAKE_GENERATOR_PLATFORM "Win32") else() message(STATUS ${CMAKE_GENERATOR_PLATFORM}) endif() endif() set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_GENERATOR_PLATFORM}-${BUILD_TYPE_NAME}") set(CPACK_TOPLEVEL_TAG "${CMAKE_SYSTEM_NAME}-${CMAKE_GENERATOR_PLATFORM}-${BUILD_TYPE_NAME}") if(WIN32) # dll rc version string(TIMESTAMP RC_VERSION_YEAR "%Y") set(RC_VERSION_AUTHOR ${RVC_AUTHOR}) set(RC_VERSION_COMPANY ${RVC_COMPANY}) set(RC_VERSION_PRODUCT ${RVC_PRODUCT}) set(RC_VERSION_PATCH ${BUILD_NUMBER}) set(RC_VERSION_DESCRIPTION "${RVC_VERSION_FULL} ${CPACK_SYSTEM_NAME}") endif(WIN32) if(BUILD_SHARED_LIBS) message(STATUS "build shared libs") endif(BUILD_SHARED_LIBS) include_directories(Common) add_subdirectory(third_party) add_subdirectory(libtoolkit) add_subdirectory(RvcComm) add_subdirectory(spbase) add_subdirectory(spshell) add_subdirectory(sphost) if(BUILD_TESTING) add_subdirectory(test) endif() # 安装 string(REPLACE "\\" "/" OUTPUT_VERSION_PATH ${OUTPUT_VERSION_PATH}) set(CMAKE_INSTALL_PREFIX "${OUTPUT_VERSION_PATH}") #set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install") # /${RVC_VERSION} set(CMAKE_INSTALL_LOCAL_ONLY ON) include(InstallRequiredSystemLibraries) # 打包 set(CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;/\\\\.gitignore;/CMakeCache.txt;/\\\\build;/\\\\out") string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_PROJECT_NAME_lower) set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME_lower}-${RVC_VERSION_FULL}-${CPACK_SYSTEM_NAME}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME_lower}-${RVC_VERSION_FULL}-${CPACK_SYSTEM_NAME}") # 设置软件包名 set(CPACK_PACKAGE_NAME "RvcFramework") set(CPACK_PACKAGE_VENDOR "RVC-CCDG") # 设置软件包版本 set(CPACK_PACKAGE_VERSION ${RVC_VERSION_FULL}) set(CPACK_PACKAGE_VERSION_MAJOR ${RVC_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${RVC_VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${RVC_VERSION_REVISION}) set(CPACK_COMPONENTS_ALL headers libraries) if(MSVC) if( NOT CPACK_GENERATOR) set(CPACK_GENERATOR "ZIP") message(STATUS "set zip package file type") endif() if(CPACK_GENERATOR MATCHES "NSIS") set(CPACK_PACKAGE_INSTALL_DIRECTORY "C:\\\\Run") endif() endif(MSVC) if(MSVC) if(MSVC_RUNTIME STREQUAL "dynamic") message(STATUS "dynamic format") # the INSTALL command is not called. The user can use the variable # CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS to use a custom install command and install them however they want. set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE) include(InstallRequiredSystemLibraries) install(PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION ${RVC_RUNTIME_PATH} COMPONENT libraries) else() include(InstallRequiredSystemLibraries) endif() endif() include(CPack) # 会直接复制文件夹 if(INSTALL_INCLUDE_FILES) install(DIRECTORY Common DESTINATION ${RVC_INCLUDE_PATH} COMPONENT headers FILES_MATCHING PATTERN "*.h") install(FILES "${PROJECT_BINARY_DIR}/version.h" DESTINATION "${RVC_INCLUDE_PATH}/Common" COMPONENT headers) endif() install(DIRECTORY "${CMAKE_SOURCE_DIR}/addin/${RVC_RUNTIME_PATH}" DESTINATION "." COMPONENT libraries) install(DIRECTORY "${CMAKE_SOURCE_DIR}/addin/${RVC_CONFIG_PATH}" DESTINATION "." COMPONENT configs FILES_MATCHING PATTERN "*.ini") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/addin/${RVC_CONFIG_PATH}/shell.ini.in" ${CMAKE_CURRENT_BINARY_DIR}/shell.ini @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/shell.ini DESTINATION ${RVC_CONFIG_PATH}) # if necessary # install(DIRECTORY ${CMAKE_SOURCE_DIR}/addin/mod DESTINATION ${RVC_MODULE_PATH} COMPONENT modules) # install(DIRECTORY ${CMAKE_SOURCE_DIR}/addin/dep DESTINATION ${RVC_VENDOR_PATH} COMPONENT vendors) # install(PROGRAMS "") install(CODE "message(\"install message start.\")") install(CODE "EXECUTE_PROCESS(COMMAND -E remove_directory \"${CMAKE_INSTALL_PREFIX}/${RVC_INCLUDE_PATH}\")") install(CODE "message(\"install message done.\")") # no used now function(package_static_libs output_library) get_target_property(libtype ${output_library} TYPE) if(NOT libtype STREQUAL "STATIC_LIBRARY" OR NOT libtype STREQUAL "EXECUTABLE ") message(FATAL_ERROR "can only process static library or execuate program.") endif() get_target_property(libfile ${output_library} LOCATION) endfunction()