From 4315f96a3bcf40153d0e9b19992c8514ea53002d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 6 Dec 2015 12:04:59 +0000 Subject: Start generating MSVC project files using CMake. Update getversion.pl to work when run from CMake. Update modules.txt to give our CMake configuration the necessary dependency information. --- infrastructure/cmake/.gitignore | 6 +++ infrastructure/cmake/CMakeLists.txt | 78 +++++++++++++++++++++++++++++++++---- infrastructure/msvc/getversion.pl | 3 +- modules.txt | 14 +++---- 4 files changed, 85 insertions(+), 16 deletions(-) create mode 100644 infrastructure/cmake/.gitignore diff --git a/infrastructure/cmake/.gitignore b/infrastructure/cmake/.gitignore new file mode 100644 index 00000000..b27d6b9f --- /dev/null +++ b/infrastructure/cmake/.gitignore @@ -0,0 +1,6 @@ +*.vcxproj +*.vcxproj.filters +BoxBackup.sln +CMakeCache.txt +CMakeFiles +cmake_install.cmake diff --git a/infrastructure/cmake/CMakeLists.txt b/infrastructure/cmake/CMakeLists.txt index f1a02252..e47ccd5a 100644 --- a/infrastructure/cmake/CMakeLists.txt +++ b/infrastructure/cmake/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.6) project(BoxBackup) -set(base_dir ../..) +set(base_dir ${CMAKE_SOURCE_DIR}/../..) set(files_to_configure infrastructure/BoxPlatform.pm @@ -47,7 +47,8 @@ foreach(file_to_configure ${files_to_configure}) endforeach() file(STRINGS ${base_dir}/modules.txt module_deps REGEX "^[^#]") -foreach(module_dep ${module_deps}) +# qdbm, lib/common and lib/win32 aren't listed in modules.txt, so hard-code them. +foreach(module_dep "qdbm" "lib/win32" "lib/common lib/win32" ${module_deps}) string(REGEX MATCH "([^ ]+)[ ]*(.*)" valid_module_line ${module_dep}) if(valid_module_line) if(DEBUG) @@ -57,16 +58,23 @@ foreach(module_dep ${module_deps}) set(module_dir ${base_dir}/${CMAKE_MATCH_1}) string(REPLACE "/" "_" module_name ${CMAKE_MATCH_1}) string(REPLACE "/" "_" dependencies "${CMAKE_MATCH_2}") + file(GLOB module_files ${module_dir}/*.c ${module_dir}/*.cpp) + + # everything except lib/common and lib/win32 implicitly depend on + # lib/common, so express that dependency here. + if(module_name MATCHES "^lib_(common|win32)$") + else() + set(dependencies "${dependencies} lib_common") + endif() string(REGEX REPLACE "^ " "" dependencies "${dependencies}") string(REGEX REPLACE " $" "" dependencies "${dependencies}") - file(GLOB module_files ${module_dir}/*.c ${module_dir}/*.cpp) if(module_name MATCHES "^(bin|test)_") if(DEBUG) message(STATUS "add executable '${module_name}': '${module_files}'") endif() add_executable(${module_name} ${module_files}) - elseif(module_name MATCHES "^lib_") + elseif(module_name MATCHES "^(lib_.*|qdbm)$") if(DEBUG) message(STATUS "add library '${module_name}': '${module_files}'") endif() @@ -75,9 +83,65 @@ foreach(module_dep ${module_deps}) message(FATAL_ERROR "Unsupported module type: " ${module_dir}) endif() - if(DEBUG) - message(STATUS "add dependencies to '${module_name}': '${dependencies}'") + if(dependencies MATCHES ".") + if(DEBUG) + message(STATUS "add dependencies to '${module_name}': '${dependencies}'") + endif() + string(REGEX REPLACE "[ ]+" ";" dependency_list "${dependencies}") + foreach(dependency ${dependency_list}) + add_dependencies(${module_name} ${dependency}) + if(dependency MATCHES "^lib_") + target_link_libraries(${module_name} PUBLIC ${dependency}) + endif() + endforeach() endif() - target_link_libraries(${module_name} ${dependencies}) + + target_include_directories(${module_name} PUBLIC ${module_dir}) endif() endforeach() + +# Parsing Makefile.extra files in CMake script is a pain, so the relevant rules are +# hard-coded here. +set(exception_files + lib/backupclient/ClientException.txt + lib/backupstore/BackupStoreException.txt + lib/common/CommonException.txt + lib/common/ConversionException.txt + lib/compress/CompressException.txt + lib/crypto/CipherException.txt + lib/httpserver/HTTPException.txt + lib/raidfile/RaidFileException.txt + lib/server/ServerException.txt + lib/server/ConnectionException.txt +) + +include(FindPerl) + +execute_process( + COMMAND ${PERL_EXECUTABLE} ${base_dir}/infrastructure/msvc/getversion.pl + RESULT_VARIABLE status + OUTPUT_VARIABLE command_output + ERROR_VARIABLE command_output) +if(NOT status EQUAL 0) + message(FATAL_ERROR "Failed to execute: " + "${PERL_EXECUTABLE} ${base_dir}/infrastructure/msvc/getversion.pl: " + "status ${status}: ${command_output}") +endif() + +foreach(exception_file ${exception_files}) + string(REGEX MATCH "(.*)/(.*)" valid_exception_file ${exception_file}) + if(NOT valid_exception_file) + message(FATAL_ERROR "invalid exception file: '${exception_file}'") + endif() + + execute_process( + COMMAND ${PERL_EXECUTABLE} ${base_dir}/lib/common/makeexception.pl ${CMAKE_MATCH_2} + WORKING_DIRECTORY "${base_dir}/${CMAKE_MATCH_1}" + RESULT_VARIABLE status) + if(NOT status EQUAL 0) + message(FATAL_ERROR "Failed to execute: " + "${PERL_EXECUTABLE} ${base_dir}/lib/common/makeexception.pl ${CMAKE_MATCH_2}" + "(in ${CMAKE_MATCH_1}): ${status}") + endif() +endforeach() + diff --git a/infrastructure/msvc/getversion.pl b/infrastructure/msvc/getversion.pl index 0cf9cbcb..fe958831 100644 --- a/infrastructure/msvc/getversion.pl +++ b/infrastructure/msvc/getversion.pl @@ -1,8 +1,7 @@ #!perl $basedir = $0; -$basedir =~ s/\\[^\\]*$//; -$basedir =~ s/\\[^\\]*$//; +$basedir =~ s|/|\\|g; $basedir =~ s/\\[^\\]*$//; $basedir =~ s/\\[^\\]*$//; $basedir =~ s/\\[^\\]*$//; diff --git a/modules.txt b/modules.txt index 09cee59b..e0e2afce 100644 --- a/modules.txt +++ b/modules.txt @@ -28,19 +28,19 @@ test/basicserver qdbm lib/server lib/backupstore lib/server lib/raidfile lib/crypto lib/compress lib/httpserver lib/backupclient lib/backupstore -bin/bbackupobjdump lib/backupclient lib/backupstore -bin/bbstored lib/raidfile lib/server lib/backupstore -bin/bbstoreaccounts lib/raidfile lib/backupstore -bin/bbackupd lib/server lib/backupclient qdbm -bin/bbackupquery lib/server lib/backupclient -bin/bbackupctl bin/bbackupd +bin/bbackupobjdump lib/backupstore +bin/bbstored lib/backupstore +bin/bbstoreaccounts lib/backupclient +bin/bbackupd lib/backupclient qdbm +bin/bbackupquery lib/backupclient +bin/bbackupctl lib/backupclient qdbm test/backupstore bin/bbstored bin/bbstoreaccounts lib/server lib/backupstore lib/backupclient lib/raidfile test/backupstorefix bin/bbstored bin/bbstoreaccounts lib/backupstore lib/raidfile bin/bbackupquery bin/bbackupd bin/bbackupctl test/backupstorepatch bin/bbstored bin/bbstoreaccounts lib/backupclient test/backupdiff lib/backupclient test/bbackupd bin/bbackupd bin/bbstored bin/bbstoreaccounts bin/bbackupquery bin/bbackupctl lib/server lib/backupstore lib/backupclient lib/intercept -test/s3store lib/backupclient lib/httpserver bin/s3simulator +test/s3store lib/backupclient lib/httpserver bin/s3simulator bin/bbstoreaccounts # HTTP server system lib/httpserver lib/server -- cgit v1.2.3