From e5c8b6ead65060e77b1c4a54d729bd7877160afd Mon Sep 17 00:00:00 2001 From: Raphael Isemann <teemperor@gmail.com> Date: Fri, 10 Mar 2017 16:36:17 +0100 Subject: [PATCH] Moved to explicit modulemaps Signed-off-by: Vassil Vassilev <vvasilev@cern.ch> --- CMakeLists.txt | 109 ++++++++++++++++++++---------- cmake/modules/CheckCompiler.cmake | 55 --------------- 2 files changed, 74 insertions(+), 90 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b39c46af45..7069e689c9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,9 +120,82 @@ foreach(tutorial_file ${tutorial_files}) endforeach() add_custom_target(move_artifacts DEPENDS ${stamp_file} ${tutorial_files_builddir}) +add_subdirectory (interpreter) + +#---CXX MODULES----------------------------------------------------------------------------------- +if(cxxmodules) + # Copy-pasted from HandleLLVMOptions.cmake, please keep up to date. + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fmodules -fcxx-modules") + # Check that we can build code with modules enabled, and that repeatedly + # including <cassert> still manages to respect NDEBUG properly. + CHECK_CXX_SOURCE_COMPILES("#undef NDEBUG + #include <cassert> + #define NDEBUG + #include <cassert> + int main() { assert(this code is not compiled); }" + CXX_SUPPORTS_MODULES) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) + if(NOT CXX_SUPPORTS_MODULES) + message(FATAL_ERROR "cxxmodules is not supported by this compiler") + endif() + + set(ROOT_CXXMODULES_COMMONFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -fmodules -fmodules-cache-path=${CMAKE_BINARY_DIR}/include/pcms/ -fno-autolink -fdiagnostics-show-note-include-stack") + + set(ROOT_CXXMODULES_COMMONFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -fno-implicit-module-maps -fmodule-map-file=${CMAKE_BINARY_DIR}/include/module.modulemap") + + configure_file("${CMAKE_SOURCE_DIR}/build/unix/module.modulemap" "${CMAKE_BINARY_DIR}/include/module.modulemap" COPYONLY) + + add_custom_target(copymodulemap + DEPENDS build/unix/module.modulemap + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/build/unix/module.modulemap ${CMAKE_BINARY_DIR}/include/module.modulemap + ) + get_property(__modulemap_extra_content GLOBAL PROPERTY ROOT_CXXMODULES_EXTRA_MODULEMAP_CONTENT) + string(REPLACE ";" "" __modulemap_extra_content "${__modulemap_extra_content}") + file(WRITE "${CMAKE_BINARY_DIR}/include/module.modulemap.extra" "${__modulemap_extra_content}") + add_custom_command(TARGET copymodulemap POST_BUILD + COMMAND cat "${CMAKE_BINARY_DIR}/include/module.modulemap.extra" >> ${CMAKE_BINARY_DIR}/include/module.modulemap + VERBATIM + ) + add_dependencies(move_artifacts copymodulemap) + + # Provide our own modulemap for implementations other than libcxx. + if (NOT libcxx) + # Write a empty overlay file to the output directory that CMake can run its compiler tests. + # We will create the actual overlay later in the configuration. + file(WRITE ${CMAKE_BINARY_DIR}/include/modulemap.overlay.yaml "{'version' : 0, 'roots' : []}") + set(__vfs_overlay "-ivfsoverlay ${CMAKE_BINARY_DIR}/include/modulemap.overlay.yaml") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${__vfs_overlay}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${__vfs_overlay}") + + # Only use the first path from the HEADERS_LOCATION (which is separated by colons). + get_property(__libcpp_full_paths GLOBAL PROPERTY ROOT_CLING_CXX_HEADERS_LOCATION) + string(REGEX MATCHALL "[^:]+" __libcpp_full_paths_list "${__libcpp_full_paths}") + list(GET __libcpp_full_paths_list 0 __libcpp_full_path) + + set(ROOT_CXXMODULES_COMMONFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -fmodule-map-file=${__libcpp_full_path}/module.modulemap") + + configure_file(${CMAKE_SOURCE_DIR}/build/unix/modulemap.overlay.yaml.in ${CMAKE_BINARY_DIR}/include/modulemap.overlay.yaml @ONLY) + + add_custom_target(copystlmodulemap + DEPENDS build/unix/module.modulemap + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/build/unix/stl.cppmap ${CMAKE_BINARY_DIR}/include/stl.cppmap + ) + + add_dependencies(copymodulemap copystlmodulemap) + endif() + + # These vars are useful when we want to compile things without cxxmodules. + set(ROOT_CXXMODULES_CXXFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -fcxx-modules -Xclang -fmodules-local-submodule-visibility" CACHE STRING "Useful to filter out the modules-related cxxflags.") + set(ROOT_CXXMODULES_CFLAGS "${ROOT_CXXMODULES_COMMONFLAGS}" CACHE STRING "Useful to filter out the modules-related cflags.") + + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ROOT_CXXMODULES_CFLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ROOT_CXXMODULES_CXXFLAGS}") +endif(cxxmodules) + #---Recurse into the given subdirectories. This does not actually cause another cmake executable # to run. The same process will walk through the project's entire directory structure. -add_subdirectory (interpreter) add_subdirectory (core) add_subdirectory (build) add_subdirectory (math) @@ -191,40 +264,6 @@ add_dependencies(onepcm ${__allTargets}) install(FILES ${CMAKE_BINARY_DIR}/etc/allDict.cxx.pch DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}) install(DIRECTORY ${CMAKE_BINARY_DIR}/etc/dictpch DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}) -#---CXX MODULES----------------------------------------------------------------------------------- -if(cxxmodules) - add_custom_target(copymodulemap - DEPENDS build/unix/module.modulemap - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/build/unix/module.modulemap ${CMAKE_BINARY_DIR}/include/module.modulemap - ) - get_property(__modulemap_extra_content GLOBAL PROPERTY ROOT_CXXMODULES_EXTRA_MODULEMAP_CONTENT) - string(REPLACE ";" "" __modulemap_extra_content "${__modulemap_extra_content}") - if (NOT APPLE) - set(__echo_args "-e") - endif() - file(WRITE "${CMAKE_BINARY_DIR}/include/module.modulemap.extra" "${__modulemap_extra_content}") - add_custom_command(TARGET copymodulemap POST_BUILD - COMMAND cat "${CMAKE_BINARY_DIR}/include/module.modulemap.extra" >> ${CMAKE_BINARY_DIR}/include/module.modulemap - VERBATIM - ) - add_dependencies(move_artifacts copymodulemap) - if (NOT libcxx) - # Only use the first path from the HEADERS_LOCATION (which is separated by colons). - get_property(__libcpp_full_paths GLOBAL PROPERTY ROOT_CLING_CXX_HEADERS_LOCATION) - string(REGEX MATCHALL "[^:]+" __libcpp_full_paths_list "${__libcpp_full_paths}") - list(GET __libcpp_full_paths_list 0 __libcpp_full_path) - - configure_file(${CMAKE_SOURCE_DIR}/build/unix/modulemap.overlay.yaml.in ${CMAKE_BINARY_DIR}/include/modulemap.overlay.yaml @ONLY) - add_custom_target(copystlmodulemap - DEPENDS build/unix/module.modulemap - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/build/unix/stl.cppmap ${CMAKE_BINARY_DIR}/include/stl.cppmap - ) - add_dependencies(copymodulemap copystlmodulemap) - endif() - - -endif(cxxmodules) - #---hsimple.root---------(use the executable for clearer dependencies and proper return code)--- add_custom_target(hsimple ALL DEPENDS tutorials/hsimple.root) add_dependencies(hsimple onepcm) diff --git a/cmake/modules/CheckCompiler.cmake b/cmake/modules/CheckCompiler.cmake index a49dd252633..28532ba5c07 100644 --- a/cmake/modules/CheckCompiler.cmake +++ b/cmake/modules/CheckCompiler.cmake @@ -120,61 +120,6 @@ if(libcxx) endif() endif() - -#---Check for cxxmodules option------------------------------------------------------------ -if(cxxmodules) - # Copy-pasted from HandleLLVMOptions.cmake, please keep up to date. - set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fmodules -fcxx-modules") - # Check that we can build code with modules enabled, and that repeatedly - # including <cassert> still manages to respect NDEBUG properly. - CHECK_CXX_SOURCE_COMPILES("#undef NDEBUG - #include <cassert> - #define NDEBUG - #include <cassert> - int main() { assert(this code is not compiled); }" - CXX_SUPPORTS_MODULES) - set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) - if(CXX_SUPPORTS_MODULES) - set(ROOT_CXXMODULES_COMMONFLAGS "-fmodules -fmodules-cache-path=${CMAKE_BINARY_DIR}/include/pcms/ -fno-autolink -fdiagnostics-show-note-include-stack") - if (APPLE) - # FIXME: TGLIncludes and alike depend on glew.h doing special preprocessor - # trickery to override the contents of system's OpenGL. - # On OSX #include TGLIncludes.h will trigger the creation of the system - # OpenGL.pcm. Once it is built, glew cannot use preprocessor trickery to 'fix' - # the translation units which it needs to 'rewrite'. The translation units - # which need glew support are in graf3d. However, depending on the modulemap - # organization we could request it implicitly (eg. one big module for ROOT). - # In these cases we need to 'prepend' this include path to the compiler in order - # for glew.h to it its trick. - #set(ROOT_CXXMODULES_COMMONFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -isystem ${CMAKE_SOURCE_DIR}/graf3d/glew/isystem" - - # Workaround the issue described above by not picking up the system module - # maps. In this way we can use the -fmodules-local-submodule-visibility - # flag. - set(ROOT_CXXMODULES_COMMONFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -fno-implicit-module-maps -fmodule-map-file=${CMAKE_BINARY_DIR}/include/module.modulemap") - endif(APPLE) - - # Provide our own modulemap for implementations other than libcxx. - if (NOT libcxx) - # Write a empty overlay file to the output directory that CMake can run its compiler tests. - # We will create the actual overlay later in the configuration. - file(WRITE ${CMAKE_BINARY_DIR}/include/modulemap.overlay.yaml "{'version' : 0, 'roots' : []}") - set(__vfs_overlay "-ivfsoverlay ${CMAKE_BINARY_DIR}/include/modulemap.overlay.yaml") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${__vfs_overlay}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${__vfs_overlay}") - endif() - - # These vars are useful when we want to compile things without cxxmodules. - set(ROOT_CXXMODULES_CXXFLAGS "${ROOT_CXXMODULES_COMMONFLAGS} -fcxx-modules -Xclang -fmodules-local-submodule-visibility" CACHE STRING "Useful to filter out the modules-related cxxflags.") - set(ROOT_CXXMODULES_CFLAGS "${ROOT_CXXMODULES_COMMONFLAGS}" CACHE STRING "Useful to filter out the modules-related cflags.") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ROOT_CXXMODULES_CFLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ROOT_CXXMODULES_CXXFLAGS}") - else() - message(FATAL_ERROR "cxxmodules is not supported by this compiler") - endif() -endif(cxxmodules) - #---Need to locate thead libraries and options to set properly some compilation flags---------------- find_package(Threads) if(CMAKE_USE_PTHREADS_INIT) -- GitLab