From f052140f856210ce4f081dc021fb85167e1351d4 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 19 Mar 2018 20:43:21 +0100 Subject: [PATCH 1/1] Do not load internal headers when compiling the examples --- CMakeLists.txt | 20 ++++++++++++-------- include/xbt/mmalloc.h | 3 +-- teshsuite/mc/CMakeLists.txt | 1 + teshsuite/simdag/CMakeLists.txt | 1 + teshsuite/surf/CMakeLists.txt | 2 ++ teshsuite/xbt/CMakeLists.txt | 4 +++- tools/cmake/Java.cmake | 2 ++ tools/cmake/MakeLib.cmake | 10 ++++++++-- tools/cmake/Tests.cmake | 6 ++++++ tools/cmake/UnitTesting.cmake | 5 +++++ 10 files changed, 41 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41f6c7aa81..62c423ee73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,20 +159,26 @@ endif() SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) ### Compute the include paths -set(INCLUDES + +# Only include public headers by default +include_directories( + ${CMAKE_BINARY_DIR}/include + ${CMAKE_HOME_DIRECTORY}/include +) + +# Compute the ones that should be added when compiling the library +set(INTERNAL_INCLUDES ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}/include ${CMAKE_HOME_DIRECTORY} - ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_HOME_DIRECTORY}/src/include ) if(enable_smpi) - set (INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/src/smpi/include) + set (INTERNAL_INCLUDES ${INTERNAL_INCLUDES} ${CMAKE_HOME_DIRECTORY}/src/smpi/include) endif() if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/) - set(INCLUDES ${INCLUDES} /usr/include/) + set(INTERNAL_INCLUDES ${INTERNAL_INCLUDES} /usr/include/) endif() if(WIN32) @@ -180,12 +186,10 @@ if(WIN32) set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}") string(REGEX REPLACE "/bin/gcc.*" "/include" CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}") string(REGEX REPLACE "/bin/gcc.*" "/lib" CMAKE_LIB_WIN "${CMAKE_LIB_WIN}") - set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN}) + set(INTERNAL_INCLUDES ${INTERNAL_INCLUDES} ${CMAKE_INCLUDE_WIN}) unset(CMAKE_INCLUDE_WIN) endif() -include_directories(${INCLUDES}) - # library dependency cannot start with a space (CMP0004), so initialize it with something that is never desactivated. set(SIMGRID_DEP "-lm") diff --git a/include/xbt/mmalloc.h b/include/xbt/mmalloc.h index eff59a07dd..62d0a00805 100644 --- a/include/xbt/mmalloc.h +++ b/include/xbt/mmalloc.h @@ -1,5 +1,4 @@ -/* Copyright (c) 2010-2018. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2010-2018. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ diff --git a/teshsuite/mc/CMakeLists.txt b/teshsuite/mc/CMakeLists.txt index 5d42234bf8..e1618b97f9 100644 --- a/teshsuite/mc/CMakeLists.txt +++ b/teshsuite/mc/CMakeLists.txt @@ -3,6 +3,7 @@ foreach(x dwarf dwarf-expression) add_executable (${x} ${x}/${x}.cpp) target_link_libraries(${x} simgrid) set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) + set_property(TARGET ${x} APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") endif() set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) diff --git a/teshsuite/simdag/CMakeLists.txt b/teshsuite/simdag/CMakeLists.txt index f05938480a..b0d6575d43 100644 --- a/teshsuite/simdag/CMakeLists.txt +++ b/teshsuite/simdag/CMakeLists.txt @@ -21,6 +21,7 @@ foreach(x flatifier is-router) add_executable (${x} ${x}/${x}.cpp) target_link_libraries(${x} simgrid) set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) + set_property(TARGET ${x} APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.cpp) diff --git a/teshsuite/surf/CMakeLists.txt b/teshsuite/surf/CMakeLists.txt index 8bede3c023..467abf95cd 100644 --- a/teshsuite/surf/CMakeLists.txt +++ b/teshsuite/surf/CMakeLists.txt @@ -2,6 +2,7 @@ foreach(x lmm_usage surf_usage surf_usage2) add_executable (${x} ${x}/${x}.cpp) target_link_libraries(${x} simgrid) set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) + set_property(TARGET ${x} APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.cpp) @@ -10,6 +11,7 @@ endforeach() add_executable (maxmin_bench maxmin_bench/maxmin_bench.cpp) target_link_libraries(maxmin_bench simgrid) set_target_properties(maxmin_bench PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/maxmin_bench) +set_property(TARGET maxmin_bench APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") foreach(x small medium large) set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/maxmin_bench/maxmin_bench_${x}.tesh) diff --git a/teshsuite/xbt/CMakeLists.txt b/teshsuite/xbt/CMakeLists.txt index 8a16af4c43..bd505c89bb 100644 --- a/teshsuite/xbt/CMakeLists.txt +++ b/teshsuite/xbt/CMakeLists.txt @@ -11,6 +11,7 @@ foreach(x parmap_bench parmap_test) add_executable (${x} ${x}/${x}.cpp) target_link_libraries(${x} simgrid) set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) + set_property(TARGET ${x} APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.cpp) @@ -19,7 +20,8 @@ endforeach() if(HAVE_MMALLOC) add_executable (mmalloc_test ${CMAKE_CURRENT_SOURCE_DIR}/mmalloc/mmalloc_test.cpp) target_link_libraries(mmalloc_test simgrid) - set_target_properties(mmalloc_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mmalloc) + set_target_properties(mmalloc_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mmalloc) + set_property(TARGET mmalloc_test APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") endif() set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/log_usage/log_usage_ndebug.tesh diff --git a/tools/cmake/Java.cmake b/tools/cmake/Java.cmake index 24c0994060..fecf92b3e5 100644 --- a/tools/cmake/Java.cmake +++ b/tools/cmake/Java.cmake @@ -28,6 +28,8 @@ endif() add_library(simgrid-java SHARED ${JMSG_C_SRC}) set_target_properties(simgrid-java PROPERTIES VERSION ${libsimgrid-java_version}) set_target_properties(simgrid-java PROPERTIES SKIP_BUILD_RPATH ON) +set_property(TARGET simgrid-java + APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") target_link_libraries(simgrid-java simgrid) diff --git a/tools/cmake/MakeLib.cmake b/tools/cmake/MakeLib.cmake index 3f634ddfd2..66886a7ce2 100644 --- a/tools/cmake/MakeLib.cmake +++ b/tools/cmake/MakeLib.cmake @@ -20,6 +20,9 @@ endif() # Actually declare our libraries add_library(simgrid SHARED ${simgrid_sources}) set_target_properties(simgrid PROPERTIES VERSION ${libsimgrid_version}) +# The library can obviously use the internal headers +set_property(TARGET simgrid + APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") add_dependencies(simgrid maintainer_files) @@ -27,10 +30,13 @@ if(enable_model-checking) add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC}) target_link_libraries(simgrid-mc simgrid) set_target_properties(simgrid-mc - PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + set_property(TARGET simgrid-mc + APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}") + endif() + # Compute the dependencies of SimGrid ##################################### if (HAVE_BOOST_CONTEXTS) diff --git a/tools/cmake/Tests.cmake b/tools/cmake/Tests.cmake index 39e78d82e4..b1c99ef8e2 100644 --- a/tools/cmake/Tests.cmake +++ b/tools/cmake/Tests.cmake @@ -93,6 +93,12 @@ if(Boost_UNIT_TEST_FRAMEWORK_FOUND) add_executable (unit_tmgr src/surf/trace_mgr_test.cpp) target_link_libraries(unit_tmgr simgrid ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) ADD_TEST(unit_tmgr ${CMAKE_BINARY_DIR}/unit_tmgr --build_info=yes) + set_property( + TARGET unit_tmgr + APPEND PROPERTY + INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}" + ) + else() set(EXTRA_DIST ${EXTRA_DIST} src/surf/trace_mgr_test.cpp) diff --git a/tools/cmake/UnitTesting.cmake b/tools/cmake/UnitTesting.cmake index 43af6555a6..cd3f9a457c 100644 --- a/tools/cmake/UnitTesting.cmake +++ b/tools/cmake/UnitTesting.cmake @@ -46,4 +46,9 @@ ADD_CUSTOM_COMMAND( add_executable (testall ${EXTRACTED_TEST_SOURCE_FILES}) target_link_libraries(testall simgrid) +set_property( + TARGET testall + APPEND PROPERTY + INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}" + ) -- 2.20.1