From afe0d238281d83248d2611566fa672922bbf99ee Mon Sep 17 00:00:00 2001 From: Bill Katz Date: Fri, 1 Mar 2013 13:44:19 -0500 Subject: [PATCH] Add Ullrich Koethe's improvement ExternalProjectMultiPlatform from ilastik-build --- ExternalProjectMultiPlatform.cmake | 114 +++++++++++++++++++++++++ test_multi_platform/CMakeLists.txt | 54 ++++++++++++ test_multi_platform/foo/CMakeLists.txt | 4 + test_multi_platform/foo/foo.cxx | 0 4 files changed, 172 insertions(+) create mode 100644 ExternalProjectMultiPlatform.cmake create mode 100644 test_multi_platform/CMakeLists.txt create mode 100644 test_multi_platform/foo/CMakeLists.txt create mode 100644 test_multi_platform/foo/foo.cxx diff --git a/ExternalProjectMultiPlatform.cmake b/ExternalProjectMultiPlatform.cmake new file mode 100644 index 0000000..253e596 --- /dev/null +++ b/ExternalProjectMultiPlatform.cmake @@ -0,0 +1,114 @@ +include(ExternalProject) + +FUNCTION(ExternalProject_AddMultiPlatform name) + SET(keywords + #--General-------------- + DEPENDS PREFIX LIST_SEPARATOR TMP_DIR STAMP_DIR + #--Download step-------------- + DOWNLOAD_DIR DOWNLOAD_COMMAND + CVS_REPOSITORY CVS_MODULE CVS_TAG + SVN_REPOSITORY SVN_REVISION SVN_USERNAME SVN_PASSWORD SVN_TRUST_CERT + GIT_REPOSITORY GIT_TAG + URL URL_MD5 TIMEOUT + #--Update/Patch step---------- + UPDATE_COMMAND PATCH_COMMAND + #--Configure step------------- + SOURCE_DIR CONFIGURE_COMMAND CMAKE_COMMAND CMAKE_GENERATOR CMAKE_ARGS CMAKE_CACHE_ARGS + #--Build step----------------- + BINARY_DIR BUILD_COMMAND BUILD_IN_SOURCE + #--Install step--------------- + INSTALL_DIR INSTALL_COMMAND + #--Test step------------------ + TEST_BEFORE_INSTALL TEST_AFTER_INSTALL TEST_COMMAND + #--Output logging------------- + LOG_DOWNLOAD LOG_UPDATE LOG_CONFIGURE LOG_BUILD LOG_TEST LOG_INSTALL + #--Custom targets------------- + STEP_TARGETS + ) + + # build the regular expression to identify keywords and + # initialize all keywords to "NOT_SPECIFIED" + SET(keywords_re) + foreach(i ${keywords}) + SET(${i} "NOT_SPECIFIED") + if(NOT keywords_re) + SET(keywords_re "^(PLATFORM|UNSUPPORTED|${i}") + else() + SET(keywords_re "${keywords_re}|${i}") + endif() + endforeach(i) + SET(keywords_re "${keywords_re})$") + + # parse the arguments + SET(command) + SET(ignore NO) + SET(unsupported NO) + string(TOLOWER ${PLATFORM_SPEC} platform_lower) + foreach(i ${ARGN}) + string(REGEX MATCH ${keywords_re} keyword ${i}) + if(keyword) + set(command ${keyword}) + if("${command}" STREQUAL "PLATFORM") + SET(ignore NO) + elseif(NOT ${ignore}) + set(${command}) + if("${command}" STREQUAL "UNSUPPORTED") + SET(ignore YES) + SET(unsupported YES) + else() + SET(unsupported NO) + endif() + endif() + else() + if("${command}" STREQUAL "PLATFORM") + string(TOLOWER ${i} i_lower) + string(REGEX MATCH ${i_lower} platform_matches "${platform_lower}") + if("${platform_matches}" STREQUAL "") + SET(ignore YES) + endif() + elseif(NOT ${ignore}) + if(${command}) + set(${command} "${${command}} ${i}") + else() + set(${command} "${i}") + endif() + endif() + endif() + endforeach(i) + + if(DRY_RUN) + # report results + if(unsupported) + MESSAGE("platform is unsupported!") + else() + MESSAGE("calling ExternalProject_Add() with") + MESSAGE(" name: ${name}") + foreach(i ${keywords}) + if(NOT ${i} STREQUAL "NOT_SPECIFIED") + if("${${i}}" STREQUAL "") + MESSAGE(" ${i}: \"\"") + else() + MESSAGE(" ${i}: ${${i}}") + endif() + endif() + endforeach(i) + endif() + else() + if(unsupported) + MESSAGE(FATAL_ERROR "Package ${name} doesn't support platform ${PLATFORM_SPEC}!") + else() + SET(project_params ${name}) + foreach(i ${keywords}) + if(NOT ${i} STREQUAL "NOT_SPECIFIED") + if("${${i}}" STREQUAL "") + SET(project_params ${project_params} ${i}) + else() + string(REGEX REPLACE " +" ";" args ${${i}}) + SET(project_params ${project_params} ${i} ${args}) + endif() + endif() + endforeach(i) + ExternalProject_Add(${project_params}) + endif() + endif() +ENDFUNCTION(ExternalProject_AddMultiPlatform) diff --git a/test_multi_platform/CMakeLists.txt b/test_multi_platform/CMakeLists.txt new file mode 100644 index 0000000..b22a38a --- /dev/null +++ b/test_multi_platform/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 2.8) +project(bar NONE) + +SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${bar_SOURCE_DIR}/..) + +include(ExternalProjectMultiPlatform) + +# try it for 6 platforms +SET(DRY_RUN YES) + +MESSAGE("**********************") +foreach(PLATFORM_SPEC "B" "B C" "Q" "T" "X" "X Y") + MESSAGE("dry-run for platform: ${PLATFORM_SPEC}") + + ExternalProject_AddMultiPlatform(foo + DEPENDS baz + PLATFORM B + PATCH_COMMAND patch patchfile + BUILD_COMMAND make + INSTALL_COMMAND make install + PLATFORM B C + INSTALL_COMMAND install.sh + PLATFORM Q + BUILD_COMMAND devenv + INSTALL_COMMAND "" + PLATFORM X + UNSUPPORTED + PLATFORM X Y + BUILD_COMMAND nmake + ) + MESSAGE("**********************") +endforeach(PLATFORM_SPEC) + +# do the real thing +SET(DRY_RUN NO) + +MESSAGE("**********************") +foreach(PLATFORM_SPEC "B C") + MESSAGE("real run for platform: ${PLATFORM_SPEC}") + + ExternalProject_AddMultiPlatform(foo + PLATFORM B + SOURCE_DIR ./foo + DOWNLOAD_COMMAND "" + BINARY_DIR ./foo + CONFIGURE_COMMAND cmake . + BUILD_COMMAND devenv foo.sln /build Release /project foo1 + \ndevenv foo.sln /build Release /project foo2 + INSTALL_COMMAND devenv foo.sln /build Release /project INSTALL + PLATFORM B C + INSTALL_COMMAND install.bat + ) + MESSAGE("**********************") +endforeach(PLATFORM_SPEC) diff --git a/test_multi_platform/foo/CMakeLists.txt b/test_multi_platform/foo/CMakeLists.txt new file mode 100644 index 0000000..b2f8e76 --- /dev/null +++ b/test_multi_platform/foo/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8) +project(foo) + +add_target(foo SOURCES foo.cxx) diff --git a/test_multi_platform/foo/foo.cxx b/test_multi_platform/foo/foo.cxx new file mode 100644 index 0000000..e69de29