From 0a081c2abdb2b0bea62b774865f58fced137af6e Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 5 Oct 2012 12:21:44 +0000 Subject: [PATCH] Add an option to check the syntax of headers, individually. That feature can be enabled with g++, clang++, and icpc (intel). It could be implemented for MSVC, with the flag /Zs, but that is not yet done (and probably will not). The option is controlled by a CMake option, CGAL_ENABLE_CHECK_HEADERS, that is disabled by default. If that option is enabled by the user, then CMake will check if the compiler $CXX understand the syntax: $CXX -x c++ -fsyntax-only CGAL/header.h and send an error otherwise. Then phony targets will be created: - a target check_CGAL__header_h for each header , - a target check_pkg_ for each package , - and a target check_headers for the whole CGAL. Those new targets currently give a lot of compilation errors if CGAL_ENABLE_CHECK_HEADERS is enabled! + fix several missing includes in Mesh_2. --- Installation/CMakeLists.txt | 60 +++++++++++++++++++ .../config/support/test_syntaxonly.cpp | 0 Mesh_2/include/CGAL/Mesh_2/Refine_edges.h | 2 + Mesh_2/include/CGAL/Mesher_level.h | 2 + .../Triangulation_mesher_level_traits_3.h | 1 + 5 files changed, 65 insertions(+) create mode 100644 Installation/config/support/test_syntaxonly.cpp diff --git a/Installation/CMakeLists.txt b/Installation/CMakeLists.txt index 35d9a874297..ce6725245f3 100644 --- a/Installation/CMakeLists.txt +++ b/Installation/CMakeLists.txt @@ -948,3 +948,63 @@ if( WITH_CPACK AND EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake" ) endif() + +if ( CGAL_BRANCH_BUILD ) + option(CGAL_ENABLE_CHECK_HEADERS + "Enable the special targets \"check_pkg_headers\", and \"check_pkg__headers\" for each package" + FALSE) + + if(CGAL_ENABLE_CHECK_HEADERS) + + if(NOT DEFINED CGAL_CHECK_SYNTAX_ONLY) + execute_process(COMMAND + ${CMAKE_CXX_COMPILER} -x c++ -fsyntax-only ${CMAKE_CURRENT_SOURCE_DIR}/config/support/test_syntaxonly.cpp + ERROR_QUIET + RESULT_VARIABLE ok) + if(ok EQUAL 0) + set(CGAL_CHECK_SYNTAX_ONLY ON CACHE INTERNAL "") + else() + set(CGAL_CHECK_SYNTAX_ONLY OFF CACHE INTERNAL "") + endif() + endif(NOT DEFINED CGAL_CHECK_SYNTAX_ONLY) + + if(NOT CGAL_CHECK_SYNTAX_ONLY) + message(FATAL_ERROR "Your compiler does not seem to support -fsyntax-only. +You must disable CGAL_ENABLE_CHECK_HEADERS.") + endif() + + ## Fill the variable include_options with all the -I and -isystem options + set(include_options) + foreach (incdir ${CGAL_INCLUDE_DIRS}) + list(APPEND include_options "-I${incdir}") + endforeach() + foreach (incdir ${CGAL_3RD_PARTY_INCLUDE_DIRS}) + list(APPEND include_options "-isystem${incdir}") + endforeach() + include_directories ( SYSTEM ${CGAL_3RD_PARTY_INCLUDE_DIRS} ) + + ## Loop on package and headers + set(check_pkg_target_list) + foreach (package ${CGAL_CONFIGURED_PACKAGES_NAMES}) + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../${package}/include) + set(depends "") + file(GLOB_RECURSE ${package}_HEADERS + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/../${package}/include" + "${CMAKE_CURRENT_SOURCE_DIR}/../${package}/include/*.h") + foreach(header ${${package}_HEADERS}) + string(REPLACE "/" "__" header2 "${header}") + string(REPLACE "." "_" header2 "${header2}") + add_custom_target(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}" + VERBATIM + COMMENT "Check header ${header}" + ) + list(APPEND depends check_${header2}) + endforeach() # look on headers + add_custom_target(check_pkg_${package}_headers DEPENDS ${depends}) + list(APPEND check_pkg_target_list check_pkg_${package}_headers) + endif() # if the package has an include directory + endforeach() # loop on packages + add_custom_target(check_headers DEPENDS ${check_pkg_target_list}) + endif() +endif( CGAL_BRANCH_BUILD ) diff --git a/Installation/config/support/test_syntaxonly.cpp b/Installation/config/support/test_syntaxonly.cpp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/Mesh_2/include/CGAL/Mesh_2/Refine_edges.h b/Mesh_2/include/CGAL/Mesh_2/Refine_edges.h index 0ceb0ad7793..363bfefdb65 100644 --- a/Mesh_2/include/CGAL/Mesh_2/Refine_edges.h +++ b/Mesh_2/include/CGAL/Mesh_2/Refine_edges.h @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include diff --git a/Mesh_2/include/CGAL/Mesher_level.h b/Mesh_2/include/CGAL/Mesher_level.h index 8e0c46ff335..5ba8f158ef2 100644 --- a/Mesh_2/include/CGAL/Mesher_level.h +++ b/Mesh_2/include/CGAL/Mesher_level.h @@ -21,6 +21,8 @@ #ifndef CGAL_MESHER_LEVEL_H #define CGAL_MESHER_LEVEL_H +#include + namespace CGAL { enum Mesher_level_conflict_status { diff --git a/Mesh_2/include/CGAL/Meshes/Triangulation_mesher_level_traits_3.h b/Mesh_2/include/CGAL/Meshes/Triangulation_mesher_level_traits_3.h index f8195ba3678..35dab457521 100644 --- a/Mesh_2/include/CGAL/Meshes/Triangulation_mesher_level_traits_3.h +++ b/Mesh_2/include/CGAL/Meshes/Triangulation_mesher_level_traits_3.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace CGAL {