diff --git a/AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp b/AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp index f1d983eccf12..d3b2af45913f 100644 --- a/AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp @@ -44,7 +44,7 @@ struct Skip int main(int argc, char* argv[]) { - const char* filename = (argc > 1) ? argv[1] : "data/tetrahedron.off"; + const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/tetrahedron.off"); Mesh mesh; if(!CGAL::IO::read_polygon_mesh(filename, mesh)) diff --git a/AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp b/AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp index 5489c2c9c157..13eb303b771b 100644 --- a/AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp @@ -38,7 +38,7 @@ int test() // load polyhedron typedef CGAL::Polyhedron_3 Polyhedron; Polyhedron polyhedron; - std::ifstream ifs("./data/tetrahedron.off"); + std::ifstream ifs(CGAL::data_file_path("meshes/tetrahedron.off")); ifs >> polyhedron; // construct tree from facets @@ -129,4 +129,3 @@ int main() /* Local Variables: */ /* tab-width: 2 */ /* End: */ - diff --git a/Cone_spanners_2/examples/Cone_spanners_2/theta_io.cmd b/Cone_spanners_2/examples/Cone_spanners_2/theta_io.cmd deleted file mode 100644 index ddce44428551..000000000000 --- a/Cone_spanners_2/examples/Cone_spanners_2/theta_io.cmd +++ /dev/null @@ -1 +0,0 @@ -4 data/n9.cin diff --git a/Cone_spanners_2/examples/Cone_spanners_2/theta_io.cpp b/Cone_spanners_2/examples/Cone_spanners_2/theta_io.cpp index f070784e005e..4096cf1c71f8 100644 --- a/Cone_spanners_2/examples/Cone_spanners_2/theta_io.cpp +++ b/Cone_spanners_2/examples/Cone_spanners_2/theta_io.cpp @@ -26,26 +26,37 @@ typedef boost::adjacency_list 1 && + (!strcmp(argv[1],"-h") || !strcmp(argv[1],"--help") || !strcmp(argv[1],"-?"))) + { std::cout << "Usage: " << argv[0] << " [ ]" << std::endl; return 1; } - unsigned int k = atoi(argv[1]); - if (k<2) { - std::cout << "The number of cones should be larger than 1!" << std::endl; - return 1; + if (argc > 1) + { + k = atoi(argv[1]); + if (k<2) { + std::cout << "The number of cones should be larger than 1!" << std::endl; + return 1; + } } + if (argc > 2) + { filename=std::string(argv[2]); } + // open the file containing the vertex list - std::ifstream inf(argv[2]); + std::ifstream inf(filename); if (!inf) { - std::cout << "Cannot open file " << argv[2] << "!" << std::endl; + std::cout << "Cannot open file " << filename << "!" << std::endl; return 1; } Direction_2 initial_direction; - if (argc == 3) + if (argc == 1 || argc == 3) initial_direction = Direction_2(1, 0); // default initial_direction else if (argc == 5) initial_direction = Direction_2(atof(argv[3]), atof(argv[4])); diff --git a/Data/data/meshes/tetrahedron.off b/Data/data/meshes/tetrahedron.off new file mode 100644 index 000000000000..5c641a7849e0 --- /dev/null +++ b/Data/data/meshes/tetrahedron.off @@ -0,0 +1,11 @@ +OFF +4 4 0 +0.0 0.0 0.0 +1.0 0.0 0.0 +0.0 1.0 0.0 +0.0 0.0 1.0 +3 0 1 2 +3 0 3 1 +3 0 2 3 +3 1 3 2 + diff --git a/Point_set_processing_3/test/Point_set_processing_3/data/sphere_20k.xyz b/Data/data/points_3/sphere_20k.xyz similarity index 100% rename from Point_set_processing_3/test/Point_set_processing_3/data/sphere_20k.xyz rename to Data/data/points_3/sphere_20k.xyz diff --git a/Installation/CMakeLists.txt b/Installation/CMakeLists.txt index e4d90fb23b6f..b2a267f03390 100644 --- a/Installation/CMakeLists.txt +++ b/Installation/CMakeLists.txt @@ -22,8 +22,6 @@ include(GNUInstallDirs) # #-------------------------------------------------------------------------------------------------- -message("== Setting paths ==") - if(CGAL_BRANCH_BUILD) message( @@ -857,6 +855,8 @@ if(NOT RUNNING_CGAL_AUTO_TEST) endif() endif() +message("== Setting paths ==") + #-------------------------------------------------------------------------------------------------- # # -= CPack =- diff --git a/Installation/cmake/modules/CGALConfig_binary.cmake.in b/Installation/cmake/modules/CGALConfig_binary.cmake.in index 364ab5bb823e..01fae62d34a0 100644 --- a/Installation/cmake/modules/CGALConfig_binary.cmake.in +++ b/Installation/cmake/modules/CGALConfig_binary.cmake.in @@ -196,4 +196,15 @@ if( CGAL_DEV_MODE OR RUNNING_CGAL_AUTO_TEST ) include(CGAL_SetupFlags) endif() +#CGAL_DATA_DIR, used by `CGAL::data_file_path(filename)` from `CGAL/config.h` +set(CGAL_DATA_DIR "@CGAL_DATA_DIR@") + +if(NOT TARGET CGAL::Data) + add_library(CGAL::Data INTERFACE IMPORTED) + if ( NOT "${CGAL_DATA_DIR}" STREQUAL "" ) + set_target_properties(CGAL::Data PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "CGAL_DATA_DIR=\"${CGAL_DATA_DIR}\"") + endif() +endif() + include("${CGAL_MODULES_DIR}/CGAL_enable_end_of_configuration_hook.cmake") diff --git a/Installation/cmake/modules/CGALConfig_install.cmake.in b/Installation/cmake/modules/CGALConfig_install.cmake.in index cb51524dcfae..e11acd785226 100644 --- a/Installation/cmake/modules/CGALConfig_install.cmake.in +++ b/Installation/cmake/modules/CGALConfig_install.cmake.in @@ -179,4 +179,16 @@ if( CGAL_DEV_MODE OR RUNNING_CGAL_AUTO_TEST ) # Nov. 2017). -- Laurent Rineau include(CGAL_SetupFlags) endif() + +#CGAL_DATA_DIR +set(CGAL_DATA_DIR "@CGAL_DATA_DIR@") + +if(NOT TARGET CGAL::Data) + add_library(CGAL::Data INTERFACE IMPORTED) + if ( NOT "${CGAL_DATA_DIR}" STREQUAL "" ) + set_target_properties(CGAL::Data PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "CGAL_DATA_DIR=\"${CGAL_DATA_DIR}\"") + endif() +endif() + include("${CGAL_MODULES_DIR}/CGAL_enable_end_of_configuration_hook.cmake") diff --git a/Installation/cmake/modules/CGAL_CreateSingleSourceCGALProgram.cmake b/Installation/cmake/modules/CGAL_CreateSingleSourceCGALProgram.cmake index 161e59d0391f..1eb308fbe1cc 100644 --- a/Installation/cmake/modules/CGAL_CreateSingleSourceCGALProgram.cmake +++ b/Installation/cmake/modules/CGAL_CreateSingleSourceCGALProgram.cmake @@ -65,7 +65,7 @@ function(create_single_source_cgal_program firstfile ) add_to_cached_list( CGAL_EXECUTABLE_TARGETS ${exe_name} ) - target_link_libraries(${exe_name} PRIVATE CGAL::CGAL) + target_link_libraries(${exe_name} PRIVATE CGAL::CGAL CGAL::Data) foreach(comp ${CGAL_REQUESTED_COMPONENTS}) if(TARGET CGAL::CGAL_${comp}) target_link_libraries(${exe_name} PRIVATE CGAL::CGAL_${comp}) diff --git a/Installation/cmake/modules/CGAL_add_test.cmake b/Installation/cmake/modules/CGAL_add_test.cmake index 7090304dc262..4b6a610e8614 100644 --- a/Installation/cmake/modules/CGAL_add_test.cmake +++ b/Installation/cmake/modules/CGAL_add_test.cmake @@ -325,6 +325,7 @@ function(cgal_add_test exe_name) endif() if(EXISTS ${cmd_file}) file(STRINGS "${cmd_file}" CMD_LINES) + string(CONFIGURE "${CMD_LINES}" CMD_LINES) set(ARGS) # message(STATUS "DEBUG test ${exe_name}") foreach(CMD_LINE ${CMD_LINES}) diff --git a/Installation/include/CGAL/config.h b/Installation/include/CGAL/config.h index ccca6b86cb63..82bddde90683 100644 --- a/Installation/include/CGAL/config.h +++ b/Installation/include/CGAL/config.h @@ -737,4 +737,63 @@ namespace cpp11{ /// @} #include +//----------------------------------------------------------------------// +// Function to define data directory +//----------------------------------------------------------------------// +#include +#include +#include +#include + +namespace CGAL { + +// Returns filename prefixed by the directory of CGAL containing data. +// This directory is either defined in the environement variable CGAL_DATA_DIR, +// otherwise it is taken from the constant CGAL_DATA_DIR (defined in CMake), +// otherwise it is empty (and thus returns filename unmodified). +inline std::string data_file_path(const std::string& filename) +{ + const char* cgal_dir=nullptr; + +#ifdef _MSC_VER + char* cgal_dir_windows=nullptr; + _dupenv_s( &cgal_dir_windows, nullptr, "CGAL_DATA_DIR"); + if (cgal_dir_windows!=nullptr) + { cgal_dir=cgal_dir_windows; } +#else + cgal_dir=getenv("CGAL_DATA_DIR"); +#endif + +#ifdef CGAL_DATA_DIR + if (cgal_dir==nullptr) + { cgal_dir=CGAL_DATA_DIR; } +#endif + + std::string cgal_dir_string; + if (cgal_dir!=nullptr) + { cgal_dir_string=std::string(cgal_dir); } + + std::string res=cgal_dir_string; + if (!res.empty() && res.back()!='/') + { res+=std::string("/"); } + res+=filename; + + // Test if the file exists, write a warning otherwise + std::ifstream f(res); + if (!f) + { + std::cerr<<"[WARNING] file "<