diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 182dd302b6..44a5ced761 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -5,8 +5,8 @@ Thank your for considering to contribute to the LAMMPS software project. The following is a set of guidelines as well as explanations of policies and work flows for contributing to the LAMMPS molecular dynamics software project. These guidelines focus on submitting issues or pull requests on the LAMMPS GitHub project. Thus please also have a look at: -* [The guide for submitting new features in the LAMMPS manual](https://lammps.sandia.gov/doc/Modify_contribute.html) -* [The guide on programming style and requirement in the LAMMPS manual](https://lammps.sandia.gov/doc/Modify_contribute.html) +* [The guide for submitting new features in the LAMMPS manual](https://www.lammps.org/doc/Modify_contribute.html) +* [The guide on programming style and requirement in the LAMMPS manual](https://www.lammps.org/doc/Modify_style.html) * [The GitHub tutorial in the LAMMPS manual](http://lammps.sandia.gov/doc/Howto_github.html) ## Table of Contents diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..5ace4600a1 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index f9503e0e1f..07f7564727 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -5,12 +5,19 @@ on: push: branches: [develop] + workflow_dispatch: + jobs: analyze: name: Analyze if: ${{ github.repository == 'lammps/lammps' }} runs-on: ubuntu-latest + permissions: + security-events: write + actions: read + contents: read + strategy: fail-fast: false matrix: @@ -18,17 +25,17 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 2 - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: '3.x' - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} config-file: ./.github/codeql/${{ matrix.language }}.yml @@ -46,4 +53,4 @@ jobs: cmake --build . --parallel 2 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index b31c262e32..7747be7b46 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -5,6 +5,8 @@ on: push: branches: [develop] + workflow_dispatch: + jobs: build: name: Windows Compilation Test @@ -13,12 +15,12 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 2 - name: Select Python version - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: '3.10' diff --git a/.github/workflows/unittest-macos.yml b/.github/workflows/unittest-macos.yml index a222380f60..e6e5ccfdc8 100644 --- a/.github/workflows/unittest-macos.yml +++ b/.github/workflows/unittest-macos.yml @@ -5,6 +5,8 @@ on: push: branches: [develop] + workflow_dispatch: + jobs: build: name: MacOS Unit Test @@ -15,7 +17,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 2 @@ -26,7 +28,7 @@ jobs: run: mkdir build - name: Set up ccache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ env.CCACHE_DIR }} key: macos-ccache-${{ github.sha }} diff --git a/cmake/CMakeLists.jpeg b/cmake/CMakeLists.jpeg new file mode 100644 index 0000000000..f0bd85a90d --- /dev/null +++ b/cmake/CMakeLists.jpeg @@ -0,0 +1,615 @@ +cmake_minimum_required(VERSION 3.10) +# When using CMake 3.4 and later, don't export symbols from executables unless +# the CMAKE_ENABLE_EXPORTS variable is set. +if(POLICY CMP0065) + cmake_policy(SET CMP0065 NEW) +endif() +if (POLICY CMP0077) + cmake_policy(SET CMP0077 NEW) +endif() +if(CMAKE_EXECUTABLE_SUFFIX) + set(CMAKE_EXECUTABLE_SUFFIX_TMP ${CMAKE_EXECUTABLE_SUFFIX}) +endif() + +project(libjpeg-turbo C) +set(VERSION 2.1.3) +set(COPYRIGHT_YEAR "1991-2022") +string(REPLACE "." ";" VERSION_TRIPLET ${VERSION}) +list(GET VERSION_TRIPLET 0 VERSION_MAJOR) +list(GET VERSION_TRIPLET 1 VERSION_MINOR) +list(GET VERSION_TRIPLET 2 VERSION_REVISION) +function(pad_number NUMBER OUTPUT_LEN) + string(LENGTH "${${NUMBER}}" INPUT_LEN) + if(INPUT_LEN LESS OUTPUT_LEN) + math(EXPR ZEROES "${OUTPUT_LEN} - ${INPUT_LEN} - 1") + set(NUM ${${NUMBER}}) + foreach(C RANGE ${ZEROES}) + set(NUM "0${NUM}") + endforeach() + set(${NUMBER} ${NUM} PARENT_SCOPE) + endif() +endfunction() +pad_number(VERSION_MINOR 3) +pad_number(VERSION_REVISION 3) +set(LIBJPEG_TURBO_VERSION_NUMBER ${VERSION_MAJOR}${VERSION_MINOR}${VERSION_REVISION}) + +# CMake 3.14 and later sets CMAKE_MACOSX_BUNDLE to TRUE by default when +# CMAKE_SYSTEM_NAME is iOS, tvOS, or watchOS, which breaks the libjpeg-turbo +# build. (Specifically, when CMAKE_MACOSX_BUNDLE is TRUE, executables for +# Apple platforms are built as application bundles, which causes CMake to +# complain that our install() directives for executables do not specify a +# BUNDLE DESTINATION. Even if CMake did not complain, building executables as +# application bundles would break our iOS packages.) +set(CMAKE_MACOSX_BUNDLE FALSE) + +string(TIMESTAMP DEFAULT_BUILD "%Y%m%d") +set(BUILD ${DEFAULT_BUILD} CACHE STRING "Build string (default: ${DEFAULT_BUILD})") + +# NOTE: On Windows, this does nothing except when using MinGW or Cygwin. +# CMAKE_BUILD_TYPE has no meaning in Visual Studio, and it always defaults to +# Debug when using NMake. +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() +message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}") + +message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}") + +include(cmakescripts/PackageInfo.cmake) + +# Detect CPU type and whether we're building 64-bit or 32-bit code +math(EXPR BITS "${CMAKE_SIZEOF_VOID_P} * 8") +string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} CMAKE_SYSTEM_PROCESSOR_LC) +set(COUNT 1) +foreach(ARCH ${CMAKE_OSX_ARCHITECTURES}) + if(COUNT GREATER 1) + message(FATAL_ERROR "The libjpeg-turbo build system does not support multiple values in CMAKE_OSX_ARCHITECTURES.") + endif() + math(EXPR COUNT "${COUNT}+1") +endforeach() +if(CMAKE_SYSTEM_PROCESSOR_LC MATCHES "x86_64" OR + CMAKE_SYSTEM_PROCESSOR_LC MATCHES "amd64" OR + CMAKE_SYSTEM_PROCESSOR_LC MATCHES "i[0-9]86" OR + CMAKE_SYSTEM_PROCESSOR_LC MATCHES "x86" OR + CMAKE_SYSTEM_PROCESSOR_LC MATCHES "ia32") + if(BITS EQUAL 64 OR CMAKE_C_COMPILER_ABI MATCHES "ELF X32") + set(CPU_TYPE x86_64) + else() + set(CPU_TYPE i386) + endif() + if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ${CPU_TYPE}) + set(CMAKE_SYSTEM_PROCESSOR ${CPU_TYPE}) + endif() +elseif(CMAKE_SYSTEM_PROCESSOR_LC STREQUAL "aarch64" OR + CMAKE_SYSTEM_PROCESSOR_LC MATCHES "^arm") + if(BITS EQUAL 64) + set(CPU_TYPE arm64) + else() + set(CPU_TYPE arm) + endif() +elseif(CMAKE_SYSTEM_PROCESSOR_LC MATCHES "^ppc" OR + CMAKE_SYSTEM_PROCESSOR_LC MATCHES "^powerpc") + set(CPU_TYPE powerpc) +else() + set(CPU_TYPE ${CMAKE_SYSTEM_PROCESSOR_LC}) +endif() +if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR + CMAKE_OSX_ARCHITECTURES MATCHES "arm64" OR + CMAKE_OSX_ARCHITECTURES MATCHES "i386") + set(CPU_TYPE ${CMAKE_OSX_ARCHITECTURES}) +endif() +if(CMAKE_OSX_ARCHITECTURES MATCHES "ppc") + set(CPU_TYPE powerpc) +endif() +if(MSVC_IDE AND CMAKE_GENERATOR_PLATFORM MATCHES "arm64") + set(CPU_TYPE arm64) +endif() + +message(STATUS "${BITS}-bit build (${CPU_TYPE})") + +macro(report_directory var) + if(CMAKE_INSTALL_${var} STREQUAL CMAKE_INSTALL_FULL_${var}) + message(STATUS "CMAKE_INSTALL_${var} = ${CMAKE_INSTALL_${var}}") + else() + message(STATUS "CMAKE_INSTALL_${var} = ${CMAKE_INSTALL_${var}} (${CMAKE_INSTALL_FULL_${var}})") + endif() + mark_as_advanced(CLEAR CMAKE_INSTALL_${var}) +endmacro() + +set(DIRLIST "BINDIR;DATAROOTDIR;DOCDIR;INCLUDEDIR;LIBDIR") +if(UNIX) + list(APPEND DIRLIST "MANDIR") +endif() +foreach(dir ${DIRLIST}) + report_directory(${dir}) +endforeach() + + +############################################################################### +# CONFIGURATION OPTIONS +############################################################################### + +macro(boolean_number var) + if(${var}) + set(${var} 1 ${ARGN}) + else() + set(${var} 0 ${ARGN}) + endif() +endmacro() + +option(ENABLE_SHARED "Build shared libraries" FALSE) +boolean_number(ENABLE_SHARED) +option(ENABLE_STATIC "Build static libraries" TRUE) +boolean_number(ENABLE_STATIC) +option(REQUIRE_SIMD "Generate a fatal error if SIMD extensions are not available for this platform (default is to fall back to a non-SIMD build)" FALSE) +boolean_number(REQUIRE_SIMD) +option(WITH_12BIT "Encode/decode JPEG images with 12-bit samples (implies WITH_ARITH_DEC=0 WITH_ARITH_ENC=0 WITH_JAVA=0 WITH_SIMD=0 WITH_TURBOJPEG=0 )" FALSE) +boolean_number(WITH_12BIT) +option(WITH_ARITH_DEC "Include arithmetic decoding support when emulating the libjpeg v6b API/ABI" TRUE) +boolean_number(WITH_ARITH_DEC) +option(WITH_ARITH_ENC "Include arithmetic encoding support when emulating the libjpeg v6b API/ABI" TRUE) +boolean_number(WITH_ARITH_ENC) +if(CMAKE_C_COMPILER_ABI MATCHES "ELF X32") + set(WITH_JAVA 0) +else() + option(WITH_JAVA "Build Java wrapper for the TurboJPEG API library (implies ENABLE_SHARED=1)" FALSE) + boolean_number(WITH_JAVA) +endif() +option(WITH_JPEG7 "Emulate libjpeg v7 API/ABI (this makes ${CMAKE_PROJECT_NAME} backward-incompatible with libjpeg v6b)" FALSE) +boolean_number(WITH_JPEG7) +option(WITH_JPEG8 "Emulate libjpeg v8 API/ABI (this makes ${CMAKE_PROJECT_NAME} backward-incompatible with libjpeg v6b)" FALSE) +boolean_number(WITH_JPEG8) +option(WITH_MEM_SRCDST "Include in-memory source/destination manager functions when emulating the libjpeg v6b or v7 API/ABI" TRUE) +boolean_number(WITH_MEM_SRCDST) +option(WITH_SIMD "Include SIMD extensions, if available for this platform" FALSE) +boolean_number(WITH_SIMD) +option(WITH_TURBOJPEG "Include the TurboJPEG API library and associated test programs" FALSE) +boolean_number(WITH_TURBOJPEG) +option(WITH_FUZZ "Build fuzz targets" FALSE) + +macro(report_option var desc) + if(${var}) + message(STATUS "${desc} enabled (${var} = ${${var}})") + else() + message(STATUS "${desc} disabled (${var} = ${${var}})") + endif() +endmacro() + +if(WITH_JAVA) + set(ENABLE_SHARED 1) +endif() + +# Explicitly setting CMAKE_POSITION_INDEPENDENT_CODE=FALSE disables PIC for all +# targets, which will cause the shared library builds to fail. Thus, if shared +# libraries are enabled and CMAKE_POSITION_INDEPENDENT_CODE is explicitly set +# to FALSE, we need to unset it, thus restoring the default behavior +# (automatically using PIC for shared library targets.) +if(DEFINED CMAKE_POSITION_INDEPENDENT_CODE AND + NOT CMAKE_POSITION_INDEPENDENT_CODE AND ENABLE_SHARED) + unset(CMAKE_POSITION_INDEPENDENT_CODE CACHE) +endif() + +report_option(ENABLE_SHARED "Shared libraries") +report_option(ENABLE_STATIC "Static libraries") + +if(ENABLE_SHARED) + set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) +endif() + +if(WITH_JPEG8 OR WITH_JPEG7) + set(WITH_ARITH_ENC 1) + set(WITH_ARITH_DEC 1) +endif() +if(WITH_JPEG8) + set(WITH_MEM_SRCDST 0) +endif() + +if(WITH_12BIT) + set(WITH_ARITH_DEC 0) + set(WITH_ARITH_ENC 0) + set(WITH_JAVA 0) + set(WITH_SIMD 0) + set(WITH_TURBOJPEG 0) + set(BITS_IN_JSAMPLE 12) +else() + set(BITS_IN_JSAMPLE 8) +endif() +report_option(WITH_12BIT "12-bit JPEG support") + +if(WITH_ARITH_DEC) + set(D_ARITH_CODING_SUPPORTED 1) +endif() +if(NOT WITH_12BIT) + report_option(WITH_ARITH_DEC "Arithmetic decoding support") +endif() + +if(WITH_ARITH_ENC) + set(C_ARITH_CODING_SUPPORTED 1) +endif() +if(NOT WITH_12BIT) + report_option(WITH_ARITH_ENC "Arithmetic encoding support") +endif() + +if(NOT WITH_12BIT) + report_option(WITH_TURBOJPEG "TurboJPEG API library") + report_option(WITH_JAVA "TurboJPEG Java wrapper") +endif() + +if(WITH_MEM_SRCDST) + set(MEM_SRCDST_SUPPORTED 1) + set(MEM_SRCDST_FUNCTIONS "global: jpeg_mem_dest; jpeg_mem_src;") +endif() +if(NOT WITH_JPEG8) + report_option(WITH_MEM_SRCDST "In-memory source/destination managers") +endif() + +set(SO_AGE 2) +if(WITH_MEM_SRCDST) + set(SO_AGE 3) +endif() + +if(WITH_JPEG8) + set(JPEG_LIB_VERSION 80) +elseif(WITH_JPEG7) + set(JPEG_LIB_VERSION 70) +else() + set(JPEG_LIB_VERSION 62) +endif() + +math(EXPR JPEG_LIB_VERSION_DIV10 "${JPEG_LIB_VERSION} / 10") +math(EXPR JPEG_LIB_VERSION_MOD10 "${JPEG_LIB_VERSION} % 10") +if(JPEG_LIB_VERSION STREQUAL "62") + set(DEFAULT_SO_MAJOR_VERSION ${JPEG_LIB_VERSION}) +else() + set(DEFAULT_SO_MAJOR_VERSION ${JPEG_LIB_VERSION_DIV10}) +endif() +if(JPEG_LIB_VERSION STREQUAL "80") + set(DEFAULT_SO_MINOR_VERSION 2) +else() + set(DEFAULT_SO_MINOR_VERSION 0) +endif() + +# This causes SO_MAJOR_VERSION/SO_MINOR_VERSION to reset to defaults if +# WITH_JPEG7 or WITH_JPEG8 has changed. +if((DEFINED WITH_JPEG7_INT AND NOT WITH_JPEG7 EQUAL WITH_JPEG7_INT) OR + (DEFINED WITH_JPEG8_INT AND NOT WITH_JPEG8 EQUAL WITH_JPEG8_INT)) + set(FORCE_SO_VERSION "FORCE") +endif() +set(WITH_JPEG7_INT ${WITH_JPEG7} CACHE INTERNAL "") +set(WITH_JPEG8_INT ${WITH_JPEG8} CACHE INTERNAL "") + +set(SO_MAJOR_VERSION ${DEFAULT_SO_MAJOR_VERSION} CACHE STRING + "Major version of the libjpeg API shared library (default: ${DEFAULT_SO_MAJOR_VERSION})" + ${FORCE_SO_VERSION}) +set(SO_MINOR_VERSION ${DEFAULT_SO_MINOR_VERSION} CACHE STRING + "Minor version of the libjpeg API shared library (default: ${DEFAULT_SO_MINOR_VERSION})" + ${FORCE_SO_VERSION}) + +set(JPEG_LIB_VERSION_DECIMAL "${JPEG_LIB_VERSION_DIV10}.${JPEG_LIB_VERSION_MOD10}") +message(STATUS "Emulating libjpeg API/ABI v${JPEG_LIB_VERSION_DECIMAL} (WITH_JPEG7 = ${WITH_JPEG7}, WITH_JPEG8 = ${WITH_JPEG8})") +message(STATUS "libjpeg API shared library version = ${SO_MAJOR_VERSION}.${SO_AGE}.${SO_MINOR_VERSION}") + +# Because the TurboJPEG API library uses versioned symbols and changes the +# names of functions whenever they are modified in a backward-incompatible +# manner, it is always backward-ABI-compatible with itself, so the major and +# minor SO versions don't change. However, we increase the middle number (the +# SO "age") whenever functions are added to the API. +set(TURBOJPEG_SO_MAJOR_VERSION 0) +set(TURBOJPEG_SO_AGE 2) +set(TURBOJPEG_SO_VERSION 0.${TURBOJPEG_SO_AGE}.0) + + +############################################################################### +# COMPILER SETTINGS +############################################################################### + +if(MSVC) + option(WITH_CRT_DLL + "Link all ${CMAKE_PROJECT_NAME} libraries and executables with the C run-time DLL (msvcr*.dll) instead of the static C run-time library (libcmt*.lib.) The default is to use the C run-time DLL only with the libraries and executables that need it." + FALSE) + if(NOT WITH_CRT_DLL) + # Use the static C library for all build types + foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) + if(${var} MATCHES "/MD") + string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}") + endif() + endforeach() + endif() + add_definitions(-D_CRT_NONSTDC_NO_WARNINGS) +endif() + +if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") + # Use the maximum optimization level for release builds + foreach(var CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO) + if(${var} MATCHES "-O2") + string(REGEX REPLACE "-O2" "-O3" ${var} "${${var}}") + endif() + endforeach() +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") + if(CMAKE_C_COMPILER_ID MATCHES "SunPro") + # Use the maximum optimization level for release builds + foreach(var CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO) + if(${var} MATCHES "-xO3") + string(REGEX REPLACE "-xO3" "-xO5" ${var} "${${var}}") + endif() + if(${var} MATCHES "-xO2") + string(REGEX REPLACE "-xO2" "-xO5" ${var} "${${var}}") + endif() + endforeach() + endif() +endif() + +string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC) + +set(EFFECTIVE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UC}}") +message(STATUS "Compiler flags = ${EFFECTIVE_C_FLAGS}") + +set(EFFECTIVE_LD_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UC}}") +message(STATUS "Linker flags = ${EFFECTIVE_LD_FLAGS}") + +include(CheckCSourceCompiles) +include(CheckIncludeFiles) +include(CheckTypeSize) + +check_type_size("size_t" SIZE_T) +check_type_size("unsigned long" UNSIGNED_LONG) + +if(SIZE_T EQUAL UNSIGNED_LONG) + check_c_source_compiles("int main(int argc, char **argv) { unsigned long a = argc; return __builtin_ctzl(a); }" + HAVE_BUILTIN_CTZL) +endif() +if(MSVC) + check_include_files("intrin.h" HAVE_INTRIN_H) +endif() + +if(UNIX) + if(CMAKE_CROSSCOMPILING) + set(RIGHT_SHIFT_IS_UNSIGNED 0) + else() + include(CheckCSourceRuns) + check_c_source_runs(" + #include + #include + int is_shifting_signed (long arg) { + long res = arg >> 4; + if (res == -0x7F7E80CL) + return 1; /* right shift is signed */ + /* see if unsigned-shift hack will fix it. */ + /* we can't just test exact value since it depends on width of long... */ + res |= (~0L) << (32-4); + if (res == -0x7F7E80CL) + return 0; /* right shift is unsigned */ + printf(\"Right shift isn't acting as I expect it to.\\\\n\"); + printf(\"I fear the JPEG software will not work at all.\\\\n\\\\n\"); + return 0; /* try it with unsigned anyway */ + } + int main (void) { + exit(is_shifting_signed(-0x7F7E80B1L)); + }" RIGHT_SHIFT_IS_UNSIGNED) + endif() +endif() + +if(MSVC) + set(INLINE_OPTIONS "__inline;inline") +else() + set(INLINE_OPTIONS "__inline__;inline") +endif() +option(FORCE_INLINE "Force function inlining" TRUE) +boolean_number(FORCE_INLINE) +if(FORCE_INLINE) + if(MSVC) + list(INSERT INLINE_OPTIONS 0 "__forceinline") + else() + list(INSERT INLINE_OPTIONS 0 "inline __attribute__((always_inline))") + list(INSERT INLINE_OPTIONS 0 "__inline__ __attribute__((always_inline))") + endif() +endif() +foreach(inline ${INLINE_OPTIONS}) + check_c_source_compiles("${inline} static int foo(void) { return 0; } int main(void) { return foo(); }" + INLINE_WORKS) + if(INLINE_WORKS) + set(INLINE ${inline}) + break() + endif() +endforeach() +if(NOT INLINE_WORKS) + message(FATAL_ERROR "Could not determine how to inline functions.") +endif() +message(STATUS "INLINE = ${INLINE} (FORCE_INLINE = ${FORCE_INLINE})") + +if(WITH_TURBOJPEG) + if(MSVC) + set(THREAD_LOCAL "__declspec(thread)") + else() + set(THREAD_LOCAL "__thread") + endif() + check_c_source_compiles("${THREAD_LOCAL} int i; int main(void) { i = 0; return i; }" HAVE_THREAD_LOCAL) + if(HAVE_THREAD_LOCAL) + message(STATUS "THREAD_LOCAL = ${THREAD_LOCAL}") + else() + message(WARNING "Thread-local storage is not available. The TurboJPEG API library's global error handler will not be thread-safe.") + unset(THREAD_LOCAL) + endif() +endif() + +if(UNIX AND NOT APPLE) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/conftest.map "VERS_1 { global: *; };") + set(CMAKE_REQUIRED_FLAGS + "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/conftest.map") + check_c_source_compiles("int main(void) { return 0; }" HAVE_VERSION_SCRIPT) + set(CMAKE_REQUIRED_FLAGS) + file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/conftest.map) + if(HAVE_VERSION_SCRIPT) + message(STATUS "Linker supports GNU-style version scripts") + set(MAPFLAG "-Wl,--version-script,") + set(TJMAPFLAG "-Wl,--version-script,") + else() + message(STATUS "Linker does not support GNU-style version scripts") + if(CMAKE_SYSTEM_NAME STREQUAL "SunOS") + # The Solaris linker doesn't like our version script for the libjpeg API + # library, but the version script for the TurboJPEG API library should + # still work. + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/conftest.map + "VERS_1 { global: foo; local: *; }; VERS_2 { global: foo2; } VERS_1;") + set(CMAKE_REQUIRED_FLAGS "-Wl,-M,${CMAKE_CURRENT_BINARY_DIR}/conftest.map -shared") + check_c_source_compiles("int foo() { return 0; } int foo2() { return 2; }" + HAVE_MAPFILE) + set(CMAKE_REQUIRED_FLAGS) + file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/conftest.map) + if(HAVE_MAPFILE) + message(STATUS "Linker supports mapfiles") + set(TJMAPFLAG "-Wl,-M,") + else() + message(STATUS "Linker does not support mapfiles") + endif() + endif() + endif() +endif() + +# Generate files +if(WIN32) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/win/jconfig.h.in jconfig.h) +else() + configure_file(jconfig.h.in jconfig.h) +endif() +configure_file(jconfigint.h.in jconfigint.h) +configure_file(jversion.h.in jversion.h) +if(UNIX) + configure_file(libjpeg.map.in libjpeg.map) +endif() + +# Include directories and compiler definitions +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + + +############################################################################### +# TARGETS +############################################################################### + +if(CMAKE_EXECUTABLE_SUFFIX_TMP) + set(CMAKE_EXECUTABLE_SUFFIX ${CMAKE_EXECUTABLE_SUFFIX_TMP}) +endif() +message(STATUS "CMAKE_EXECUTABLE_SUFFIX = ${CMAKE_EXECUTABLE_SUFFIX}") + +set(JPEG_SOURCES jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c + jcicc.c jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c + jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c jdatadst.c + jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c jdicc.c jdinput.c + jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c jdpostct.c jdsample.c + jdtrans.c jerror.c jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c + jidctint.c jidctred.c jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c) + +if(WITH_ARITH_ENC OR WITH_ARITH_DEC) + set(JPEG_SOURCES ${JPEG_SOURCES} jaricom.c) +endif() + +if(WITH_ARITH_ENC) + set(JPEG_SOURCES ${JPEG_SOURCES} jcarith.c) +endif() + +if(WITH_ARITH_DEC) + set(JPEG_SOURCES ${JPEG_SOURCES} jdarith.c) +endif() + +if(WITH_SIMD) + add_subdirectory(simd) + if(NEON_INTRINSICS) + add_definitions(-DNEON_INTRINSICS) + endif() +elseif(NOT WITH_12BIT) + message(STATUS "SIMD extensions: None (WITH_SIMD = ${WITH_SIMD})") +endif() +if(WITH_SIMD) + message(STATUS "SIMD extensions: ${CPU_TYPE} (WITH_SIMD = ${WITH_SIMD})") + if(MSVC_IDE OR XCODE) + set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1) + endif() +else() + add_library(simd OBJECT jsimd_none.c) + if(NOT WIN32 AND (CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED)) + set_target_properties(simd PROPERTIES POSITION_INDEPENDENT_CODE 1) + endif() +endif() + +if(WITH_JAVA) + add_subdirectory(java) +endif() + +if(ENABLE_SHARED) + add_subdirectory(sharedlib) +endif() + +if(ENABLE_STATIC) + add_library(jpeg-static STATIC ${JPEG_SOURCES} $ + ${SIMD_OBJS}) + if(NOT MSVC) + set_target_properties(jpeg-static PROPERTIES OUTPUT_NAME jpeg) + endif() +endif() + +if(WITH_TURBOJPEG) + if(ENABLE_SHARED) + set(TURBOJPEG_SOURCES ${JPEG_SOURCES} $ ${SIMD_OBJS} + turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c rdbmp.c rdppm.c + wrbmp.c wrppm.c) + set(TJMAPFILE ${CMAKE_CURRENT_SOURCE_DIR}/turbojpeg-mapfile) + if(WITH_JAVA) + set(TURBOJPEG_SOURCES ${TURBOJPEG_SOURCES} turbojpeg-jni.c) + include_directories(${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2}) + set(TJMAPFILE ${CMAKE_CURRENT_SOURCE_DIR}/turbojpeg-mapfile.jni) + endif() + if(MSVC) + configure_file(${CMAKE_SOURCE_DIR}/win/turbojpeg.rc.in + ${CMAKE_BINARY_DIR}/win/turbojpeg.rc) + set(TURBOJPEG_SOURCES ${TURBOJPEG_SOURCES} + ${CMAKE_BINARY_DIR}/win/turbojpeg.rc) + endif() + add_library(turbojpeg SHARED ${TURBOJPEG_SOURCES}) + set_property(TARGET turbojpeg PROPERTY COMPILE_FLAGS + "-DBMP_SUPPORTED -DPPM_SUPPORTED") + if(WIN32) + set_target_properties(turbojpeg PROPERTIES DEFINE_SYMBOL DLLDEFINE) + endif() + if(MINGW) + set_target_properties(turbojpeg PROPERTIES LINK_FLAGS -Wl,--kill-at) + endif() + if(APPLE AND (NOT CMAKE_OSX_DEPLOYMENT_TARGET OR + CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER 10.4)) + if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG) + set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,") + endif() + set_target_properties(turbojpeg PROPERTIES MACOSX_RPATH 1) + endif() + set_target_properties(turbojpeg PROPERTIES + SOVERSION ${TURBOJPEG_SO_MAJOR_VERSION} VERSION ${TURBOJPEG_SO_VERSION}) + if(TJMAPFLAG) + set_target_properties(turbojpeg PROPERTIES + LINK_FLAGS "${TJMAPFLAG}${TJMAPFILE}") + endif() + endif() + + if(ENABLE_STATIC) + add_library(turbojpeg-static STATIC ${JPEG_SOURCES} $ + ${SIMD_OBJS} turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c rdbmp.c + rdppm.c wrbmp.c wrppm.c) + set_property(TARGET turbojpeg-static PROPERTY COMPILE_FLAGS + "-DBMP_SUPPORTED -DPPM_SUPPORTED") + if(NOT MSVC) + set_target_properties(turbojpeg-static PROPERTIES OUTPUT_NAME turbojpeg) + endif() + endif() +endif() + +if(WIN32) + set(USE_SETMODE "-DUSE_SETMODE") +endif() +if(WITH_12BIT) + set(COMPILE_FLAGS "-DGIF_SUPPORTED -DPPM_SUPPORTED ${USE_SETMODE}") +else() + set(COMPILE_FLAGS "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED ${USE_SETMODE}") + set(CJPEG_BMP_SOURCES rdbmp.c rdtarga.c) + set(DJPEG_BMP_SOURCES wrbmp.c wrtarga.c) +endif() \ No newline at end of file diff --git a/cmake/CMakeLists.png b/cmake/CMakeLists.png new file mode 100644 index 0000000000..2521ab41be --- /dev/null +++ b/cmake/CMakeLists.png @@ -0,0 +1,741 @@ +# CMakeLists.txt + +# Copyright (C) 2018 Cosmin Truta +# Copyright (C) 2007,2009-2018 Glenn Randers-Pehrson +# Written by Christian Ehrlicher, 2007 +# Revised by Roger Lowman, 2009-2010 +# Revised by Clifford Yapp, 2011-2012,2017 +# Revised by Roger Leigh, 2016 +# Revised by Andreas Franek, 2016 +# Revised by Sam Serrels, 2017 +# Revised by Vadim Barkov, 2017 +# Revised by Vicky Pfau, 2018 +# Revised by Cameron Cawley, 2018 +# Revised by Cosmin Truta, 2018 +# Revised by Kyle Bentley, 2018 + +# This code is released under the libpng license. +# For conditions of distribution and use, see the disclaimer +# and license in png.h + +cmake_minimum_required(VERSION 3.10) +cmake_policy(VERSION 3.1) +# When using CMake 3.4 and later, don't export symbols from executables unless +# the CMAKE_ENABLE_EXPORTS variable is set. +if(POLICY CMP0065) + cmake_policy(SET CMP0065 NEW) +endif() +if (POLICY CMP0077) + cmake_policy(SET CMP0077 NEW) +endif() +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) + +project(libpng C ASM) +enable_testing() + +set(PNGLIB_MAJOR 1) +set(PNGLIB_MINOR 6) +set(PNGLIB_RELEASE 37) +set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR}) +set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE}) + +include(GNUInstallDirs) + +# needed packages + +# Allow users to specify location of Zlib. +# Useful if zlib is being built alongside this as a sub-project. +option(PNG_BUILD_ZLIB "Custom zlib Location, else find_package is used" ON) + +if(NOT PNG_BUILD_ZLIB) + find_package(ZLIB REQUIRED) + include_directories(${ZLIB_INCLUDE_DIR}) +endif() + +if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU) + find_library(M_LIBRARY m) +else() + # libm is not needed and/or not available + set(M_LIBRARY "") +endif() + +# COMMAND LINE OPTIONS +option(PNG_SHARED "Build shared lib" OFF) +option(PNG_STATIC "Build static lib" ON) +option(PNG_TESTS "Build libpng tests" OFF) + +# Many more configuration options could be added here +option(PNG_FRAMEWORK "Build OS X framework" OFF) +option(PNG_DEBUG "Build with debug output" OFF) +option(PNG_HARDWARE_OPTIMIZATIONS "Enable hardware optimizations" OFF) + +set(PNG_PREFIX "" CACHE STRING "Prefix to add to the API function names") +set(DFA_XTRA "" CACHE FILEPATH "File containing extra configuration settings") + +if(PNG_HARDWARE_OPTIMIZATIONS) + +# set definitions and sources for arm +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" OR + CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") + set(PNG_ARM_NEON_POSSIBLE_VALUES check on off) + set(PNG_ARM_NEON "check" CACHE STRING "Enable ARM NEON optimizations: + check: (default) use internal checking code; + off: disable the optimizations; + on: turn on unconditionally.") + set_property(CACHE PNG_ARM_NEON PROPERTY STRINGS + ${PNG_ARM_NEON_POSSIBLE_VALUES}) + list(FIND PNG_ARM_NEON_POSSIBLE_VALUES ${PNG_ARM_NEON} index) + if(index EQUAL -1) + message(FATAL_ERROR + "PNG_ARM_NEON must be one of [${PNG_ARM_NEON_POSSIBLE_VALUES}]") + elseif(NOT ${PNG_ARM_NEON} STREQUAL "off") + set(libpng_arm_sources + arm/arm_init.c + arm/filter_neon.S + arm/filter_neon_intrinsics.c + arm/palette_neon_intrinsics.c) + + if(${PNG_ARM_NEON} STREQUAL "on") + add_definitions(-DPNG_ARM_NEON_OPT=2) + elseif(${PNG_ARM_NEON} STREQUAL "check") + add_definitions(-DPNG_ARM_NEON_CHECK_SUPPORTED) + endif() + else() + add_definitions(-DPNG_ARM_NEON_OPT=0) + endif() +endif() + +# set definitions and sources for powerpc +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^powerpc*" OR + CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc64*") + set(PNG_POWERPC_VSX_POSSIBLE_VALUES on off) + set(PNG_POWERPC_VSX "on" CACHE STRING "Enable POWERPC VSX optimizations: + off: disable the optimizations.") + set_property(CACHE PNG_POWERPC_VSX PROPERTY STRINGS + ${PNG_POWERPC_VSX_POSSIBLE_VALUES}) + list(FIND PNG_POWERPC_VSX_POSSIBLE_VALUES ${PNG_POWERPC_VSX} index) + if(index EQUAL -1) + message(FATAL_ERROR + "PNG_POWERPC_VSX must be one of [${PNG_POWERPC_VSX_POSSIBLE_VALUES}]") + elseif(NOT ${PNG_POWERPC_VSX} STREQUAL "off") + set(libpng_powerpc_sources + powerpc/powerpc_init.c + powerpc/filter_vsx_intrinsics.c) + if(${PNG_POWERPC_VSX} STREQUAL "on") + add_definitions(-DPNG_POWERPC_VSX_OPT=2) + endif() + else() + add_definitions(-DPNG_POWERPC_VSX_OPT=0) + endif() +endif() + +# set definitions and sources for intel +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?86" OR + CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64*") + set(PNG_INTEL_SSE_POSSIBLE_VALUES on off) + set(PNG_INTEL_SSE "on" CACHE STRING "Enable INTEL_SSE optimizations: + off: disable the optimizations") + set_property(CACHE PNG_INTEL_SSE PROPERTY STRINGS + ${PNG_INTEL_SSE_POSSIBLE_VALUES}) + list(FIND PNG_INTEL_SSE_POSSIBLE_VALUES ${PNG_INTEL_SSE} index) + if(index EQUAL -1) + message(FATAL_ERROR + "PNG_INTEL_SSE must be one of [${PNG_INTEL_SSE_POSSIBLE_VALUES}]") + elseif(NOT ${PNG_INTEL_SSE} STREQUAL "off") + set(libpng_intel_sources + intel/intel_init.c + intel/filter_sse2_intrinsics.c) + if(${PNG_INTEL_SSE} STREQUAL "on") + add_definitions(-DPNG_INTEL_SSE_OPT=1) + endif() + else() + add_definitions(-DPNG_INTEL_SSE_OPT=0) + endif() +endif() + +# set definitions and sources for MIPS +if(CMAKE_SYSTEM_PROCESSOR MATCHES "mipsel*" OR + CMAKE_SYSTEM_PROCESSOR MATCHES "mips64el*") + set(PNG_MIPS_MSA_POSSIBLE_VALUES on off) + set(PNG_MIPS_MSA "on" CACHE STRING "Enable MIPS_MSA optimizations: + off: disable the optimizations") + set_property(CACHE PNG_MIPS_MSA PROPERTY STRINGS + ${PNG_MIPS_MSA_POSSIBLE_VALUES}) + list(FIND PNG_MIPS_MSA_POSSIBLE_VALUES ${PNG_MIPS_MSA} index) + if(index EQUAL -1) + message(FATAL_ERROR + "PNG_MIPS_MSA must be one of [${PNG_MIPS_MSA_POSSIBLE_VALUES}]") + elseif(NOT ${PNG_MIPS_MSA} STREQUAL "off") + set(libpng_mips_sources + mips/mips_init.c + mips/filter_msa_intrinsics.c) + if(${PNG_MIPS_MSA} STREQUAL "on") + add_definitions(-DPNG_MIPS_MSA_OPT=2) + endif() + else() + add_definitions(-DPNG_MIPS_MSA_OPT=0) + endif() +endif() + +else(PNG_HARDWARE_OPTIMIZATIONS) + +# set definitions and sources for arm +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" OR + CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") + add_definitions(-DPNG_ARM_NEON_OPT=0) +endif() + +# set definitions and sources for powerpc +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^powerpc*" OR + CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc64*") + add_definitions(-DPNG_POWERPC_VSX_OPT=0) +endif() + +# set definitions and sources for intel +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?86" OR + CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64*") + add_definitions(-DPNG_INTEL_SSE_OPT=0) +endif() + +# set definitions and sources for MIPS +if(CMAKE_SYSTEM_PROCESSOR MATCHES "mipsel*" OR + CMAKE_SYSTEM_PROCESSOR MATCHES "mips64el*") + add_definitions(-DPNG_MIPS_MSA_OPT=0) +endif() + +endif(PNG_HARDWARE_OPTIMIZATIONS) + +# SET LIBNAME +set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR}) + +# to distinguish between debug and release lib +set(CMAKE_DEBUG_POSTFIX "d") + +include(CheckCSourceCompiles) +option(ld-version-script "Enable linker version script" ON) +if(ld-version-script AND NOT APPLE) + # Check if LD supports linker scripts. + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map" "VERS_1 { + global: sym; + local: *; +}; + +VERS_2 { + global: sym2; + main; +} VERS_1; +") + set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS}) + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/conftest.map'") + check_c_source_compiles("void sym(void) {} +void sym2(void) {} +int main(void) {return 0;} +" HAVE_LD_VERSION_SCRIPT) + if(NOT HAVE_LD_VERSION_SCRIPT) + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE} "-Wl,-M -Wl,${CMAKE_CURRENT_BINARY_DIR}/conftest.map") + check_c_source_compiles("void sym(void) {} +void sym2(void) {} +int main(void) {return 0;} +" HAVE_SOLARIS_LD_VERSION_SCRIPT) + endif() + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE}) + file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/conftest.map") +endif() + +# Find symbol prefix. Likely obsolete and unnecessary with recent +# toolchains (it's not done in many other projects). +function(symbol_prefix) + set(SYMBOL_PREFIX) + + execute_process(COMMAND "${CMAKE_C_COMPILER}" "-E" "-" + INPUT_FILE /dev/null + OUTPUT_VARIABLE OUT + RESULT_VARIABLE STATUS) + + if(CPP_FAIL) + message(WARNING "Failed to run the C preprocessor") + endif() + + string(REPLACE "\n" ";" OUT "${OUT}") + foreach(line ${OUT}) + string(REGEX MATCH "^PREFIX=" found_match "${line}") + if(found_match) + string(REGEX REPLACE "^PREFIX=(.*\)" "\\1" prefix "${line}") + string(REGEX MATCH "__USER_LABEL_PREFIX__" found_match "${prefix}") + if(found_match) + string(REGEX REPLACE "(.*)__USER_LABEL_PREFIX__(.*)" "\\1\\2" prefix "${prefix}") + endif() + set(SYMBOL_PREFIX "${prefix}") + endif() + endforeach() + + message(STATUS "Symbol prefix: ${SYMBOL_PREFIX}") + set(SYMBOL_PREFIX "${SYMBOL_PREFIX}" PARENT_SCOPE) +endfunction() + +if(UNIX) + symbol_prefix() +endif() + +find_program(AWK NAMES gawk awk) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +if(NOT AWK OR ANDROID) + # No awk available to generate sources; use pre-built pnglibconf.h + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt + ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h) + add_custom_target(genfiles) # Dummy +else() + include(CMakeParseArguments) + # Generate .chk from .out with awk + # generate_chk(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]]) + function(generate_chk) + set(options) + set(oneValueArgs INPUT OUTPUT) + set(multiValueArgs DEPENDS) + cmake_parse_arguments(_GC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + if(NOT _GC_INPUT) + message(FATAL_ERROR "generate_chk: Missing INPUT argument") + endif() + if(NOT _GC_OUTPUT) + message(FATAL_ERROR "generate_chk: Missing OUTPUT argument") + endif() + + add_custom_command(OUTPUT "${_GC_OUTPUT}" + COMMAND "${CMAKE_COMMAND}" + "-DINPUT=${_GC_INPUT}" + "-DOUTPUT=${_GC_OUTPUT}" + -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake" + DEPENDS "${_GC_INPUT}" ${_GC_DEPENDS} + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + endfunction() + + # Generate .out from .c with awk + # generate_out(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]]) + function(generate_out) + set(options) + set(oneValueArgs INPUT OUTPUT) + set(multiValueArgs DEPENDS) + cmake_parse_arguments(_GO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + if(NOT _GO_INPUT) + message(FATAL_ERROR "generate_out: Missing INPUT argument") + endif() + if(NOT _GO_OUTPUT) + message(FATAL_ERROR "generate_out: Missing OUTPUT argument") + endif() + + add_custom_command(OUTPUT "${_GO_OUTPUT}" + COMMAND "${CMAKE_COMMAND}" + "-DINPUT=${_GO_INPUT}" + "-DOUTPUT=${_GO_OUTPUT}" + -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake" + DEPENDS "${_GO_INPUT}" ${_GO_DEPENDS} + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + endfunction() + + # Generate specific source file with awk + # generate_source(OUTPUT outputfile [DEPENDS dep1 [dep2...]]) + function(generate_source) + set(options) + set(oneValueArgs OUTPUT) + set(multiValueArgs DEPENDS) + cmake_parse_arguments(_GSO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + if(NOT _GSO_OUTPUT) + message(FATAL_ERROR "generate_source: Missing OUTPUT argument") + endif() + + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_GSO_OUTPUT}" + COMMAND "${CMAKE_COMMAND}" + "-DOUTPUT=${_GSO_OUTPUT}" + -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake" + DEPENDS ${_GSO_DEPENDS} + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + endfunction() + + # Copy file + function(generate_copy source destination) + add_custom_command(OUTPUT "${destination}" + COMMAND "${CMAKE_COMMAND}" -E remove "${destination}" + COMMAND "${CMAKE_COMMAND}" -E copy "${source}" + "${destination}" + DEPENDS "${source}") + endfunction() + + # Generate scripts/pnglibconf.h + generate_source(OUTPUT "scripts/pnglibconf.c" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa" + "${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk" + "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h") + + # Generate pnglibconf.c + generate_source(OUTPUT "pnglibconf.c" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa" + "${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk" + "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h") + + if(PNG_PREFIX) + set(PNGLIBCONF_H_EXTRA_DEPENDS + "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out" + "${CMAKE_CURRENT_SOURCE_DIR}/scripts/macro.lst") + set(PNGPREFIX_H_EXTRA_DEPENDS + "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out") + endif() + + generate_out(INPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out") + + # Generate pnglibconf.h + generate_source(OUTPUT "pnglibconf.h" + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out" + ${PNGLIBCONF_H_EXTRA_DEPENDS}) + + generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/intprefix.c" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out" + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h") + + generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/prefix.c" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h" + "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h" + "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out") + + # Generate pngprefix.h + generate_source(OUTPUT "pngprefix.h" + DEPENDS ${PNGPREFIX_H_EXTRA_DEPENDS}) + + generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/sym.c" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out" + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h") + + generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.c" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h" + "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h" + "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt") + + generate_out(INPUT "${CMAKE_CURRENT_SOURCE_DIR}/scripts/vers.c" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/png.h" + "${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h" + "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h") + + generate_chk(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/checksym.awk" + "${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.def") + + add_custom_target(symbol-check DEPENDS + "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk") + + generate_copy("${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out" + "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym") + generate_copy("${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out" + "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers") + + add_custom_target(genvers DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers") + add_custom_target(gensym DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym") + + add_custom_target("genprebuilt" + COMMAND "${CMAKE_COMMAND}" + "-DOUTPUT=scripts/pnglibconf.h.prebuilt" + -P "${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + + # A single target handles generation of all generated files. If + # they are depended upon separately by multiple targets, this + # confuses parallel make (it would require a separate top-level + # target for each file to track the dependencies properly). + add_custom_target(genfiles DEPENDS + "${CMAKE_CURRENT_BINARY_DIR}/libpng.sym" + "${CMAKE_CURRENT_BINARY_DIR}/libpng.vers" + "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c" + "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" + "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out" + "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h" + "${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out" + "${CMAKE_CURRENT_BINARY_DIR}/scripts/pnglibconf.c" + "${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out" + "${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out" + "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk" + "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out" + "${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out") +endif(NOT AWK OR ANDROID) + +# OUR SOURCES +set(libpng_public_hdrs + png.h + pngconf.h + "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h" +) +set(libpng_private_hdrs + pngpriv.h + pngdebug.h + pnginfo.h + pngstruct.h +) +if(AWK AND NOT ANDROID) + list(APPEND libpng_private_hdrs "${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h") +endif() +set(libpng_sources + ${libpng_public_hdrs} + ${libpng_private_hdrs} + png.c + pngerror.c + pngget.c + pngmem.c + pngpread.c + pngread.c + pngrio.c + pngrtran.c + pngrutil.c + pngset.c + pngtrans.c + pngwio.c + pngwrite.c + pngwtran.c + pngwutil.c + ${libpng_arm_sources} + ${libpng_intel_sources} + ${libpng_mips_sources} + ${libpng_powerpc_sources} +) +set(pngtest_sources + pngtest.c +) +set(pngvalid_sources + contrib/libtests/pngvalid.c +) +set(pngstest_sources + contrib/libtests/pngstest.c +) +set(pngunknown_sources + contrib/libtests/pngunknown.c +) +set(pngimage_sources + contrib/libtests/pngimage.c +) +set(pngfix_sources + contrib/tools/pngfix.c +) +set(png_fix_itxt_sources + contrib/tools/png-fix-itxt.c +) + +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_DEPRECATE) +endif() + +if(PNG_DEBUG) + add_definitions(-DPNG_DEBUG) +endif() + +# NOW BUILD OUR TARGET +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR}) + +unset(PNG_LIB_TARGETS) + +if(PNG_STATIC) + # does not work without changing name + set(PNG_LIB_NAME_STATIC png_static) + add_library(png_static STATIC ${libpng_sources}) + add_dependencies(png_static genfiles) + # MSVC doesn't use a different file extension for shared vs. static + # libs. We are able to change OUTPUT_NAME to remove the _static + # for all other platforms. + if(NOT MSVC) + set_target_properties(png_static PROPERTIES + OUTPUT_NAME "${PNG_LIB_NAME}" + CLEAN_DIRECT_OUTPUT 1) + else() + set_target_properties(png_static PROPERTIES + OUTPUT_NAME "${PNG_LIB_NAME}_static" + CLEAN_DIRECT_OUTPUT 1) + endif() + list(APPEND PNG_LIB_TARGETS png_static) + if(MSVC) + # msvc does not append 'lib' - do it here to have consistent name + set_target_properties(png_static PROPERTIES PREFIX "lib") + endif() + target_link_libraries(png_static ${M_LIBRARY}) +endif() + +if(NOT PNG_LIB_TARGETS) + message(SEND_ERROR + "No library variant selected to build. " + "Please enable at least one of the following options: " + "PNG_STATIC, PNG_SHARED, PNG_FRAMEWORK") +endif() + +# Set a variable with CMake code which: +# Creates a symlink from src to dest (if possible) or alternatively +# copies if different. +include(CMakeParseArguments) + +function(create_symlink DEST_FILE) + + cmake_parse_arguments(S "" "FILE;TARGET" "" ${ARGN}) + + if(NOT S_TARGET AND NOT S_FILE) + message(FATAL_ERROR "create_symlink: Missing TARGET or FILE argument") + endif() + + if(S_TARGET AND S_FILE) + message(FATAL_ERROR "create_symlink: Both source file ${S_FILE} and build target ${S_TARGET} arguments are present; can only have one.") + endif() + + if(S_FILE) + # If we don't need to symlink something that's coming from a build target, + # we can go ahead and symlink/copy at configure time. + if(CMAKE_HOST_WIN32 AND NOT CYGWIN) + execute_process( + COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${S_FILE} ${DEST_FILE} + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + else() + execute_process( + COMMAND ${CMAKE_COMMAND} -E create_symlink ${S_FILE} ${DEST_FILE} + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") + endif() + endif() + + if(S_TARGET) + # We need to use generator expressions, which can be a bit tricky, so for + # simplicity make the symlink a POST_BUILD step and use the TARGET + # signature of add_custom_command. + if(CMAKE_HOST_WIN32 AND NOT CYGWIN) + add_custom_command(TARGET ${S_TARGET} POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_if_different $ $/${DEST_FILE}) + else() + add_custom_command(TARGET ${S_TARGET} POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E create_symlink $ $/${DEST_FILE}) + endif() + endif() + +endfunction() + +# Create source generation scripts. +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genchk.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake @ONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genout.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake @ONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/gensrc.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake @ONLY) + +# libpng is a library so default to 'lib' +if(NOT DEFINED CMAKE_INSTALL_LIBDIR) + set(CMAKE_INSTALL_LIBDIR lib) +endif() + +# CREATE PKGCONFIG FILES +# We use the same files like ./configure, so we have to set its vars. +# Only do this on Windows for Cygwin - the files don't make much sense outside +# of a UNIX look-alike. +if(NOT WIN32 OR CYGWIN OR MINGW) + set(prefix ${CMAKE_INSTALL_PREFIX}) + set(exec_prefix ${CMAKE_INSTALL_PREFIX}) + set(libdir ${CMAKE_INSTALL_FULL_LIBDIR}) + set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR}) + set(LIBS "-lz -lm") + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY) + create_symlink(libpng.pc FILE ${PNGLIB_NAME}.pc) + + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in + ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY) + create_symlink(libpng-config FILE ${PNGLIB_NAME}-config) +endif() + +# SET UP LINKS +if(PNG_SHARED) + set_target_properties(png PROPERTIES +# VERSION 16.${PNGLIB_RELEASE}.1.6.37 + VERSION 16.${PNGLIB_RELEASE}.0 + SOVERSION 16 + CLEAN_DIRECT_OUTPUT 1) +endif() + +# INSTALL +if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) + install(TARGETS ${PNG_LIB_TARGETS} + EXPORT libpng + RUNTIME DESTINATION bin + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}) + + if(PNG_SHARED) + # Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin + if(CYGWIN OR MINGW) + create_symlink(libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} TARGET png) + install(FILES $/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} + DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + + if(NOT WIN32) + create_symlink(libpng${CMAKE_SHARED_LIBRARY_SUFFIX} TARGET png) + install(FILES $/libpng${CMAKE_SHARED_LIBRARY_SUFFIX} + DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + endif() + + if(PNG_STATIC) + if(NOT WIN32 OR CYGWIN OR MINGW) + create_symlink(libpng${CMAKE_STATIC_LIBRARY_SUFFIX} TARGET png_static) + install(FILES $/libpng${CMAKE_STATIC_LIBRARY_SUFFIX} + DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + endif() +endif() + +if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL) + install(FILES ${libpng_public_hdrs} DESTINATION include) + install(FILES ${libpng_public_hdrs} DESTINATION include/${PNGLIB_NAME}) +endif() +if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL) + if(NOT WIN32 OR CYGWIN OR MINGW) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin) + endif() +endif() + +if(NOT SKIP_INSTALL_PROGRAMS AND NOT SKIP_INSTALL_ALL) + install(TARGETS ${PNG_BIN_TARGETS} + RUNTIME DESTINATION bin) +endif() + +if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL) + # Install man pages + if(NOT PNG_MAN_DIR) + set(PNG_MAN_DIR "share/man") + endif() + install(FILES libpng.3 libpngpf.3 DESTINATION ${PNG_MAN_DIR}/man3) + install(FILES png.5 DESTINATION ${PNG_MAN_DIR}/man5) + # Install pkg-config files + if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config + DESTINATION bin) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config + DESTINATION bin) + endif() +endif() + +# Create an export file that CMake users can include() to import our targets. +if(NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL) + install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake) +endif() + +# what's with libpng-manual.txt and all the extra files? + +# UNINSTALL +# do we need this? + +# DIST +# do we need this? + +# to create msvc import lib for mingw compiled shared lib +# pexports libpng.dll > libpng.def +# lib /def:libpng.def /machine:x86 diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 75a0e87193..404048b705 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -105,8 +105,28 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") endif() endif() +# silence excessive warnings for new Intel Compilers +if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") + set(CMAKE_TUNE_DEFAULT "-Wno-tautological-constant-compare -Wno-unused-command-line-argument") +endif() + +# silence excessive warnings for PGI/NVHPC compilers +if((CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC") OR (CMAKE_CXX_COMPILER_ID STREQUAL "PGI")) + set(CMAKE_TUNE_DEFAULT "-Minform=severe") +endif() + +# silence nvcc warnings +if((PKG_KOKKOS) AND (Kokkos_ENABLE_CUDA) AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) + set(CMAKE_TUNE_DEFAULT "${CMAKE_TUNE_DEFAULT} -Xcudafe --diag_suppress=unrecognized_pragma") +endif() + # we require C++11 without extensions. Kokkos requires at least C++14 (currently) -set(CMAKE_CXX_STANDARD 11) +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 11) +endif() +if(CMAKE_CXX_STANDARD LESS 11) + message(FATAL_ERROR "C++ standard must be set to at least 11") +endif() if(PKG_KOKKOS AND (CMAKE_CXX_STANDARD LESS 14)) set(CMAKE_CXX_STANDARD 14) endif() @@ -115,9 +135,14 @@ set(CMAKE_CXX_EXTENSIONS OFF CACHE BOOL "Use compiler extensions") # ugly hacks for MSVC which by default always reports an old C++ standard in the __cplusplus macro # and prints lots of pointless warnings about "unsafe" functions if(MSVC) - add_compile_options(/Zc:__cplusplus) - add_compile_options(/wd4244) - add_compile_options(/wd4267) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options(/Zc:__cplusplus) + add_compile_options(/wd4244) + add_compile_options(/wd4267) + if(LAMMPS_EXCEPTIONS) + add_compile_options(/EHsc) + endif() + endif() add_compile_definitions(_CRT_SECURE_NO_WARNINGS) endif() @@ -141,10 +166,12 @@ option(CMAKE_POSITION_INDEPENDENT_CODE "Create object compatible with shared lib option(BUILD_TOOLS "Build and install LAMMPS tools (msi2lmp, binary2txt, chain)" OFF) option(BUILD_LAMMPS_SHELL "Build and install the LAMMPS shell" OFF) -# allow enabling clang-tidy for C++ files +# Support using clang-tidy for C++ files with selected options set(ENABLE_CLANG_TIDY OFF CACHE BOOL "Include clang-tidy processing when compiling") if(ENABLE_CLANG_TIDY) - set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*-header-filter=.*" CACHE STRING "") + set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=-*,performance-trivially-destructible,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-member-init,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-boolean-expr,readability-static-accessed-through-instance,readability-static-definition-in-anonymous-namespace,modernize-use-override,modernize-use-bool-literals,modernize-use-emplace,modernize-return-braced-init-list,modernize-use-equals-default,modernize-use-equals-delete,modernize-replace-random-shuffle,modernize-deprecated-headers,modernize-use-nullptr,modernize-use-noexcept,modernize-redundant-void-arg;-fix;-header-filter=.*,header-filter=library.h,header-filter=fmt/*.h" CACHE STRING "clang-tidy settings") +else() + unset(CMAKE_CXX_CLANG_TIDY CACHE) endif() include(GNUInstallDirs) @@ -190,6 +217,7 @@ set(STANDARD_PACKAGES DPD-SMOOTH DRUDE EFF + ELECTRODE EXTRA-COMPUTE EXTRA-DUMP EXTRA-FIX @@ -308,7 +336,9 @@ string(TOUPPER ${LAMMPS_SIZES} LAMMPS_SIZES) target_compile_definitions(lammps PUBLIC -DLAMMPS_${LAMMPS_SIZES}) # posix_memalign is not available on Windows -if(CMAKE_SYSTEM_NAME STREQUAL "Windows") +# with INTEL package and Intel compilers we use TBB's aligned malloc +if((CMAKE_SYSTEM_NAME STREQUAL "Windows") + AND NOT (PKG_INTEL AND ((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") OR (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")))) set(LAMMPS_MEMALIGN "0" CACHE STRING "posix_memalign() is not available on Windows" FORCE) else() set(LAMMPS_MEMALIGN "64" CACHE STRING "enables the use of the posix_memalign() call instead of malloc() when large chunks or memory are allocated by LAMMPS. Set to 0 to disable") @@ -330,10 +360,12 @@ pkg_depends(ATC MANYBODY) pkg_depends(AMOEBA KSPACE) pkg_depends(LATBOLTZ MPI) pkg_depends(SCAFACOS MPI) +pkg_depends(AMOEBA KSPACE) pkg_depends(DIELECTRIC KSPACE) pkg_depends(DIELECTRIC EXTRA-PAIR) pkg_depends(CG-DNA MOLECULE) pkg_depends(CG-DNA ASPHERE) +pkg_depends(ELECTRODE KSPACE) # detect if we may enable OpenMP support by default set(BUILD_OMP_DEFAULT OFF) @@ -371,7 +403,7 @@ if(BUILD_OMP) target_link_libraries(lmp PRIVATE OpenMP::OpenMP_CXX) endif() -if(PKG_MSCG OR PKG_ATC OR PKG_AWPMD OR PKG_ML-QUIP OR PKG_LATTE) +if(PKG_MSCG OR PKG_ATC OR PKG_AWPMD OR PKG_ML-QUIP OR PKG_LATTE OR PKG_ELECTRODE) enable_language(C) find_package(LAPACK) find_package(BLAS) @@ -470,6 +502,7 @@ set(CMAKE_TUNE_FLAGS "${CMAKE_TUNE_DEFAULT}" CACHE STRING "Compiler and machine separate_arguments(CMAKE_TUNE_FLAGS) foreach(_FLAG ${CMAKE_TUNE_FLAGS}) target_compile_options(lammps PRIVATE ${_FLAG}) + target_compile_options(lmp PRIVATE ${_FLAG}) endforeach() ######################################################################## # Basic system tests (standard libraries, headers, functions, types) # @@ -574,6 +607,10 @@ foreach(PKG_LIB POEMS ATC AWPMD H5MD MESONT) endif() endforeach() +if(PKG_ELECTRODE) + target_link_libraries(lammps PRIVATE ${LAPACK_LIBRARIES}) +endif() + if(PKG_AWPMD) target_link_libraries(awpmd PRIVATE ${LAPACK_LIBRARIES}) endif() @@ -752,14 +789,16 @@ if(BUILD_SHARED_LIBS) find_package(Python COMPONENTS Interpreter) endif() if(BUILD_IS_MULTI_CONFIG) - set(LIBLAMMPS_SHARED_BINARY ${CMAKE_BINARY_DIR}/$/liblammps${LAMMPS_MACHINE}${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(MY_BUILD_DIR ${CMAKE_BINARY_DIR}/$) else() - set(LIBLAMMPS_SHARED_BINARY ${CMAKE_BINARY_DIR}/liblammps${LAMMPS_MACHINE}${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(MY_BUILD_DIR ${CMAKE_BINARY_DIR}) endif() + set(LIBLAMMPS_SHARED_BINARY ${MY_BUILD_DIR}/liblammps${LAMMPS_MACHINE}${CMAKE_SHARED_LIBRARY_SUFFIX}) if(Python_EXECUTABLE) add_custom_target( install-python ${CMAKE_COMMAND} -E remove_directory build - COMMAND ${Python_EXECUTABLE} ${LAMMPS_PYTHON_DIR}/install.py -p ${LAMMPS_PYTHON_DIR}/lammps -l ${LIBLAMMPS_SHARED_BINARY} + COMMAND ${Python_EXECUTABLE} ${LAMMPS_PYTHON_DIR}/install.py -p ${LAMMPS_PYTHON_DIR}/lammps + -l ${LIBLAMMPS_SHARED_BINARY} -w ${MY_BUILD_DIR} COMMENT "Installing LAMMPS Python module") else() add_custom_target( @@ -922,6 +961,12 @@ if(PKG_KSPACE) else() message(STATUS "Kokkos FFT: cuFFT") endif() + elseif(Kokkos_ENABLE_HIP) + if(FFT STREQUAL "KISS") + message(STATUS "Kokkos FFT: KISS") + else() + message(STATUS "Kokkos FFT: hipFFT") + endif() else() message(STATUS "Kokkos FFT: ${FFT}") endif() diff --git a/cmake/CMakeLists.zlib b/cmake/CMakeLists.zlib new file mode 100644 index 0000000000..a33f14ce64 --- /dev/null +++ b/cmake/CMakeLists.zlib @@ -0,0 +1,195 @@ +cmake_minimum_required(VERSION 3.10) +# When using CMake 3.4 and later, don't export symbols from executables unless +# the CMAKE_ENABLE_EXPORTS variable is set. +if(POLICY CMP0065) + cmake_policy(SET CMP0065 NEW) +endif() +if (POLICY CMP0077) + cmake_policy(SET CMP0077 NEW) +endif() +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) + +project(zlib C) + +set(VERSION "1.2.11") + +option(ASM686 "Enable building i686 assembly implementation" OFF) +option(AMD64 "Enable building amd64 assembly implementation" OFF) + +set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") +set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") +set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") +set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages") +set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") + +include(CheckTypeSize) +include(CheckFunctionExists) +include(CheckIncludeFile) +include(CheckCSourceCompiles) + +check_include_file(sys/types.h HAVE_SYS_TYPES_H) +check_include_file(stdint.h HAVE_STDINT_H) +check_include_file(stddef.h HAVE_STDDEF_H) + +# +# Check to see if we have large file support +# +set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1) +# We add these other definitions here because CheckTypeSize.cmake +# in CMake 2.4.x does not automatically do so and we want +# compatibility with CMake 2.4.x. +if(HAVE_SYS_TYPES_H) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H) +endif() +if(HAVE_STDINT_H) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H) +endif() +if(HAVE_STDDEF_H) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) +endif() +check_type_size(off64_t OFF64_T) +check_type_size(off64_t OFF64_T) +if(HAVE_OFF64_T) + add_definitions(-D_LARGEFILE64_SOURCE=1) +endif() +set(CMAKE_REQUIRED_DEFINITIONS) # clear variable + +# +# Check for fseeko +# +check_function_exists(fseeko HAVE_FSEEKO) +if(NOT HAVE_FSEEKO) + add_definitions(-DNO_FSEEKO) +endif() + +# +# Check for unistd.h +# +check_include_file(unistd.h Z_HAVE_UNISTD_H) + +if(MSVC) + set(CMAKE_DEBUG_POSTFIX "d") + add_definitions(-D_CRT_SECURE_NO_DEPRECATE) + add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +endif() + +if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) + # If we're doing an out of source build and the user has a zconf.h + # in their source tree... + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h) + file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included) + endif() +endif() + +set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein + ${ZLIB_PC} @ONLY) +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein + ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) + + +#============================================================================ +# zlib +#============================================================================ + +set(ZLIB_PUBLIC_HDRS + ${CMAKE_CURRENT_BINARY_DIR}/zconf.h + zlib.h +) +set(ZLIB_PRIVATE_HDRS + crc32.h + deflate.h + gzguts.h + inffast.h + inffixed.h + inflate.h + inftrees.h + trees.h + zutil.h +) +set(ZLIB_SRCS + adler32.c + compress.c + crc32.c + deflate.c + gzclose.c + gzlib.c + gzread.c + gzwrite.c + inflate.c + infback.c + inftrees.c + inffast.c + trees.c + uncompr.c + zutil.c +) + +if(NOT MINGW) + set(ZLIB_DLL_SRCS + win32/zlib1.rc # If present will override custom build rule below. + ) +endif() + +if(CMAKE_COMPILER_IS_GNUCC) + if(ASM686) + set(ZLIB_ASMS contrib/asm686/match.S) + elseif (AMD64) + set(ZLIB_ASMS contrib/amd64/amd64-match.S) + endif () + + if(ZLIB_ASMS) + add_definitions(-DASMV) + set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE) + endif() +endif() + +if(MSVC) + if(ASM686) + ENABLE_LANGUAGE(ASM_MASM) + set(ZLIB_ASMS + contrib/masmx86/inffas32.asm + contrib/masmx86/match686.asm + ) + elseif (AMD64) + ENABLE_LANGUAGE(ASM_MASM) + set(ZLIB_ASMS + contrib/masmx64/gvmat64.asm + contrib/masmx64/inffasx64.asm + ) + endif() + + if(ZLIB_ASMS) + add_definitions(-DASMV -DASMINF) + endif() +endif() + +# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION +file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents) +string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*" + "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents}) + +if(MINGW) + # This gets us DLL resource information when compiling on MinGW. + if(NOT CMAKE_RC_COMPILER) + set(CMAKE_RC_COMPILER windres.exe) + endif() + + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj + COMMAND ${CMAKE_RC_COMPILER} + -D GCC_WINDRES + -I ${CMAKE_CURRENT_SOURCE_DIR} + -I ${CMAKE_CURRENT_BINARY_DIR} + -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj + -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc) + set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) +endif(MINGW) + +add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) + +if(UNIX) + # On unix-like platforms the library is almost always called libz + set_target_properties(zlibstatic PROPERTIES OUTPUT_NAME z) +endif() \ No newline at end of file diff --git a/cmake/CMakeSettings.json b/cmake/CMakeSettings.json index d8ef47a220..c139114c0b 100644 --- a/cmake/CMakeSettings.json +++ b/cmake/CMakeSettings.json @@ -8,7 +8,7 @@ "installRoot": "${workspaceRoot}\\install\\${name}", "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows.cmake", "buildCommandArgs": "", - "ctestCommandArgs": "", + "ctestCommandArgs": "-V", "inheritEnvironments": [ "msvc_x64_x64" ], "variables": [ { @@ -26,11 +26,6 @@ "value": "True", "type": "BOOL" }, - { - "name": "PKG_PYTHON", - "value": "True", - "type": "BOOL" - }, { "name": "ENABLE_TESTING", "value": "True", @@ -46,7 +41,7 @@ "installRoot": "${workspaceRoot}\\install\\${name}", "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows.cmake", "buildCommandArgs": "", - "ctestCommandArgs": "", + "ctestCommandArgs": "-V", "inheritEnvironments": [ "msvc_x64_x64" ], "variables": [ { @@ -64,11 +59,6 @@ "value": "True", "type": "BOOL" }, - { - "name": "PKG_PYTHON", - "value": "True", - "type": "BOOL" - }, { "name": "ENABLE_TESTING", "value": "True", @@ -102,11 +92,6 @@ "value": "True", "type": "BOOL" }, - { - "name": "PKG_PYTHON", - "value": "True", - "type": "BOOL" - }, { "name": "ENABLE_TESTING", "value": "True", @@ -122,7 +107,7 @@ "installRoot": "${workspaceRoot}\\install\\${name}", "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows.cmake -DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe", "buildCommandArgs": "", - "ctestCommandArgs": "", + "ctestCommandArgs": "-V", "inheritEnvironments": [ "clang_cl_x64" ], "variables": [ { @@ -141,7 +126,40 @@ "type": "BOOL" }, { - "name": "PKG_PYTHON", + "name": "ENABLE_TESTING", + "value": "True", + "type": "BOOL" + } + ] + }, + { + "name": "x64-Debug-IntelLLVM", + "generator": "Ninja", + "configurationType": "Debug", + "buildRoot": "${workspaceRoot}\\build\\${name}", + "installRoot": "${workspaceRoot}\\install\\${name}", + "buildCommandArgs": "", + "ctestCommandArgs": "-V", + "inheritEnvironments": [], + "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows-intel-llvm.cmake -C ${workspaceRoot}\\cmake\\presets\\windows.cmake", + "variables": [ + { + "name": "PKG_ELECTRODE", + "value": "True", + "type": "BOOL" + }, + { + "name": "BUILD_SHARED_LIBS", + "value": "True", + "type": "BOOL" + }, + { + "name": "BUILD_TOOLS", + "value": "True", + "type": "BOOL" + }, + { + "name": "LAMMPS_EXCEPTIONS", "value": "True", "type": "BOOL" }, @@ -149,8 +167,142 @@ "name": "ENABLE_TESTING", "value": "True", "type": "BOOL" + }, + { + "name": "FFT", + "value": "MKL", + "type": "STRING" + } + ] + }, + { + "name": "x64-Release-IntelLLVM", + "generator": "Ninja", + "configurationType": "Release", + "buildRoot": "${workspaceRoot}\\build\\${name}", + "installRoot": "${workspaceRoot}\\install\\${name}", + "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows-intel-llvm.cmake -C ${workspaceRoot}\\cmake\\presets\\windows.cmake", + "buildCommandArgs": "", + "ctestCommandArgs": "-V", + "inheritEnvironments": [], + "variables": [ + { + "name": "PKG_ELECTRODE", + "value": "True", + "type": "BOOL" + }, + { + "name": "BUILD_SHARED_LIBS", + "value": "True", + "type": "BOOL" + }, + { + "name": "BUILD_TOOLS", + "value": "True", + "type": "BOOL" + }, + { + "name": "LAMMPS_EXCEPTIONS", + "value": "True", + "type": "BOOL" + }, + { + "name": "ENABLE_TESTING", + "value": "True", + "type": "BOOL" + }, + { + "name": "FFT", + "value": "MKL", + "type": "STRING" + } + ] + }, + { + "name": "x64-Debug-Intel-Classic", + "generator": "Ninja", + "configurationType": "Debug", + "buildRoot": "${workspaceRoot}\\build\\${name}", + "installRoot": "${workspaceRoot}\\install\\${name}", + "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows-intel-classic.cmake -C ${workspaceRoot}\\cmake\\presets\\windows.cmake", + "buildCommandArgs": "", + "ctestCommandArgs": "-V", + "inheritEnvironments": [], + "variables": [ + { + "name": "PKG_ELECTRODE", + "value": "True", + "type": "BOOL" + }, + { + "name": "BUILD_SHARED_LIBS", + "value": "True", + "type": "BOOL" + }, + { + "name": "BUILD_TOOLS", + "value": "True", + "type": "BOOL" + }, + { + "name": "LAMMPS_EXCEPTIONS", + "value": "True", + "type": "BOOL" + }, + { + "name": "ENABLE_TESTING", + "value": "False", + "type": "BOOL" + }, + { + "name": "FFT", + "value": "MKL", + "type": "STRING" + } + ] + }, + { + "name": "x64-Release-Intel-Classic", + "generator": "Ninja", + "configurationType": "Release", + "buildRoot": "${workspaceRoot}\\build\\${name}", + "installRoot": "${workspaceRoot}\\install\\${name}", + "cmakeCommandArgs": "-C ${workspaceRoot}\\cmake\\presets\\windows-intel-classic.cmake -C ${workspaceRoot}\\cmake\\presets\\windows.cmake", + "buildCommandArgs": "", + "ctestCommandArgs": "-V", + "inheritEnvironments": [], + "variables": [ + { + "name": "PKG_ELECTRODE", + "value": "True", + "type": "BOOL" + }, + { + "name": "BUILD_SHARED_LIBS", + "value": "True", + "type": "BOOL" + }, + { + "name": "BUILD_TOOLS", + "value": "True", + "type": "BOOL" + }, + { + "name": "LAMMPS_EXCEPTIONS", + "value": "True", + "type": "BOOL" + }, + { + "name": "ENABLE_TESTING", + "value": "False", + "type": "BOOL" + }, + { + "name": "FFT", + "value": "MKL", + "type": "STRING" } ] } ] -} \ No newline at end of file +} diff --git a/cmake/Modules/Documentation.cmake b/cmake/Modules/Documentation.cmake index 16dd5dd4fa..35661843a2 100644 --- a/cmake/Modules/Documentation.cmake +++ b/cmake/Modules/Documentation.cmake @@ -7,13 +7,13 @@ if(BUILD_DOC) # Sphinx 3.x requires at least Python 3.5 if(CMAKE_VERSION VERSION_LESS 3.12) find_package(PythonInterp 3.5 REQUIRED) - set(VIRTUALENV ${PYTHON_EXECUTABLE} -m virtualenv -p ${PYTHON_EXECUTABLE}) + set(VIRTUALENV ${PYTHON_EXECUTABLE} -m venv) else() find_package(Python3 REQUIRED COMPONENTS Interpreter) if(Python3_VERSION VERSION_LESS 3.5) message(FATAL_ERROR "Python 3.5 and up is required to build the HTML documentation") endif() - set(VIRTUALENV ${Python3_EXECUTABLE} -m virtualenv -p ${Python3_EXECUTABLE}) + set(VIRTUALENV ${Python3_EXECUTABLE} -m venv) endif() find_package(Doxygen 1.8.10 REQUIRED) diff --git a/cmake/Modules/LAMMPSInterfacePlugin.cmake b/cmake/Modules/LAMMPSInterfacePlugin.cmake new file mode 100644 index 0000000000..ec7a739785 --- /dev/null +++ b/cmake/Modules/LAMMPSInterfacePlugin.cmake @@ -0,0 +1,197 @@ +# CMake script code to define LAMMPS settings required for building LAMMPS plugins + +# enforce out-of-source build +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "In-source builds are not allowed. You must create and use a build directory. " + "Please remove CMakeCache.txt and CMakeFiles first.") +endif() + +# global LAMMPS/plugin build settings +set(LAMMPS_SOURCE_DIR "" CACHE PATH "Location of LAMMPS sources folder") +if(NOT LAMMPS_SOURCE_DIR) + message(FATAL_ERROR "Must set LAMMPS_SOURCE_DIR") +endif() + +# by default, install into $HOME/.local (not /usr/local), +# so that no root access (and sudo) is needed +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local" CACHE PATH "Default install path" FORCE) +endif() + +# ugly hacks for MSVC which by default always reports an old C++ standard in the __cplusplus macro +# and prints lots of pointless warnings about "unsafe" functions +if(MSVC) + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options(/Zc:__cplusplus) + add_compile_options(/wd4244) + add_compile_options(/wd4267) + if(LAMMPS_EXCEPTIONS) + add_compile_options(/EHsc) + endif() + endif() + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) +endif() + +# C++11 is required +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Need -restrict with Intel compilers +if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict") +endif() +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) + +####### +# helper functions from LAMMPSUtils.cmake +function(validate_option name values) + string(TOLOWER ${${name}} needle_lower) + string(TOUPPER ${${name}} needle_upper) + list(FIND ${values} ${needle_lower} IDX_LOWER) + list(FIND ${values} ${needle_upper} IDX_UPPER) + if(${IDX_LOWER} LESS 0 AND ${IDX_UPPER} LESS 0) + list_to_bulletpoints(POSSIBLE_VALUE_LIST ${${values}}) + message(FATAL_ERROR "\n########################################################################\n" + "Invalid value '${${name}}' for option ${name}\n" + "\n" + "Possible values are:\n" + "${POSSIBLE_VALUE_LIST}" + "########################################################################") + endif() +endfunction(validate_option) + +# helper function for getting the most recently modified file or folder from a glob pattern +function(get_newest_file path variable) + file(GLOB _dirs ${path}) + set(_besttime 2000-01-01T00:00:00) + set(_bestfile "") + foreach(_dir ${_dirs}) + file(TIMESTAMP ${_dir} _newtime) + if(_newtime IS_NEWER_THAN _besttime) + set(_bestfile ${_dir}) + set(_besttime ${_newtime}) + endif() + endforeach() + if(_bestfile STREQUAL "") + message(FATAL_ERROR "Could not find valid path at: ${path}") + endif() + set(${variable} ${_bestfile} PARENT_SCOPE) +endfunction() + +################################################################################# +# LAMMPS C++ interface. We only need the header related parts except on windows. +add_library(lammps INTERFACE) +target_include_directories(lammps INTERFACE ${LAMMPS_SOURCE_DIR}) +if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING) + target_link_libraries(lammps INTERFACE ${CMAKE_BINARY_DIR}/../liblammps.dll.a) +endif() + +################################################################################ +# MPI configuration +if(NOT CMAKE_CROSSCOMPILING) + find_package(MPI QUIET) + option(BUILD_MPI "Build MPI version" ${MPI_FOUND}) +else() + option(BUILD_MPI "Build MPI version" OFF) +endif() + +if(BUILD_MPI) + # do not include the (obsolete) MPI C++ bindings which makes + # for leaner object files and avoids namespace conflicts + set(MPI_CXX_SKIP_MPICXX TRUE) + # We use a non-standard procedure to cross-compile with MPI on Windows + if((CMAKE_SYSTEM_NAME STREQUAL "Windows") AND CMAKE_CROSSCOMPILING) + # Download and configure custom MPICH files for Windows + message(STATUS "Downloading and configuring MPICH-1.4.1 for Windows") + set(MPICH2_WIN64_DEVEL_URL "${LAMMPS_THIRDPARTY_URL}/mpich2-win64-devel.tar.gz" CACHE STRING "URL for MPICH2 (win64) tarball") + set(MPICH2_WIN32_DEVEL_URL "${LAMMPS_THIRDPARTY_URL}/mpich2-win32-devel.tar.gz" CACHE STRING "URL for MPICH2 (win32) tarball") + set(MPICH2_WIN64_DEVEL_MD5 "4939fdb59d13182fd5dd65211e469f14" CACHE STRING "MD5 checksum of MPICH2 (win64) tarball") + set(MPICH2_WIN32_DEVEL_MD5 "a61d153500dce44e21b755ee7257e031" CACHE STRING "MD5 checksum of MPICH2 (win32) tarball") + mark_as_advanced(MPICH2_WIN64_DEVEL_URL) + mark_as_advanced(MPICH2_WIN32_DEVEL_URL) + mark_as_advanced(MPICH2_WIN64_DEVEL_MD5) + mark_as_advanced(MPICH2_WIN32_DEVEL_MD5) + + include(ExternalProject) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + ExternalProject_Add(mpi4win_build + URL ${MPICH2_WIN64_DEVEL_URL} + URL_MD5 ${MPICH2_WIN64_DEVEL_MD5} + CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" + BUILD_BYPRODUCTS /lib/libmpi.a) + else() + ExternalProject_Add(mpi4win_build + URL ${MPICH2_WIN32_DEVEL_URL} + URL_MD5 ${MPICH2_WIN32_DEVEL_MD5} + CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" + BUILD_BYPRODUCTS /lib/libmpi.a) + endif() + + ExternalProject_get_property(mpi4win_build SOURCE_DIR) + file(MAKE_DIRECTORY "${SOURCE_DIR}/include") + add_library(MPI::MPI_CXX UNKNOWN IMPORTED) + set_target_properties(MPI::MPI_CXX PROPERTIES + IMPORTED_LOCATION "${SOURCE_DIR}/lib/libmpi.a" + INTERFACE_INCLUDE_DIRECTORIES "${SOURCE_DIR}/include" + INTERFACE_COMPILE_DEFINITIONS "MPICH_SKIP_MPICXX") + add_dependencies(MPI::MPI_CXX mpi4win_build) + + # set variables for status reporting at the end of CMake run + set(MPI_CXX_INCLUDE_PATH "${SOURCE_DIR}/include") + set(MPI_CXX_COMPILE_DEFINITIONS "MPICH_SKIP_MPICXX") + set(MPI_CXX_LIBRARIES "${SOURCE_DIR}/lib/libmpi.a") + else() + find_package(MPI REQUIRED) + option(LAMMPS_LONGLONG_TO_LONG "Workaround if your system or MPI version does not recognize 'long long' data types" OFF) + if(LAMMPS_LONGLONG_TO_LONG) + target_compile_definitions(lammps INTERFACE -DLAMMPS_LONGLONG_TO_LONG) + endif() + endif() + target_link_libraries(lammps INTERFACE MPI::MPI_CXX) +else() + add_library(mpi_stubs INTERFACE) + target_include_directories(mpi_stubs INTERFACE $) + target_link_libraries(lammps INTERFACE mpi_stubs) +endif() + +################################################################################ +# detect if we may enable OpenMP support by default +set(BUILD_OMP_DEFAULT OFF) +find_package(OpenMP QUIET) +if(OpenMP_FOUND) + check_include_file_cxx(omp.h HAVE_OMP_H_INCLUDE) + if(HAVE_OMP_H_INCLUDE) + set(BUILD_OMP_DEFAULT ON) + endif() +endif() + +option(BUILD_OMP "Build with OpenMP support" ${BUILD_OMP_DEFAULT}) + +if(BUILD_OMP) + find_package(OpenMP REQUIRED) + check_include_file_cxx(omp.h HAVE_OMP_H_INCLUDE) + if(NOT HAVE_OMP_H_INCLUDE) + message(FATAL_ERROR "Cannot find the 'omp.h' header file required for full OpenMP support") + endif() + + if (((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0)) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "PGI") OR + ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)) OR + ((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0))) + # GCC 9.x and later plus Clang 10.x and later implement strict OpenMP 4.0 semantics for consts. + # Intel 18.0 was tested to support both, so we switch to OpenMP 4+ from 19.x onward to be safe. + target_compile_definitions(lammps INTERFACE -DLAMMPS_OMP_COMPAT=4) + else() + target_compile_definitions(lammps INTERFACE -DLAMMPS_OMP_COMPAT=3) + endif() + target_link_libraries(lammps INTERFACE OpenMP::OpenMP_CXX) +endif() + +################ +# integer size selection +set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)") +set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall) +set_property(CACHE LAMMPS_SIZES PROPERTY STRINGS ${LAMMPS_SIZES_VALUES}) +validate_option(LAMMPS_SIZES LAMMPS_SIZES_VALUES) +string(TOUPPER ${LAMMPS_SIZES} LAMMPS_SIZES) +target_compile_definitions(lammps INTERFACE -DLAMMPS_${LAMMPS_SIZES}) diff --git a/cmake/Modules/LAMMPSUtils.cmake b/cmake/Modules/LAMMPSUtils.cmake index 943c3d851e..9f624fc007 100644 --- a/cmake/Modules/LAMMPSUtils.cmake +++ b/cmake/Modules/LAMMPSUtils.cmake @@ -24,6 +24,24 @@ function(validate_option name values) endif() endfunction(validate_option) +# helper function for getting the most recently modified file or folder from a glob pattern +function(get_newest_file path variable) + file(GLOB _dirs ${path}) + set(_besttime 2000-01-01T00:00:00) + set(_bestfile "") + foreach(_dir ${_dirs}) + file(TIMESTAMP ${_dir} _newtime) + if(_newtime IS_NEWER_THAN _besttime) + set(_bestfile ${_dir}) + set(_besttime ${_newtime}) + endif() + endforeach() + if(_bestfile STREQUAL "") + message(FATAL_ERROR "Could not find valid path at: ${path}") + endif() + set(${variable} ${_bestfile} PARENT_SCOPE) +endfunction() + function(get_lammps_version version_header variable) file(STRINGS ${version_header} line REGEX LAMMPS_VERSION) set(MONTHS x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) diff --git a/cmake/Modules/Packages/COLVARS.cmake b/cmake/Modules/Packages/COLVARS.cmake index 3488aa62b1..da5b685536 100644 --- a/cmake/Modules/Packages/COLVARS.cmake +++ b/cmake/Modules/Packages/COLVARS.cmake @@ -19,6 +19,10 @@ endif() add_library(colvars STATIC ${COLVARS_SOURCES}) target_compile_definitions(colvars PRIVATE -DCOLVARS_LAMMPS) +separate_arguments(CMAKE_TUNE_FLAGS) +foreach(_FLAG ${CMAKE_TUNE_FLAGS}) + target_compile_options(colvars PRIVATE ${_FLAG}) +endforeach() set_target_properties(colvars PROPERTIES OUTPUT_NAME lammps_colvars${LAMMPS_MACHINE}) target_include_directories(colvars PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/colvars) # The line below is needed to locate math_eigen_impl.h diff --git a/cmake/Modules/Packages/INTEL.cmake b/cmake/Modules/Packages/INTEL.cmake index af08249090..ce8455e542 100644 --- a/cmake/Modules/Packages/INTEL.cmake +++ b/cmake/Modules/Packages/INTEL.cmake @@ -38,7 +38,7 @@ if(INTEL_LRT_MODE STREQUAL "C++11") endif() endif() -if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") +if((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") OR (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) message(FATAL_ERROR "INTEL needs at least a 2016 Intel compiler, found ${CMAKE_CXX_COMPILER_VERSION}") endif() @@ -46,12 +46,12 @@ else() message(WARNING "INTEL gives best performance with Intel compilers") endif() -find_package(TBB_MALLOC QUIET) +find_package(TBB_MALLOC) if(TBB_MALLOC_FOUND) target_link_libraries(lammps PRIVATE TBB::TBB_MALLOC) else() target_compile_definitions(lammps PRIVATE -DLMP_INTEL_NO_TBB) - if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + if((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") OR (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")) message(WARNING "INTEL with Intel compilers should use TBB malloc libraries") endif() endif() @@ -112,5 +112,9 @@ if(PKG_KSPACE) RegisterIntegrateStyle(${INTEL_SOURCES_DIR}/verlet_lrt_intel.h) endif() +if(PKG_ELECTRODE) + list(APPEND INTEL_SOURCES ${INTEL_SOURCES_DIR}/electrode_accel_intel.cpp) +endif() + target_sources(lammps PRIVATE ${INTEL_SOURCES}) target_include_directories(lammps PRIVATE ${INTEL_SOURCES_DIR}) diff --git a/cmake/Modules/Packages/KOKKOS.cmake b/cmake/Modules/Packages/KOKKOS.cmake index 4e35e6dcc0..cf3d19c720 100644 --- a/cmake/Modules/Packages/KOKKOS.cmake +++ b/cmake/Modules/Packages/KOKKOS.cmake @@ -47,8 +47,8 @@ if(DOWNLOAD_KOKKOS) list(APPEND KOKKOS_LIB_BUILD_ARGS "-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}") list(APPEND KOKKOS_LIB_BUILD_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") include(ExternalProject) - set(KOKKOS_URL "https://github.com/kokkos/kokkos/archive/3.5.00.tar.gz" CACHE STRING "URL for KOKKOS tarball") - set(KOKKOS_MD5 "079323d973ae0e1c38c0a54a150c674e" CACHE STRING "MD5 checksum of KOKKOS tarball") + set(KOKKOS_URL "https://github.com/kokkos/kokkos/archive/3.6.00.tar.gz" CACHE STRING "URL for KOKKOS tarball") + set(KOKKOS_MD5 "b5c44ea961031795f434002cd7b31c20" CACHE STRING "MD5 checksum of KOKKOS tarball") mark_as_advanced(KOKKOS_URL) mark_as_advanced(KOKKOS_MD5) ExternalProject_Add(kokkos_build @@ -72,7 +72,7 @@ if(DOWNLOAD_KOKKOS) add_dependencies(LAMMPS::KOKKOSCORE kokkos_build) add_dependencies(LAMMPS::KOKKOSCONTAINERS kokkos_build) elseif(EXTERNAL_KOKKOS) - find_package(Kokkos 3.5.00 REQUIRED CONFIG) + find_package(Kokkos 3.6.00 REQUIRED CONFIG) target_link_libraries(lammps PRIVATE Kokkos::kokkos) target_link_libraries(lmp PRIVATE Kokkos::kokkos) else() @@ -130,6 +130,11 @@ if(PKG_KSPACE) target_compile_definitions(lammps PRIVATE -DFFT_CUFFT) target_link_libraries(lammps PRIVATE cufft) endif() + elseif(Kokkos_ENABLE_HIP) + if(NOT (FFT STREQUAL "KISS")) + target_compile_definitions(lammps PRIVATE -DFFT_HIPFFT) + target_link_libraries(lammps PRIVATE hipfft) + endif() endif() endif() diff --git a/cmake/Modules/Packages/MACHDYN.cmake b/cmake/Modules/Packages/MACHDYN.cmake index d90ca8146c..fcc298da2f 100644 --- a/cmake/Modules/Packages/MACHDYN.cmake +++ b/cmake/Modules/Packages/MACHDYN.cmake @@ -36,3 +36,5 @@ endif() if((CMAKE_CXX_COMPILER_ID STREQUAL "PGI") OR (CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC")) target_compile_definitions(lammps PRIVATE -DEIGEN_DONT_VECTORIZE) endif() + +target_compile_definitions(lammps PRIVATE -DEIGEN_NO_CUDA) diff --git a/cmake/Modules/Packages/MDI.cmake b/cmake/Modules/Packages/MDI.cmake index 1eec53db37..88859f0285 100644 --- a/cmake/Modules/Packages/MDI.cmake +++ b/cmake/Modules/Packages/MDI.cmake @@ -50,6 +50,7 @@ if(DOWNLOAD_MDI) -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} + -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dlanguage=C -Dlibtype=STATIC -Dmpi=${MDI_USE_MPI} diff --git a/cmake/Modules/Packages/ML-PACE.cmake b/cmake/Modules/Packages/ML-PACE.cmake index d46197114d..c553809ff1 100644 --- a/cmake/Modules/Packages/ML-PACE.cmake +++ b/cmake/Modules/Packages/ML-PACE.cmake @@ -1,6 +1,6 @@ -set(PACELIB_URL "https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2021.10.25.tar.gz" CACHE STRING "URL for PACE evaluator library sources") +set(PACELIB_URL "https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2021.10.25.fix2.tar.gz" CACHE STRING "URL for PACE evaluator library sources") -set(PACELIB_MD5 "a2ac3315c41a1a4a5c912bcb1bc9c5cc" CACHE STRING "MD5 checksum of PACE evaluator library tarball") +set(PACELIB_MD5 "32394d799bc282bb57696c78c456e64f" CACHE STRING "MD5 checksum of PACE evaluator library tarball") mark_as_advanced(PACELIB_URL) mark_as_advanced(PACELIB_MD5) @@ -13,8 +13,12 @@ execute_process( COMMAND ${CMAKE_COMMAND} -E tar xzf libpace.tar.gz WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) +get_newest_file(${CMAKE_BINARY_DIR}/lammps-user-pace-* lib-pace) -file(GLOB lib-pace ${CMAKE_BINARY_DIR}/lammps-user-pace-*) +# enforce building libyaml-cpp as static library and turn off optional features +set(YAML_BUILD_SHARED_LIBS OFF) +set(YAML_CPP_BUILD_CONTRIB OFF) +set(YAML_CPP_BUILD_TOOLS OFF) add_subdirectory(${lib-pace}/yaml-cpp build-yaml-cpp) set(YAML_CPP_INCLUDE_DIR ${lib-pace}/yaml-cpp/include) @@ -28,5 +32,6 @@ target_include_directories(pace PUBLIC ${PACE_EVALUATOR_INCLUDE_DIR} ${YAML_CPP_ target_link_libraries(pace PRIVATE yaml-cpp-pace) - -target_link_libraries(lammps PRIVATE pace) +if(CMAKE_PROJECT_NAME STREQUAL "lammps") + target_link_libraries(lammps PRIVATE pace) +endif() diff --git a/cmake/Modules/Packages/ML-QUIP.cmake b/cmake/Modules/Packages/ML-QUIP.cmake index 4db1eb1541..56221accab 100644 --- a/cmake/Modules/Packages/ML-QUIP.cmake +++ b/cmake/Modules/Packages/ML-QUIP.cmake @@ -43,6 +43,7 @@ if(DOWNLOAD_QUIP) file(WRITE ${CMAKE_BINARY_DIR}/quip.config "${temp}") message(STATUS "QUIP download via git requested - we will build our own") + set(CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY CHECKOUT) # QUIP has no releases (except for a tag marking the end of Python 2 support). We use the current "public" branch # The LAMMPS interface wrapper has a compatibility constant that is being checked at runtime. include(ExternalProject) diff --git a/cmake/Modules/Tools.cmake b/cmake/Modules/Tools.cmake index c3b0a0771d..d2758f1f24 100644 --- a/cmake/Modules/Tools.cmake +++ b/cmake/Modules/Tools.cmake @@ -3,6 +3,9 @@ if(BUILD_TOOLS) target_compile_definitions(binary2txt PRIVATE -DLAMMPS_${LAMMPS_SIZES}) install(TARGETS binary2txt DESTINATION ${CMAKE_INSTALL_BINDIR}) + add_executable(stl_bin2txt ${LAMMPS_TOOLS_DIR}/stl_bin2txt.cpp) + install(TARGETS stl_bin2txt DESTINATION ${CMAKE_INSTALL_BINDIR}) + include(CheckGeneratorSupport) if(CMAKE_GENERATOR_SUPPORT_FORTRAN) include(CheckLanguage) diff --git a/cmake/Modules/generate_lmpgitversion.cmake b/cmake/Modules/generate_lmpgitversion.cmake index f066269723..32aaf6f2c5 100644 --- a/cmake/Modules/generate_lmpgitversion.cmake +++ b/cmake/Modules/generate_lmpgitversion.cmake @@ -31,5 +31,7 @@ set(temp "${temp}const char *LAMMPS_NS::LAMMPS::git_descriptor() { return \"${te set(temp "${temp}#endif\n\n") message(STATUS "Generating lmpgitversion.h...") -file(WRITE "${LAMMPS_STYLE_HEADERS_DIR}/lmpgitversion.h.tmp" "${temp}" ) -execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${LAMMPS_STYLE_HEADERS_DIR}/lmpgitversion.h.tmp" "${LAMMPS_STYLE_HEADERS_DIR}/lmpgitversion.h") + +string(REPLACE "\\ " " " LAMMPS_GIT_HEADER "${LAMMPS_STYLE_HEADERS_DIR}/lmpgitversion.h") +file(WRITE "${LAMMPS_GIT_HEADER}.tmp" "${temp}" ) +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${LAMMPS_GIT_HEADER}.tmp" "${LAMMPS_GIT_HEADER}") diff --git a/cmake/presets/all_off.cmake b/cmake/presets/all_off.cmake index fff167fa0b..92e79c02c7 100644 --- a/cmake/presets/all_off.cmake +++ b/cmake/presets/all_off.cmake @@ -26,6 +26,7 @@ set(ALL_PACKAGES DPD-REACT DPD-SMOOTH DRUDE + ELECTRODE EFF EXTRA-COMPUTE EXTRA-DUMP diff --git a/cmake/presets/all_on.cmake b/cmake/presets/all_on.cmake index df42c09232..3cc705a126 100644 --- a/cmake/presets/all_on.cmake +++ b/cmake/presets/all_on.cmake @@ -28,6 +28,7 @@ set(ALL_PACKAGES DPD-REACT DPD-SMOOTH DRUDE + ELECTRODE EFF EXTRA-COMPUTE EXTRA-DUMP diff --git a/cmake/presets/kokkos-cuda.cmake b/cmake/presets/kokkos-cuda.cmake index 36d099479d..ace8ff0879 100644 --- a/cmake/presets/kokkos-cuda.cmake +++ b/cmake/presets/kokkos-cuda.cmake @@ -3,9 +3,9 @@ # that is compatible with all higher CC, but not the default CC 3.5 set(PKG_KOKKOS ON CACHE BOOL "" FORCE) set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "" FORCE) -set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "" FORCE) set(Kokkos_ENABLE_CUDA ON CACHE BOOL "" FORCE) -set(Kokkos_ARCH_MAXWELL50 on CACHE BOOL "" FORCE) +set(Kokkos_ARCH_PASCAL60 ON CACHE BOOL "" FORCE) set(BUILD_OMP ON CACHE BOOL "" FORCE) -get_filename_component(NVCC_WRAPPER_CMD ${CMAKE_CURRENT_SOURCE_DIR}/../lib/kokkos/bin/nvcc_wrapper ABSOLUTE) -set(CMAKE_CXX_COMPILER ${NVCC_WRAPPER_CMD} CACHE FILEPATH "" FORCE) + +# hide deprecation warnings temporarily for stable release +set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE) diff --git a/cmake/presets/kokkos-hip.cmake b/cmake/presets/kokkos-hip.cmake new file mode 100644 index 0000000000..827a37152b --- /dev/null +++ b/cmake/presets/kokkos-hip.cmake @@ -0,0 +1,20 @@ +# preset that enables KOKKOS and selects HIP compilation with OpenMP +# enabled as well. Also sets some performance related compiler flags. +set(PKG_KOKKOS ON CACHE BOOL "" FORCE) +set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "" FORCE) +set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "" FORCE) +set(Kokkos_ENABLE_CUDA OFF CACHE BOOL "" FORCE) +set(Kokkos_ENABLE_HIP ON CACHE BOOL "" FORCE) +set(Kokkos_ARCH_VEGA90A on CACHE BOOL "" FORCE) +set(Kokkos_ENABLE_HIP_MULTIPLE_KERNEL_INSTANTIATIONS ON CACHE BOOL "" FORCE) +set(BUILD_OMP ON CACHE BOOL "" FORCE) + +set(CMAKE_CXX_COMPILER hipcc CACHE STRING "" FORCE) +set(CMAKE_TUNE_FLAGS "-munsafe-fp-atomics" CACHE STRING "" FORCE) + +# hide deprecation warnings temporarily for stable release +set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE) + +# these flags are needed to build with Cray MPICH on OLCF Crusher +#-D CMAKE_CXX_FLAGS="-I/${MPICH_DIR}/include" +#-D MPI_CXX_LIBRARIES="-L${MPICH_DIR}/lib -lmpi -L${CRAY_MPICH_ROOTDIR}/gtl/lib -lmpi_gtl_hsa" diff --git a/cmake/presets/kokkos-openmp.cmake b/cmake/presets/kokkos-openmp.cmake index 27d09f62cf..3a7c19ff3c 100644 --- a/cmake/presets/kokkos-openmp.cmake +++ b/cmake/presets/kokkos-openmp.cmake @@ -4,3 +4,6 @@ set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "" FORCE) set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "" FORCE) set(Kokkos_ENABLE_CUDA OFF CACHE BOOL "" FORCE) set(BUILD_OMP ON CACHE BOOL "" FORCE) + +# hide deprecation warnings temporarily for stable release +set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE) diff --git a/cmake/presets/kokkos-serial.cmake b/cmake/presets/kokkos-serial.cmake index 0208d2ee3a..f1bda7124a 100644 --- a/cmake/presets/kokkos-serial.cmake +++ b/cmake/presets/kokkos-serial.cmake @@ -3,3 +3,6 @@ set(PKG_KOKKOS ON CACHE BOOL "" FORCE) set(Kokkos_ENABLE_SERIAL ON CACHE BOOL "" FORCE) set(Kokkos_ENABLE_OPENMP OFF CACHE BOOL "" FORCE) set(Kokkos_ENABLE_CUDA OFF CACHE BOOL "" FORCE) + +# hide deprecation warnings temporarily for stable release +set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE) diff --git a/cmake/presets/kokkos-sycl.cmake b/cmake/presets/kokkos-sycl.cmake index 01abe7762f..c706aca7d8 100644 --- a/cmake/presets/kokkos-sycl.cmake +++ b/cmake/presets/kokkos-sycl.cmake @@ -8,6 +8,9 @@ set(Kokkos_ENABLE_SYCL ON CACHE BOOL "" FORCE) set(Kokkos_ARCH_MAXWELL50 on CACHE BOOL "" FORCE) set(BUILD_OMP ON CACHE BOOL "" FORCE) +# hide deprecation warnings temporarily for stable release +set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE) + set(CMAKE_CXX_COMPILER clang++ CACHE STRING "" FORCE) set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE) set(CMAKE_CXX_STANDARD 17 CACHE STRING "" FORCE) diff --git a/cmake/presets/mingw-cross.cmake b/cmake/presets/mingw-cross.cmake index 1e78537686..843dd5e4ad 100644 --- a/cmake/presets/mingw-cross.cmake +++ b/cmake/presets/mingw-cross.cmake @@ -22,6 +22,7 @@ set(WIN_PACKAGES DPD-REACT DPD-SMOOTH DRUDE + ELECTRODE EFF EXTRA-COMPUTE EXTRA-DUMP @@ -46,8 +47,8 @@ set(WIN_PACKAGES MISC ML-HDNNP ML-IAP - ML-SNAP ML-RANN + ML-SNAP MOFFF MOLECULE MOLFILE @@ -56,6 +57,7 @@ set(WIN_PACKAGES ORIENT PERI PHONON + PLUGIN POEMS PTM QEQ diff --git a/cmake/presets/most.cmake b/cmake/presets/most.cmake index 481193a627..b3e0f5ca6c 100644 --- a/cmake/presets/most.cmake +++ b/cmake/presets/most.cmake @@ -24,6 +24,7 @@ set(ALL_PACKAGES DPD-REACT DPD-SMOOTH DRUDE + ELECTRODE EFF EXTRA-COMPUTE EXTRA-DUMP diff --git a/cmake/presets/nolib.cmake b/cmake/presets/nolib.cmake index cb9c6f26b3..b6567ad617 100644 --- a/cmake/presets/nolib.cmake +++ b/cmake/presets/nolib.cmake @@ -6,6 +6,7 @@ set(PACKAGES_WITH_LIB ATC AWPMD COMPRESS + ELECTRODE GPU H5MD KIM diff --git a/cmake/presets/pgi.cmake b/cmake/presets/pgi.cmake index b34cb05331..2b7fee7efa 100644 --- a/cmake/presets/pgi.cmake +++ b/cmake/presets/pgi.cmake @@ -1,4 +1,4 @@ -# preset that will enable clang/clang++ with support for MPI and OpenMP (on Linux boxes) +# preset that will enable PGI (Nvidia) compilers with support for MPI and OpenMP (on Linux boxes) set(CMAKE_CXX_COMPILER "pgc++" CACHE STRING "" FORCE) set(CMAKE_C_COMPILER "pgcc" CACHE STRING "" FORCE) diff --git a/cmake/presets/windows-intel-classic.cmake b/cmake/presets/windows-intel-classic.cmake new file mode 100644 index 0000000000..ce6db622f0 --- /dev/null +++ b/cmake/presets/windows-intel-classic.cmake @@ -0,0 +1,8 @@ +# preset that will enable Intel compilers with support for MPI and OpenMP (on Linux boxes) + +set(CMAKE_CXX_COMPILER "icl" CACHE STRING "" FORCE) +set(CMAKE_C_COMPILER "icl" CACHE STRING "" FORCE) +set(CMAKE_Fortran_COMPILER "ifort" CACHE STRING "" FORCE) + +unset(HAVE_OMP_H_INCLUDE CACHE) + diff --git a/cmake/presets/windows-intel-llvm.cmake b/cmake/presets/windows-intel-llvm.cmake new file mode 100644 index 0000000000..e9d88d22fe --- /dev/null +++ b/cmake/presets/windows-intel-llvm.cmake @@ -0,0 +1,8 @@ +# preset that will enable Intel compilers with support for MPI and OpenMP (on Linux boxes) + +set(CMAKE_CXX_COMPILER "icx" CACHE STRING "" FORCE) +set(CMAKE_C_COMPILER "icx" CACHE STRING "" FORCE) +set(CMAKE_Fortran_COMPILER "ifx" CACHE STRING "" FORCE) +set(INTEL_LRT_MODE "C++11" CACHE STRING "" FORCE) +unset(HAVE_OMP_H_INCLUDE CACHE) +set(CMAKE_TUNE_FLAGS -Wno-unused-command-line-argument) diff --git a/cmake/presets/windows.cmake b/cmake/presets/windows.cmake index cb75d8aac0..5189a90bfe 100644 --- a/cmake/presets/windows.cmake +++ b/cmake/presets/windows.cmake @@ -44,6 +44,7 @@ set(WIN_PACKAGES PERI PHONON POEMS + PLUGIN PTM QEQ QTB diff --git a/doc/.gitignore b/doc/.gitignore index 7649fb34f1..7c953d2432 100644 --- a/doc/.gitignore +++ b/doc/.gitignore @@ -1,6 +1,6 @@ /old /html -/html-offline +/fasthtml /epub /latex /mathjax diff --git a/doc/Makefile b/doc/Makefile index a082018dfb..8841ae4825 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -13,35 +13,24 @@ VENV = $(BUILDDIR)/docenv ANCHORCHECK = $(VENV)/bin/rst_anchor_check SPHINXCONFIG = $(BUILDDIR)/utils/sphinx-config MATHJAX = $(SPHINXCONFIG)/_static/mathjax +MATHJAXTAG = 3.2.2 -PYTHON = $(shell which python3) -DOXYGEN = $(shell which doxygen) -VIRTUALENV = virtualenv +PYTHON = $(word 3,$(shell type python3)) +DOXYGEN = $(word 3,$(shell type doxygen)) HAS_PYTHON3 = NO -HAS_VIRTUALENV = NO HAS_DOXYGEN = NO HAS_PDFLATEX = NO -ifeq ($(shell which python3 >/dev/null 2>&1; echo $$?), 0) +ifeq ($(shell type python3 >/dev/null 2>&1; echo $$?), 0) HAS_PYTHON3 = YES endif -ifeq ($(shell which doxygen >/dev/null 2>&1; echo $$?), 0) +ifeq ($(shell type doxygen >/dev/null 2>&1; echo $$?), 0) HAS_DOXYGEN = YES endif -ifeq ($(shell which virtualenv-3 >/dev/null 2>&1; echo $$?), 0) -VIRTUALENV = virtualenv-3 -HAS_VIRTUALENV = YES -endif - -ifeq ($(shell which virtualenv >/dev/null 2>&1; echo $$?), 0) -VIRTUALENV = virtualenv -HAS_VIRTUALENV = YES -endif - -ifeq ($(shell which pdflatex >/dev/null 2>&1; echo $$?), 0) -ifeq ($(shell which latexmk >/dev/null 2>&1; echo $$?), 0) +ifeq ($(shell type pdflatex >/dev/null 2>&1; echo $$?), 0) +ifeq ($(shell type latexmk >/dev/null 2>&1; echo $$?), 0) HAS_PDFLATEX = YES endif endif @@ -58,7 +47,7 @@ SPHINXEXTRA = -E -j $(shell $(PYTHON) -c 'import multiprocessing;print(multiproc # we only want to use explicitly listed files. DOXYFILES = $(shell sed -n -e 's/\#.*$$//' -e '/^ *INPUT \+=/,/^[A-Z_]\+ \+=/p' doxygen/Doxyfile.in | sed -e 's/@LAMMPS_SOURCE_DIR@/..\/src/g' -e 's/\\//g' -e 's/ \+/ /' -e 's/[A-Z_]\+ \+= *\(YES\|NO\|\)//') -.PHONY: help clean-all clean clean-spelling epub mobi rst html pdf spelling anchor_check style_check char_check xmlgen +.PHONY: help clean-all clean clean-spelling epub mobi rst html pdf spelling anchor_check style_check char_check xmlgen fasthtml # ------------------------------------------ @@ -70,7 +59,8 @@ help: @echo " epub create ePUB format manual for e-book readers" @echo " mobi convert ePUB to MOBI format manual for e-book readers (e.g. Kindle)" @echo " (requires ebook-convert tool from calibre)" - @echo " clean remove all intermediate RST files" + @echo " fasthtml approximate HTML page creation in fasthtml dir (for development)" + @echo " clean remove all intermediate files" @echo " clean-all reset the entire build environment" @echo " anchor_check scan for duplicate anchor labels" @echo " style_check check for complete and consistent style lists" @@ -83,7 +73,7 @@ clean-all: clean rm -rf $(BUILDDIR)/docenv $(MATHJAX) $(BUILDDIR)/LAMMPS.mobi $(BUILDDIR)/LAMMPS.epub $(BUILDDIR)/Manual.pdf clean: clean-spelling - rm -rf $(BUILDDIR)/html $(BUILDDIR)/epub $(BUILDDIR)/latex $(BUILDDIR)/doctrees $(BUILDDIR)/doxygen/xml $(BUILDDIR)/doxygen-warn.log $(BUILDDIR)/doxygen/Doxyfile $(SPHINXCONFIG)/conf.py + rm -rf $(BUILDDIR)/html $(BUILDDIR)/epub $(BUILDDIR)/latex $(BUILDDIR)/doctrees $(BUILDDIR)/doxygen/xml $(BUILDDIR)/doxygen-warn.log $(BUILDDIR)/doxygen/Doxyfile $(SPHINXCONFIG)/conf.py $(BUILDDIR)/fasthtml clean-spelling: rm -rf $(BUILDDIR)/spelling @@ -118,6 +108,23 @@ html: xmlgen $(VENV) $(SPHINXCONFIG)/conf.py $(ANCHORCHECK) $(MATHJAX) @rm -rf html/PDF/.[sg]* @echo "Build finished. The HTML pages are in doc/html." +fasthtml: xmlgen $(VENV) $(SPHINXCONFIG)/conf.py $(ANCHORCHECK) $(MATHJAX) + @if [ "$(HAS_BASH)" == "NO" ] ; then echo "bash was not found at $(OSHELL)! Please use: $(MAKE) SHELL=/path/to/bash" 1>&2; exit 1; fi + @$(MAKE) $(MFLAGS) -C graphviz all + @mkdir -p fasthtml + @(\ + . $(VENV)/bin/activate ; env PYTHONWARNINGS= \ + sphinx-build -j 4 -b html -c $(SPHINXCONFIG) -d $(BUILDDIR)/fasthtml/doctrees $(RSTDIR) fasthtml ;\ + deactivate ;\ + ) + @rm -rf fasthtml/_sources + @rm -rf fasthtml/PDF + @rm -rf fasthtml/USER + @rm -rf fasthtml/JPG + @cp -r src/PDF fasthtml/PDF + @rm -rf fasthtml/PDF/.[sg]* + @echo "Fast HTML build finished. The HTML pages are in doc/fasthtml." + spelling: xmlgen $(SPHINXCONFIG)/conf.py $(VENV) $(SPHINXCONFIG)/false_positives.txt @if [ "$(HAS_BASH)" == "NO" ] ; then echo "bash was not found at $(OSHELL)! Please use: $(MAKE) SHELL=/path/to/bash" 1>&2; exit 1; fi @(\ @@ -220,17 +227,17 @@ $(VENV): @if [ "$(HAS_BASH)" == "NO" ] ; then echo "bash was not found at $(OSHELL)! Please use: $(MAKE) SHELL=/path/to/bash" 1>&2; exit 1; fi @if [ "$(HAS_PYTHON3)" == "NO" ] ; then echo "python3 was not found! Please see README for further instructions" 1>&2; exit 1; fi @if [ "$(HAS_DOXYGEN)" == "NO" ] ; then echo "doxygen was not found! Please see README for further instructions" 1>&2; exit 1; fi - @if [ "$(HAS_VIRTUALENV)" == "NO" ] ; then echo "virtualenv was not found! Please see README for further instructions" 1>&2; exit 1; fi @( \ - $(VIRTUALENV) -p $(PYTHON) $(VENV); \ + $(PYTHON) -m venv $(VENV); \ . $(VENV)/bin/activate; \ pip $(PIP_OPTIONS) install --upgrade pip; \ + pip $(PIP_OPTIONS) install --upgrade wheel; \ pip $(PIP_OPTIONS) install -r $(BUILDDIR)/utils/requirements.txt; \ deactivate;\ ) $(MATHJAX): - @git clone -b 3.2.0 -c advice.detachedHead=0 --depth 1 https://github.com/mathjax/MathJax.git $@ + @git clone -b $(MATHJAXTAG) -c advice.detachedHead=0 --depth 1 https://github.com/mathjax/MathJax.git $@ $(ANCHORCHECK): $(VENV) @( \ diff --git a/doc/doxygen/Doxyfile.in b/doc/doxygen/Doxyfile.in index d454898f4e..e905d5a64d 100644 --- a/doc/doxygen/Doxyfile.in +++ b/doc/doxygen/Doxyfile.in @@ -2,7 +2,7 @@ DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = "LAMMPS Programmer's Guide" -PROJECT_NUMBER = "24 August 2020" +PROJECT_NUMBER = "4 May 2022" PROJECT_BRIEF = "Documentation of the LAMMPS library interface and Python wrapper" PROJECT_LOGO = lammps-logo.png CREATE_SUBDIRS = NO @@ -437,6 +437,8 @@ INPUT = @LAMMPS_SOURCE_DIR@/utils.cpp \ @LAMMPS_SOURCE_DIR@/math_eigen.h \ @LAMMPS_SOURCE_DIR@/platform.h \ @LAMMPS_SOURCE_DIR@/platform.cpp \ + @LAMMPS_SOURCE_DIR@/math_special.h \ + @LAMMPS_SOURCE_DIR@/math_special.cpp \ # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded diff --git a/doc/lammps.1 b/doc/lammps.1 index b8011d0cb0..5f1c25867e 100644 --- a/doc/lammps.1 +++ b/doc/lammps.1 @@ -1,7 +1,7 @@ -.TH LAMMPS "1" "24 March 2022" "2022-3-24" +.TH LAMMPS "1" "23 June 2022" "2022-6-23" .SH NAME .B LAMMPS -\- Molecular Dynamics Simulator. Version 24 March 2022 +\- Molecular Dynamics Simulator. Version 23 June 2022 .SH SYNOPSIS .B lmp diff --git a/doc/src/Build_development.rst b/doc/src/Build_development.rst index 5492a1e536..66e12a0d69 100644 --- a/doc/src/Build_development.rst +++ b/doc/src/Build_development.rst @@ -486,14 +486,14 @@ The following options are available. make fix-whitespace # correct whitespace issues in files make check-homepage # search for files with old LAMMPS homepage URLs make fix-homepage # correct LAMMPS homepage URLs in files + make check-errordocs # search for deprecated error docs in header files + make fix-errordocs # remove error docs in header files make check-permissions # search for files with permissions issues make fix-permissions # correct permissions issues in files + make check # run all check targets from above -These should help to replace all TAB characters with blanks and remove -any trailing whitespace. Also all LAMMPS homepage URL references can be -updated to the location change from Sandia to the lammps.org domain. -And the permission check can remove executable permissions from non-executable -files (like source code). +These should help to make source and documentation files conforming +to some the coding style preferences of the LAMMPS developers. Clang-format support -------------------- diff --git a/doc/src/Build_extras.rst b/doc/src/Build_extras.rst index d2d12b48db..14d0e290aa 100644 --- a/doc/src/Build_extras.rst +++ b/doc/src/Build_extras.rst @@ -641,14 +641,27 @@ This list was last updated for version 3.5.0 of the Kokkos library. -D CMAKE_CXX_COMPILER=${HOME}/lammps/lib/kokkos/bin/nvcc_wrapper - To simplify compilation, four preset files are included in the + For AMD or NVIDIA GPUs using HIP, set these variables: + + .. code-block:: bash + + -D Kokkos_ARCH_HOSTARCH=yes # HOSTARCH = HOST from list above + -D Kokkos_ARCH_GPUARCH=yes # GPUARCH = GPU from list above + -D Kokkos_ENABLE_HIP=yes + -D Kokkos_ENABLE_OPENMP=yes + + This will enable FFTs on the GPU, either by the internal KISSFFT library + or with the hipFFT wrapper library, which will call out to the + platform-appropriate vendor library: rocFFT on AMD GPUs or cuFFT on + NVIDIA GPUs. + + To simplify compilation, five preset files are included in the ``cmake/presets`` folder, ``kokkos-serial.cmake``, - ``kokkos-openmp.cmake``, ``kokkos-cuda.cmake``, and - ``kokkos-sycl.cmake``. They will enable the KOKKOS package and - enable some hardware choice. So to compile with OpenMP host - parallelization, CUDA device parallelization (for GPUs with CC 5.0 - and up) with some common packages enabled, you can do the - following: + ``kokkos-openmp.cmake``, ``kokkos-cuda.cmake``, + ``kokkos-hip.cmake``, and ``kokkos-sycl.cmake``. They will enable + the KOKKOS package and enable some hardware choice. So to compile + with CUDA device parallelization (for GPUs with CC 5.0 and up) + with some common packages enabled, you can do the following: .. code-block:: bash @@ -707,6 +720,15 @@ This list was last updated for version 3.5.0 of the Kokkos library. KOKKOS_ABSOLUTE_PATH = $(shell cd $(KOKKOS_PATH); pwd) CC = mpicxx -cxx=$(KOKKOS_ABSOLUTE_PATH)/config/nvcc_wrapper + For AMD or NVIDIA GPUs using HIP: + + .. code-block:: make + + KOKKOS_DEVICES = HIP + KOKKOS_ARCH = HOSTARCH,GPUARCH # HOSTARCH = HOST from list above that is hosting the GPU + # GPUARCH = GPU from list above + FFT_INC = -DFFT_HIPFFT # enable use of hipFFT (optional) + FFT_LIB = -lhipfft # link to hipFFT library Advanced KOKKOS compilation settings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1252,6 +1274,41 @@ be built for the most part with all major versions of the C++ language. ---------- +.. _electrode: + +ELECTRODE package +----------------- + +This package depends on the KSPACE package. + +.. tabs:: + + .. tab:: CMake build + + No additional settings are needed besides ``-D PKG_KSPACE=yes`` and ``-D + PKG_ELECTRODE=yes``. + + .. tab:: Traditional make + + The package is activated with ``make yes-KSPACE`` and ``make + yes-ELECTRODE`` + + + Note that the ``Makefile.lammps`` file has settings for the BLAS and + LAPACK linear algebra libraries. As explained in ``lib/awpmd/README`` + these can either exist on your system, or you can use the files provided + in ``lib/linalg``. In the latter case you also need to build the library + in ``lib/linalg`` with a command like these: + + .. code-block:: bash + + $ make lib-linalg # print help message + $ make lib-linalg args="-m serial" # build with GNU Fortran compiler (settings as with "make serial") + $ make lib-linalg args="-m mpi" # build with default MPI Fortran compiler (settings as with "make mpi") + $ make lib-linalg args="-m gfortran" # build with GNU Fortran compiler + +---------- + .. _ml-pace: ML-PACE package diff --git a/doc/src/Build_manual.rst b/doc/src/Build_manual.rst index 5dbefd8b6e..90633d0811 100644 --- a/doc/src/Build_manual.rst +++ b/doc/src/Build_manual.rst @@ -78,11 +78,12 @@ folder. The following ``make`` commands are available: make html # generate HTML in html dir using Sphinx make pdf # generate PDF as Manual.pdf using Sphinx and PDFLaTeX - make fetch # fetch HTML pages and PDF files from LAMMPS website - # and unpack into the html_www folder and Manual_www.pdf make epub # generate LAMMPS.epub in ePUB format using Sphinx make mobi # generate LAMMPS.mobi in MOBI format using ebook-convert + make fasthtml # generate approximate HTML in fasthtml dir using Sphinx + # some Sphinx extensions do not work correctly with this + make clean # remove intermediate RST files created by HTML build make clean-all # remove entire build folder and any cached data @@ -193,8 +194,13 @@ folder need to be updated or new files added. These files are written in `reStructuredText `_ markup for translation with the Sphinx tool. Before contributing any documentation, please check that both the HTML -and the PDF format documentation can translate without errors. Please also -check the output to the console for any warnings or problems. There will +and the PDF format documentation can translate without errors. During +testing the html translation, you may use the ``make fasthtml`` command +which does an approximate translation (i.e. not all Sphinx features and +extensions will work), but runs very fast because it will only translate +files that have been changed since the last ``make fasthtml`` command. + +Please also check the output to the console for any warnings or problems. There will be multiple tests run automatically: - A test for correctness of all anchor labels and their references diff --git a/doc/src/Build_package.rst b/doc/src/Build_package.rst index 67639a46b9..9eeda4d8d4 100644 --- a/doc/src/Build_package.rst +++ b/doc/src/Build_package.rst @@ -150,7 +150,7 @@ other files dependent on that package are also excluded. .. _cmake_presets: CMake presets for installing many packages -"""""""""""""""""""""""""""""""""""""""""" +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Instead of specifying all the CMake options via the command-line, CMake allows initializing its settings cache using script files. @@ -178,6 +178,11 @@ one of them as a starting point and customize it to your needs. cmake -C ../cmake/presets/all_off.cmake [OPTIONS] ../cmake # disable all packages mingw64-cmake -C ../cmake/presets/mingw-cross.cmake [OPTIONS] ../cmake # compile with MinGW cross compilers +Presets that have names starting with "windows" are specifically for +compiling LAMMPS :doc:`natively on Windows ` and +presets that have names starting with "kokkos" are specifically for +selecting configurations for compiling LAMMPS with :ref:`KOKKOS `. + .. note:: Running cmake this way manipulates the CMake settings cache in your @@ -220,7 +225,8 @@ These commands install/un-install sets of packages: .. code-block:: bash make yes-all # install all packages - make no-all # uninstall all packages + make no-all # check for changes and uninstall all packages + make no-installed # only check and uninstall installed packages make yes-basic # install a few commonly used packages' make no-basic # remove a few commonly used packages' make yes-most # install most packages w/o libs' diff --git a/doc/src/Build_settings.rst b/doc/src/Build_settings.rst index 6053bdbf8a..7e627a052f 100644 --- a/doc/src/Build_settings.rst +++ b/doc/src/Build_settings.rst @@ -287,8 +287,8 @@ Output of JPG, PNG, and movie files The :doc:`dump image ` command has options to output JPEG or PNG image files. Likewise the :doc:`dump movie ` command -outputs movie files in MPEG format. Using these options requires the -following settings: +outputs movie files in a variety of movie formats. Using these options +requires the following settings: .. tabs:: @@ -328,11 +328,12 @@ following settings: JPG_LIB = -ljpeg -lpng -lz # library names As with CMake, you do not need to set ``JPG_INC`` or ``JPG_PATH``, - if make can find the graphics header and library files. You must - specify ``JPG_LIB`` with a list of graphics libraries to include - in the link. You must insure ffmpeg is in a directory where - LAMMPS can find it at runtime, that is a directory in your PATH - environment variable. + if make can find the graphics header and library files in their + default system locations. You must specify ``JPG_LIB`` with a + list of graphics libraries to include in the link. You must make + certain that the ffmpeg executable (or ffmpeg.exe on Windows) is + in a directory where LAMMPS can find it at runtime; that is + usually a directory list in your ``PATH`` environment variable. Using ``ffmpeg`` to output movie files requires that your machine supports the "popen" function in the standard runtime library. diff --git a/doc/src/Build_windows.rst b/doc/src/Build_windows.rst index 28fd3ff48b..d1748825eb 100644 --- a/doc/src/Build_windows.rst +++ b/doc/src/Build_windows.rst @@ -5,6 +5,7 @@ Notes for building LAMMPS on Windows * :ref:`Running Linux on Windows ` * :ref:`Using GNU GCC ported to Windows ` * :ref:`Using Visual Studio ` +* :ref:`Using Intel oneAPI compilers and libraries ` * :ref:`Using a cross-compiler ` ---------- @@ -25,8 +26,10 @@ assistance in resolving portability issues. This is particularly true for compiling LAMMPS on Windows, since this platform has significant differences in some low-level functionality. As of LAMMPS version 14 December 2021, large parts of LAMMPS can be compiled natively with the -Microsoft Visual C++ Compilers. This is largely facilitated by using -the :doc:`Developer_platform` in the ``platform`` namespace. +Microsoft Visual C++ Compilers. As of LAMMPS version 31 May 2022, also +the Intel oneAPI compilers can compile large parts of LAMMPS natively on +Windows. This is mostly facilitated by using the +:doc:`Developer_platform` in the ``platform`` namespace and CMake. Before trying to build LAMMPS on Windows yourself, please consider the `pre-compiled Windows installer packages `_ @@ -99,6 +102,10 @@ It is possible to use both the integrated CMake support of the Visual Studio IDE or use an external CMake installation (e.g. downloaded from cmake.org) to create build files and compile LAMMPS from the command line. +Compilation via command line and unit tests are checked automatically +for the LAMMPS development branch through +`GitHub Actions `_. + .. note:: Versions of Visual Studio before version 17.1 may scan the entire @@ -111,6 +118,10 @@ Please note, that for either approach CMake will create a so-called the command lines for building and testing LAMMPS must be adjusted accordingly. +The LAMMPS cmake folder contains a ``CMakeSettings.json`` file with +build configurations for MSVC compilers and the MS provided Clang +compiler package in Debug and Release mode. + To support running in parallel you can compile with OpenMP enabled using the OPENMP package or install Microsoft MPI (including the SDK) and compile LAMMPS with MPI enabled. @@ -121,6 +132,53 @@ LAMMPS with MPI enabled. via GitHub or the `LAMMPS forum at MatSci `_, if you have questions or LAMMPS specific problems. +.. _oneapi: + +Using Intel oneAPI Compilers and Libraries +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. versionadded:: 31May2022 + +After installing the `Intel oneAPI +`_ +base toolkit and the HPC toolkit, it is also possible to compile large +parts of LAMMPS natively on Windows using Intel compilers. The HPC +toolkit provides two sets of C/C++ and Fortran compilers: the so-called +"classic" compilers (``icl.exe`` and ``ifort.exe``) and newer, LLVM +based compilers (``icx.exe`` and ``ifx.exe``). In addition to the +compilers and their dependent modules, also the thread building blocks +(TBB) and the math kernel library (MKL) need to be installed. Two +presets (``cmake/presets/windows-intel-llvm.cmake`` and +``cmake/presets/windows-intel-classic.cmake``) are provided for +selecting the LLVM based or classic compilers, respectively. The preset +``cmake/presets/windows.cmake`` enables compatible packages that are not +dependent on additional features or libraries. You **must** use the +CMake based build procedure and use Ninja as build tool. For compiling +from the command prompt, thus both `CMake `_ and +`Ninja-build `_ binaries must be installed. It +is also possible to use Visual Studio, if it is started (``devenv.exe``) +from a command prompt that has the Intel oneAPI compilers enabled. The +Visual Studio settings file in the ``cmake`` folder contains +configurations for both compiler variants in debug and release settings. +Those will use the CMake and Ninja binaries bundled with Visual Studio, +thus a separate installation is not required. + +.. admonition:: Known Limitations + :class: note + + In addition to portability issues with several packages and external + libraries, the classic Intel compilers are currently not able to + compile the googletest libraries and thus enabling the ``-DENABLE_TESTING`` + option will result in compilation failure. The LLVM based compilers + are compatible. + +.. note:: + + This is work in progress and you should contact the LAMMPS developers + via GitHub or the `LAMMPS forum at MatSci `_, + if you have questions or LAMMPS specific problems. + + .. _cross: Using a cross-compiler @@ -145,14 +203,3 @@ LAMMPS developers. We instead rely on the feedback of the users of these pre-compiled LAMMPS packages for Windows. We will try to resolve issues to the best of our abilities if we become aware of them. However this is subject to time constraints and focus on HPC platforms. - -.. _native: - -Native Visual C++ support -^^^^^^^^^^^^^^^^^^^^^^^^^ - -Support for the Visual C++ compilers is currently not available. The -CMake build system is capable of creating suitable a Visual Studio -style build environment, but the LAMMPS source code itself is not -ported to fully support Visual C++. Volunteers to take on this task -are welcome. diff --git a/doc/src/Commands_all.rst b/doc/src/Commands_all.rst index bc25d0c0e0..a868ad84fc 100644 --- a/doc/src/Commands_all.rst +++ b/doc/src/Commands_all.rst @@ -14,7 +14,7 @@ General commands ================ -An alphabetic list of all general LAMMPS commands. +An alphabetic list of general LAMMPS commands. .. table_from_list:: :columns: 5 @@ -47,35 +47,26 @@ An alphabetic list of all general LAMMPS commands. * :doc:`displace_atoms ` * :doc:`dump ` * :doc:`dump_modify ` - * :doc:`dynamical_matrix (k) ` * :doc:`echo ` * :doc:`fix ` * :doc:`fix_modify ` * :doc:`group ` - * :doc:`group2ndx ` - * :doc:`hyper ` * :doc:`if ` * :doc:`improper_coeff ` * :doc:`improper_style ` * :doc:`include ` * :doc:`info ` * :doc:`jump ` - * :doc:`kim ` * :doc:`kspace_modify ` * :doc:`kspace_style ` * :doc:`label