diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a965ee0822cb41e994cd30114f1bf67183c81c5..80c8f14dba1cba3f6f060fff53c21f23c9373859 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ option(TADAH_ENABLE_FAST_MATH "Enable fast math optimizations" OFF) # 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. You may need to remove CMakeCache.txt and CMakeFiles dir. ") + message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles dir. ") endif() set(CMAKE_CXX_STANDARD 11) @@ -24,7 +24,7 @@ set(CMAKE_CXX_FLAGS_DEBUG FORCE) set(CMAKE_CXX_FLAGS_RELEASE - "-g -O3 -Wall -Wpedantic -Wextra" + "-g -O3 -Wall" CACHE STRING "Release build." FORCE) @@ -35,49 +35,82 @@ set(CMAKE_CXX_FLAGS_PROFILE "Flags used by the C++ compiler during profile builds." FORCE) +set(CMAKE_CXX_FLAGS_DEVELOP + "-g -O3 -Wall -Wpedantic -Wextra" + CACHE STRING + "Release build." + FORCE) + # Set default build type if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) + set(CMAKE_BUILD_TYPE Release) +endif() + +string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE) +if (CMAKE_BUILD_TYPE STREQUAL "DEVELOP") + function(find_directory_case_insensitive target_name search_dir result_var) + execute_process( + COMMAND find "${search_dir}" -maxdepth 1 -type d -iname "${target_name}" + OUTPUT_VARIABLE found_dir + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + if(found_dir) + set(${result_var} "${found_dir}" PARENT_SCOPE) + message("${TADAH} Develop build: Found directory: ${found_dir}") + else() + set(${result_var} "" PARENT_SCOPE) + message("${TADAH} Develop build: Directory not found.") + endif() + endfunction() + + find_directory_case_insensitive("md" "$ENV{TADAH_PATH}" DEVELOP_MD_DIR) + set(FETCHCONTENT_SOURCE_DIR_TADAH.MD "${DEVELOP_MD_DIR}") endif() # Check is build supported string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE) if (CMAKE_BUILD_TYPE STREQUAL "DEBUG" - OR - CMAKE_BUILD_TYPE STREQUAL "RELEASE" - OR - CMAKE_BUILD_TYPE STREQUAL "PROFILE" - ) - message(STATUS "${TADAH} Build type: ${CMAKE_BUILD_TYPE}.") + OR + CMAKE_BUILD_TYPE STREQUAL "RELEASE" + OR + CMAKE_BUILD_TYPE STREQUAL "PROFILE" + OR + CMAKE_BUILD_TYPE STREQUAL "DEVELOP" +) + message(STATUS "${TADAH} Build type: ${CMAKE_BUILD_TYPE}.") else() - message(FATAL_ERROR " - Selected build type is not supported: ${CMAKE_BUILD_TYPE}. - Supported build types: Release, Debug, Profile" - ) + message(FATAL_ERROR " + Selected build type is not supported: ${CMAKE_BUILD_TYPE}. + Supported build types: Release, Debug, Profile" + ) endif() # Update the documentation string of CMAKE_BUILD_TYPE for GUIs set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING - "Choose the type of build, options are: None Debug Release Profile." + "Choose the type of build, options are: None Debug Release Profile Develop." FORCE) -# Required for GitLab CI/CD + +include(FetchContent) if(DEFINED ENV{CI_COMMIT_REF_NAME}) - set(GIT_BRANCH "$ENV{CI_COMMIT_REF_NAME}") + set(GIT_BRANCH "$ENV{CI_COMMIT_REF_NAME}") +elseif(DEFINED ENV{READTHEDOCS}) + set(GIT_BRANCH "$ENV{READTHEDOCS_VERSION}") else() - execute_process( - COMMAND git rev-parse --symbolic-full-name --abbrev-ref HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_BRANCH - OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process( + COMMAND git rev-parse --symbolic-full-name --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE) endif() +message(STATUS "${TADAH}.LAMMPS Using GIT_BRANCH: ${GIT_BRANCH}.") -include(FetchContent) FetchContent_Declare( Tadah.MD GIT_REPOSITORY https://git.ecdf.ed.ac.uk/tadah/md.git GIT_TAG origin/${GIT_BRANCH} - ) +) FetchContent_MakeAvailable(Tadah.MD) add_library(tadah.lammps STATIC lammps_tadah.cpp) @@ -89,35 +122,35 @@ target_link_libraries (tadah.lammps PUBLIC ${LAPACK_LIBRARIES}) ######################################################################### if(TADAH_MARCH_NATIVE) - include(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) - if(COMPILER_SUPPORTS_MARCH_NATIVE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") - else() - message(STATUS "${TADAH} ...but -march=native is not supported") - endif() + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) + if(COMPILER_SUPPORTS_MARCH_NATIVE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") + else() + message(STATUS "${TADAH} ...but -march=native is not supported") + endif() endif() message(STATUS "${TADAH} Build with -march=native in ${TADAH_MARCH_NATIVE}") ######################################################################### ######################################################################### if(TADAH_ENABLE_FAST_MATH) - if((CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "GNU")) - add_compile_options(-ffast-math) - elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - add_compile_options(/fp:fast) - endif() + if((CMAKE_CXX_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "GNU")) + add_compile_options(-ffast-math) + elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + add_compile_options(/fp:fast) + endif() else() - if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - add_compile_options(/fp:precise) - endif() + if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + add_compile_options(/fp:precise) + endif() endif() message(STATUS "${TADAH}: Build with fast math optimisation is ${TADAH_ENABLE_FAST_MATH}") ######################################################################### if(TADAH_BUILD_TESTS) - include(CTest) - add_subdirectory(tests) + include(CTest) + add_subdirectory(tests) endif() message(STATUS "===================================================================")