From 775046144a54a70ab0267043bf43e122e48f95ed Mon Sep 17 00:00:00 2001 From: flagarde Date: Mon, 28 Dec 2020 15:18:14 +0800 Subject: [PATCH 1/2] Move to CMakeMM --- CMakeLists.txt | 46 +++++------ cmake/CXXStandards.cmake | 66 --------------- cmake/CompilerOptions.cmake | 48 ----------- cmake/GetCMakeMM.cmake | 155 ++++++++++++++++++++++++++++++++++++ libs/CMakeLists.txt | 4 +- 5 files changed, 175 insertions(+), 144 deletions(-) delete mode 100644 cmake/CXXStandards.cmake delete mode 100644 cmake/CompilerOptions.cmake create mode 100644 cmake/GetCMakeMM.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0833766..157abb8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,26 +4,28 @@ project(SDHCALSim VERSION "0.2.0" LANGUAGES CXX) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake") -if(DEFINED ENV{LCIO}) - set(CMAKE_PREFIX_PATH "$ENV{LCIO};${CMAKE_PREFIX_PATH}" CACHE PATH "CMAKE_PREFIX_PATH" FORCE) - message(STATUS "LCIO environment found ${CMAKE_PREFIX_PATH}") -endif() +# Download CMakeCM +include(GetCMakeMM) +cmmm(VERSION "1.1" + GIT_REPOSITORY "flagarde/CMakeMM" + VERBOSITY VERBOSE + DESTINATION "CMakeMM" + ) + +cmmm_modules_list(URL "https://raw.githubusercontent.com/flagarde/CMakeCMTests" BRANCH master DESTINATION "Modules") + +#PreventInSourceBuilds is in common but try to avoid downloading many files +include(PreventInSourceBuilds) +prevent_in_source_builds() + +include(DefaultInstallPrefix) +default_install_prefix("${CMAKE_SOURCE_DIR}/bin") # Ask CMake to output a compile_commands.json file for use with things like Vim YCM. set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) set(CMAKE_LINK_DEPENDS_NO_SHARED TRUE) -# guard against in-source builds -if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") - message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.") -endif() - -if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/bin" CACHE PATH "Default Install Prefix" FORCE) - message(STATUS "Install Prefix set to : ${CMAKE_INSTALL_PREFIX}") -endif() - set(LIBRARY_OUTPUT_DIR "${CMAKE_INSTALL_PREFIX}/lib") set(RUNTIME_OUTPUT_DIR "${CMAKE_INSTALL_PREFIX}") set(ARCHIVE_OUTPUT_DIR "${CMAKE_INSTALL_PREFIX}/lib") @@ -78,19 +80,6 @@ else() set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) endif() -# Optional IPO. Do not use IPO if it's not supported by compiler. -include(CheckIPOSupported) -check_ipo_supported(RESULT result OUTPUT output) -if(result) - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) -else() - message(WARNING "IPO is not supported: ${output}") -endif() - -option(ENABLE_ALL_WARNINGS "Enable all warnings" TRUE) - -include(CompilerOptions) - #---------------------------------------------------------------------------- # Find Geant4 package, activating all available UI and Vis drivers by default # You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui @@ -105,7 +94,8 @@ else() endif() find_package(ROOT REQUIRED) -find_package(LCIO 2.11 REQUIRED) + +include(Lcio) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED OFF) diff --git a/cmake/CXXStandards.cmake b/cmake/CXXStandards.cmake deleted file mode 100644 index 87a894f..0000000 --- a/cmake/CXXStandards.cmake +++ /dev/null @@ -1,66 +0,0 @@ -# -# Copyright (C) 2018 by George Cave - gcave@stablecoder.ca -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -# Set the compiler standard to C++11 -macro(cxx_11) - set(CMAKE_CXX_STANDARD 11) - set(CMAKE_CXX_STANDARD_REQUIRED ON) - set(CMAKE_CXX_EXTENSIONS OFF) - - if(MSVC_VERSION GREATER_EQUAL "1900" AND CMAKE_VERSION LESS 3.10) - include(CheckCXXCompilerFlag) - check_cxx_compiler_flag("/std:c++11" _cpp_latest_flag_supported) - if(_cpp_latest_flag_supported) - add_compile_options("/std:c++11") - endif() - endif() -endmacro() - -# Set the compiler standard to C++14 -macro(cxx_14) - set(CMAKE_CXX_STANDARD 14) - set(CMAKE_CXX_STANDARD_REQUIRED ON) - set(CMAKE_CXX_EXTENSIONS OFF) - - if(MSVC_VERSION GREATER_EQUAL "1900" AND CMAKE_VERSION LESS 3.10) - include(CheckCXXCompilerFlag) - check_cxx_compiler_flag("/std:c++14" _cpp_latest_flag_supported) - if(_cpp_latest_flag_supported) - add_compile_options("/std:c++14") - endif() - endif() -endmacro() - -# Set the compiler standard to C++17 -macro(cxx_17) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_STANDARD_REQUIRED ON) - set(CMAKE_CXX_EXTENSIONS OFF) - - if(MSVC_VERSION GREATER_EQUAL "1900" AND CMAKE_VERSION LESS 3.10) - include(CheckCXXCompilerFlag) - check_cxx_compiler_flag("/std:c++17" _cpp_latest_flag_supported) - if(_cpp_latest_flag_supported) - add_compile_options("/std:c++17") - endif() - endif() -endmacro() - -# Set the compiler standard to C++20 -macro(cxx_20) - set(CMAKE_CXX_STANDARD 20) - set(CMAKE_CXX_STANDARD_REQUIRED ON) - set(CMAKE_CXX_EXTENSIONS OFF) -endmacro() diff --git a/cmake/CompilerOptions.cmake b/cmake/CompilerOptions.cmake deleted file mode 100644 index e614124..0000000 --- a/cmake/CompilerOptions.cmake +++ /dev/null @@ -1,48 +0,0 @@ -# -# Copyright (C) 2018 by George Cave - gcave@stablecoder.ca -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -if(ENABLE_ALL_WARNINGS) - if(CMAKE_COMPILER_IS_GNUCC - OR CMAKE_COMPILER_IS_GNUCXX - OR CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang" - OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang") - # GCC/Clang - add_compile_options(-Wall -Wextra) - elseif(MSVC) - # MSVC - add_compile_options(/W4) - endif() -endif() - -if(ENABLE_EFFECTIVE_CXX) - if(CMAKE_COMPILER_IS_GNUCC - OR CMAKE_COMPILER_IS_GNUCXX - OR CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang" - OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++") - endif() -endif() - -if(GENERATE_DEPENDENCY_DATA) - if(CMAKE_COMPILER_IS_GNUCC - OR CMAKE_COMPILER_IS_GNUCXX - OR CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang" - OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang") - add_compile_options(-MD) - else() - message( - WARNING "Cannot generate header dependency on non GCC/Clang compilers.") - endif() -endif() diff --git a/cmake/GetCMakeMM.cmake b/cmake/GetCMakeMM.cmake new file mode 100644 index 0000000..c35f1af --- /dev/null +++ b/cmake/GetCMakeMM.cmake @@ -0,0 +1,155 @@ +include_guard(GLOBAL) + +if(NOT COMMAND colors) + # Colorize + macro(colors) + if(NOT WIN32) + string(ASCII 27 Esc) + set(Reset "${Esc}[m") + set(BoldRed "${Esc}[1;31m") + set(BoldMagenta "${Esc}[1;35m") + set(BoldYellow "${Esc}[1;33m") + set(BoldGreen "${Esc}[1;32m") + endif() + endmacro() +endif() + +function(cmmm) + cmake_parse_arguments(CMMM "ALWAYS_DOWNLOAD;NO_COLOR" "GIT_REPOSITORY;VERSION;DESTINATION;TIMEOUT;INACTIVITY_TIMEOUT;VERBOSITY" "" ${ARGN}) + + # Parse arguments + if(NOT DEFINED CMMM_VERSION) + message("${BoldRed}!! [CMakeMM] VERSION unknown. Please provide a version !!${Reset}") + message(FATAL_ERROR) + endif() + + if(NOT ${CMMM_NO_COLOR}) + colors() + endif() + set_property(GLOBAL PROPERTY CMMM_NO_COLOR ${CMMM_NO_COLOR}) + + list( + INSERT + VERBOSITY + 0 + "FATAL_ERROR" + "SEND_ERROR" + "WARNING" + "AUTHOR_WARNING" + "DEPRECATION" + "NOTICE" + "STATUS" + "VERBOSE" + "DEBUG" + "TRACE" + ) + if(DEFINED CMMM_VERBOSITY) + list(FIND VERBOSITY ${CMMM_VERBOSITY} FOUND) + if(${FOUND} STREQUAL "-1") + message("${BoldYellow}## [CMakeMM] VERBOSITY ${CMMM_VERBOSITY} unknown. VERBOSITY set to STATUS. ##${Reset}") + set(CMMM_VERBOSITY "STATUS") + endif() + elseif(DEFINED CMAKE_MESSAGE_LOG_LEVEL) + list(FIND VERBOSITY ${CMAKE_MESSAGE_LOG_LEVEL} FOUND) + if(${FOUND} STREQUAL "-1") + message("${BoldYellow}## [CMakeMM] VERBOSITY ${CMAKE_MESSAGE_LOG_LEVEL} unknown. VERBOSITY set to STATUS. ##${Reset}") + set(CMMM_VERBOSITY "STATUS") + else() + set(CMMM_VERBOSITY ${CMAKE_MESSAGE_LOG_LEVEL}) + endif() + else() + set(CMMM_VERBOSITY "STATUS") + endif() + set_property(GLOBAL PROPERTY CMMM_VERBOSITY ${CMMM_VERBOSITY}) + + if(NOT DEFINED CMMM_TIMEOUT) + set(CMMM_TIMEOUT 10) + endif() + set_property(GLOBAL PROPERTY CMMM_TIMEOUT ${CMMM_TIMEOUT}) + + if(NOT DEFINED CMMM_INACTIVITY_TIMEOUT) + set(CMMM_INACTIVITY_TIMEOUT 5) + endif() + set_property(GLOBAL PROPERTY CMMM_INACTIVITY_TIMEOUT ${CMMM_INACTIVITY_TIMEOUT}) + + if(NOT DEFINED CMMM_GIT_REPOSITORY) + set(CMMM_GIT_REPOSITORY "flagarde/CMakeMM") + list(APPEND ARGN URL ${CMMM_GIT_REPOSITORY}) + endif() + set_property(GLOBAL PROPERTY CMMM_GIT_REPOSITORY ${CMMM_GIT_REPOSITORY}) + + set(CMMM_GIT_URL_RELEASE "https://github.com/${CMMM_GIT_REPOSITORY}/releases/download/v${CMMM_VERSION}") + set_property(GLOBAL PROPERTY CMMM_GIT_URL_RELEASE ${CMMM_GIT_URL_RELEASE}) + + if(NOT DEFINED CMMM_DESTINATION) + set(CMMM_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/CMakeMM") + else() + get_filename_component(CMMM_DESTINATION "${CMMM_DESTINATION}" ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) + endif() + + set(CMMM_DESTINATION "${CMMM_DESTINATION}/${CMMM_VERSION}") + set_property(GLOBAL PROPERTY CMMM_DESTINATION ${CMMM_DESTINATION}) + + # add the CMakeMM installation directory to CMAKE_MODULE_PATH + list(INSERT CMAKE_MODULE_PATH 0 "${CMMM_DESTINATION}") + list(REMOVE_DUPLICATES CMAKE_MODULE_PATH) + set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) + + # Guard against multiple processes trying to use the CMakeMM dir simultaneously + file(LOCK "${CMMM_DESTINATION}" DIRECTORY GUARD PROCESS TIMEOUT 0 RESULT_VARIABLE CMMM_LOCK) + if(NOT ${CMMM_LOCK} STREQUAL "0") + if(${CMMM_VERBOSITY} STREQUAL VERBOSE) + message("${BoldYellow}## [CMakeMM] Fail to lock the directory ${CMMM_DESTINATION} (${CMMM_LOCK}). ##${Reset}") + endif() + else() + if(${CMMM_VERBOSITY} STREQUAL DEBUG) + message("${BoldGreen}** [CMakeMM] Directory ${CMMM_DESTINATION} locked successfully. **${Reset}") + endif() + endif() + + # The file that we first download + set(CMMM_ENTRY_FILE "${CMMM_DESTINATION}/Entry.cmake") + + # Downloading entry.cmake + if(NOT EXISTS "${CMMM_ENTRY_FILE}" OR ${CMMM_ALWAYS_DOWNLOAD}) + message("${BoldMagenta}-- [CMakeMM] Downloading CMakeMM version ${CMMM_VERSION} --${Reset}") + message("${BoldMagenta}-- [CMakeMM] Downloading Entry.cmake\n From : ${CMMM_GIT_URL_RELEASE}/Entry.cmake\n To : ${CMMM_ENTRY_FILE} --${Reset}") + file(DOWNLOAD "${CMMM_GIT_URL_RELEASE}/Entry.cmake" "${CMMM_ENTRY_FILE}.tmp" STATUS CMMM_STATUS TIMEOUT ${CMMM_TIMEOUT} INACTIVITY_TIMEOUT ${CMMM_INACTIVITY_TIMEOUT}) + list(GET CMMM_STATUS 0 CMMM_RC) + list(GET CMMM_STATUS 1 CMMM_MSG) + if(${CMMM_RC}) + if(NOT EXISTS ${CMMM_ENTRY_FILE}) + message("${BoldRed}!! [CMakeMM] Failed to download ${CMMM_GIT_URL_RELEASE}/Entry.cmake file.\n Error : ${CMMM_MSG} !!${Reset}") + message(FATAL_ERROR) + else() + message("${BoldYellow}## [CMakeMM] Failed to download ${CMMM_GIT_URL_RELEASE}/Entry.cmake file.\n Error : ${CMMM_MSG} !!${Reset}") + message("${BoldYellow}## [CMakeMM] Using last downloaded version. ##${Reset}") + endif() + else() + file(RENAME "${CMMM_ENTRY_FILE}.tmp" "${CMMM_ENTRY_FILE}") + endif() + endif() + + # This will trigger a warning if GetCMakeMM.cmake is not up-to-date ^^^ DO NOT CHANGE THIS LINE vvv + set(CMMM_BOOTSTRAP_VERSION 1.0) + # ^^^ DO NOT CHANGE THIS LINE ^^^ + + # Include Entry.cmake + include("${CMMM_ENTRY_FILE}") + + # Use Entry + cmmm_entry(${ARGN}) + + # Unlock the lock + file(LOCK "${CMMM_DESTINATION}" DIRECTORY RESULT_VARIABLE CMMM_LOCK RELEASE) + if(NOT ${CMMM_LOCK} STREQUAL "0") + if(${CMMM_VERBOSITY} STREQUAL VERBOSE) + message("${BoldYellow}## [CMakeMM] Fail to unlock the directory ${CMMM_DESTINATION} (${CMMM_LOCK}). ##${Reset}") + endif() + else() + if(${CMMM_VERBOSITY} STREQUAL DEBUG) + message("${BoldGreen}** [CMakeMM] Directory ${CMMM_DESTINATION} unlocked successfully. **${Reset}") + endif() + endif() + +endfunction() diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 913bc6a..a2165ed 100755 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -43,8 +43,8 @@ set(SRC ) add_library(MyLib STATIC ${SRC}) -target_include_directories(MyLib PRIVATE PUBLIC $ PUBLIC ${LCIO_INCLUDE_DIRS} PUBLIC ${INCLUDE_OUTPUT_DIR} PUBLIC ${Geant4_INCLUDE_DIRS} PUBLIC ${ROOT_INCLUDE_DIRS}) -target_link_libraries(MyLib PUBLIC ${ROOT_LIBRARIES} PUBLIC ${Geant4_LIBRARIES} PUBLIC ${LCIO_LIBRARIES}) +target_include_directories(MyLib PRIVATE PUBLIC $ PUBLIC lcio PUBLIC ${INCLUDE_OUTPUT_DIR} PUBLIC ${Geant4_INCLUDE_DIRS} PUBLIC ${ROOT_INCLUDE_DIRS}) +target_link_libraries(MyLib PUBLIC ${ROOT_LIBRARIES} PUBLIC ${Geant4_LIBRARIES} PUBLIC lcio) set_target_properties(MyLib PROPERTIES PUBLIC_HEADER "${INCLUDES}") install(TARGETS MyLib RUNTIME DESTINATION bin LIBRARY DESTINATION ${LIBRARY_OUTPUT_DIR} ARCHIVE DESTINATION ${ARCHIVE_OUTPUT_DIR} PUBLIC_HEADER DESTINATION include) From bde653f9b1dba4176a9fde74da4188ce68951c40 Mon Sep 17 00:00:00 2001 From: flagarde Date: Mon, 28 Dec 2020 16:04:54 +0800 Subject: [PATCH 2/2] Fix for china --- CMakeLists.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 157abb8..83d8f19 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,13 +6,12 @@ set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake") # Download CMakeCM include(GetCMakeMM) -cmmm(VERSION "1.1" - GIT_REPOSITORY "flagarde/CMakeMM" - VERBOSITY VERBOSE - DESTINATION "CMakeMM" - ) +cmmm(VERSION "1.2" + GIT_REPOSITORY "flagarde/CMakeMM" + VERBOSITY VERBOSE + DESTINATION "CMakeMM") -cmmm_modules_list(URL "https://raw.githubusercontent.com/flagarde/CMakeCMTests" BRANCH master DESTINATION "Modules") +cmmm_modules_list(URL "https://cdn.jsdelivr.net/gh/flagarde/CMakeCMTests@master" BRANCH "/" DESTINATION "Modules") #PreventInSourceBuilds is in common but try to avoid downloading many files include(PreventInSourceBuilds)