From ed680537c94aa5590207173f06d8e781dabc8e15 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 22 Sep 2016 18:52:47 +0200 Subject: [PATCH] WIP: compute packages dependencies, using the compiler --- Installation/CMakeLists.txt | 53 ++++++++++++++++--- .../cmake/modules/process_dependencies.cmake | 43 +++++++++++++++ .../modules/run_cmd_redirection_cerr.cmake | 37 +++++++++++++ 3 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 Installation/cmake/modules/process_dependencies.cmake create mode 100644 Installation/cmake/modules/run_cmd_redirection_cerr.cmake diff --git a/Installation/CMakeLists.txt b/Installation/CMakeLists.txt index 5a7db44c06c..5be1e08628b 100644 --- a/Installation/CMakeLists.txt +++ b/Installation/CMakeLists.txt @@ -3,7 +3,9 @@ # refer to the root source directory of the project as ${CMAKE_SOURCE_DIR} or # ${CMAKE_SOURCE_DIR} and to the root binary directory of the project as # ${CMAKE_BINARY_DIR} or ${CMAKE_BINARY_DIR}. -project(CGAL CXX C) +if(NOT PROJECT_NAME) + project(CGAL CXX C) +endif() # Minimal version of CMake: cmake_minimum_required(VERSION 2.8.11) @@ -1043,7 +1045,7 @@ You must disable CGAL_ENABLE_CHECK_HEADERS.") list(APPEND include_options "-I${incdir}") endforeach() foreach (incdir ${CGAL_3RD_PARTY_INCLUDE_DIRS}) - list(APPEND include_options "-isystem${incdir}") + list(APPEND include_options "-I${incdir}") endforeach() include_directories ( SYSTEM ${CGAL_3RD_PARTY_INCLUDE_DIRS} ) @@ -1051,28 +1053,63 @@ You must disable CGAL_ENABLE_CHECK_HEADERS.") set(check_pkg_target_list) foreach (package ${CGAL_CONFIGURED_PACKAGES_NAMES}) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../${package}/include) - set(depends "") + set(check_pkg_headers_depends "") file(GLOB ${package}_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/../${package}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../${package}/include/CGAL/*.h") list(SORT ${package}_HEADERS) + if(COMPUTE_DEPS) + set(compute_deps_extra_args "-H ") + endif() foreach(header ${${package}_HEADERS}) string(REPLACE "/" "__" header2 "${header}") string(REPLACE "." "_" header2 "${header2}") + string(REPLACE ";" " " include_options_str "${include_options}") + separate_arguments(CMD + UNIX_COMMAND +"${CMAKE_CXX_COMPILER} ${CGAL_3RD_PARTY_DEFINITIONS} ${CGAL_DEFINITIONS} \ +-I/usr/include/eigen3 ${include_options_str} -x c++ -fsyntax-only \ +${compute_deps_extra_args} \ +${CMAKE_CURRENT_SOURCE_DIR}/../${package}/include/${header}" +) add_custom_command(OUTPUT check_${header2} - COMMAND ${CMAKE_CXX_COMPILER} ${CGAL_3RD_PARTY_DEFINITIONS} ${CGAL_DEFINITIONS} ${include_options} -x c++ -fsyntax-only "${CMAKE_CURRENT_SOURCE_DIR}/../${package}/include/${header}" - COMMAND ${CMAKE_COMMAND} -E touch check_${header2} - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../${package}/include/${header}" + COMMAND ${CMAKE_COMMAND} + -DCERR:STRING=${CMAKE_CURRENT_BINARY_DIR}/check_${header2} + "-DCMD:STRING=${CMD}" + -P "${CGAL_MODULES_DIR}/run_cmd_redirection_cerr.cmake" + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../${package}/include/${header} + DEPENDS ${CGAL_MODULES_DIR}/run_cmd_redirection_cerr.cmake VERBATIM COMMENT "Check header ${header}" ) - list(APPEND depends check_${header2}) + list(APPEND check_pkg_headers_depends check_${header2}) + if(${header2}_deps) + list(REMOVE_DUPLICATES ${header2}_deps) + endif() endforeach() # look on headers - add_custom_target(check_pkg_${package}_headers DEPENDS ${depends}) + add_custom_target(check_pkg_${package}_headers + DEPENDS ${check_pkg_headers_depends}) + add_custom_command( + OUTPUT pkg_${package}_included_headers pkg_${package}_deps + DEPENDS ${check_pkg_headers_depends} + COMMENT "Compute dependencies of ${package}" + COMMAND ${CMAKE_COMMAND} + -DCGAL_PACKAGES_PREFIX=${CGAL_SOURCE_DIR} + -DOUTPUT_HEADERS_LIST=pkg_${package}_included_headers + -DOUTPUT_PACKAGES_LIST=pkg_${package}_deps + -P "${CGAL_MODULES_DIR}/process_dependencies.cmake" + ${check_pkg_headers_depends} + ) + add_custom_target(${package}_deps DEPENDS pkg_${package}_deps) list(APPEND check_pkg_target_list check_pkg_${package}_headers) + list(APPEND packages_deps ${package}_deps) endif() # if the package has an include directory + if(${package}_deps) + list(REMOVE_DUPLICATES ${package}_deps) + endif() endforeach() # loop on packages add_custom_target(check_headers DEPENDS ${check_pkg_target_list}) + add_custom_target(packages_dependencies DEPENDS ${packages_deps}) endif() endif( CGAL_BRANCH_BUILD ) diff --git a/Installation/cmake/modules/process_dependencies.cmake b/Installation/cmake/modules/process_dependencies.cmake new file mode 100644 index 00000000000..7c01ebf3939 --- /dev/null +++ b/Installation/cmake/modules/process_dependencies.cmake @@ -0,0 +1,43 @@ +foreach(n RANGE 5 ${CMAKE_ARGC}) + list(APPEND INPUT_FILES ${CMAKE_ARGV${n}}) +endforeach() + +if(NOT CGAL_PACKAGES_PREFIX) + message(FATAL_ERROR + "The variable `CGAL_PACKAGES_PREFIX` should be defined to the prefix of CGAL packages!") +endif() + +message("regexp: \\. ${CGAL_PACKAGES_PREFIX}/[^/]*/include/CGAL/.*h") +foreach(INPUT_FILE ${INPUT_FILES}) + file(STRINGS ${INPUT_FILE} input) + #message("input is : ${input}") + foreach(line ${input}) + string(REGEX MATCHALL "^\\. ${CGAL_PACKAGES_PREFIX}/[A-Za-z0-9_.-]*/include/CGAL/[A-Za-z0-9_/.-]*\\.h" header ${line}) + string(REPLACE ". ${CGAL_PACKAGES_PREFIX}/" "" header "${header}") + string(REGEX REPLACE "/.*" "" pkg "${header}") + if(header) + list(APPEND headers ${header}) + endif() + if(pkg) + list(APPEND pkgs ${pkg}) + endif() + endforeach() +endforeach() +if(headers) + list(REMOVE_DUPLICATES headers) +endif() +if(pkgs) + list(REMOVE_DUPLICATES pkgs) +endif() +if(OUTPUT_HEADERS_LIST) + file(WRITE ${OUTPUT_HEADERS_LIST} "") + foreach(header ${headers}) + file(APPEND ${OUTPUT_HEADERS_LIST} "${header}\n") + endforeach() +endif() +if(OUTPUT_PACKAGES_LIST) + file(WRITE ${OUTPUT_PACKAGES_LIST} "") + foreach(pkg ${pkgs}) + file(APPEND ${OUTPUT_PACKAGES_LIST} "${pkg}\n") + endforeach() +endif() diff --git a/Installation/cmake/modules/run_cmd_redirection_cerr.cmake b/Installation/cmake/modules/run_cmd_redirection_cerr.cmake new file mode 100644 index 00000000000..baaa2971452 --- /dev/null +++ b/Installation/cmake/modules/run_cmd_redirection_cerr.cmake @@ -0,0 +1,37 @@ +if(NOT DEFINED CMD) +# message("CMAKE_ARGC: ${CMAKE_ARGC}") +# message("CMAKE_ARGV0: ${CMAKE_ARGV0}") +# message("CMAKE_ARGV1: ${CMAKE_ARGV1}") +# message("CMAKE_ARGV2: ${CMAKE_ARGV2}") +# message("CMAKE_ARGV3: ${CMAKE_ARGV3}") +# message("CMAKE_ARGV4: ${CMAKE_ARGV4}") + foreach(n RANGE 4 ${CMAKE_ARGC}) + list(APPEND CMD ${CMAKE_ARGV${n}}) + endforeach() +endif() +#message("run_cmd_redirection, the CMD list is: ${CMD}") +if(NOT CERR) + message(FATAL_ERROR + "The variable `CERR` should be defined to the output error file!") +endif() + +execute_process( + COMMAND ${CMD} + ERROR_VARIABLE err + OUTPUT_VARIABLE output + RESULT_VARIABLE error_result) + +file(WRITE ${CERR} "${err}") + +if(error_result) + string(REPLACE ";" " " CMD_STR "${CMD}") + message(SEND_ERROR +"The command + ${CMD_STR} > ${CERR} +ended with the error code ${error_result}, +the following output: +${output} +and the following error output: +${err}" +) +endif()