From 4f6f97281c07ab881b0f92109d381d0a61351ef3 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 14 Oct 2019 11:34:16 -0400 Subject: [PATCH] Improvements to SHTfile project inclusion. Will now look for SHTfile inside of EMSoft/ExternalProjects. If it is not found then it will clone it from github.com/emsoft-org/SHTfile Signed-off-by: Michael Jackson --- CMakeLists.txt | 44 +++++++++++++++++++-- Source/EMsoftLib/CMakeLists.txt | 44 +++++++++++---------- Source/EMsoftLib/sht_file.cpp | 69 +++++++++++++++------------------ 3 files changed, 97 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1b86cd2..c06a25d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,43 @@ if (NOT DEFINED CMP_SOURCE_DIR) endif() include (${CMP_SOURCE_DIR}/cmpCMakeMacros.cmake ) +#get_filename_component(EMsoft_PARENT ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY CACHE) + +find_package(Git REQUIRED) + +#------------------------------------------------------------------------------ +# If the developer has set another EMsoft directory then use that, otherwise look +# for the EMsoft directory at the same level as the EMsoftPrivate directory +if("${SHTfile_SOURCE_DIR}" STREQUAL "") + if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ExternalProjects") + file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ExternalProjects") + endif() + set(SHTfile_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ExternalProjects/SHTfile") + message(STATUS "Locating EMsoft Source directory at ${SHTfile_SOURCE_DIR}") + if(EXISTS "${SHTfile_SOURCE_DIR}") + message(STATUS "SHTfile_SOURCE_DIR: ${SHTfile_SOURCE_DIR}") + else() + + if(Git_FOUND) + message(STATUS "SHTfile_SOURCE_DIR does not exist at ${SHTfile_SOURCE_DIR}. Attempting to clone it from Github....") + execute_process(COMMAND ${GIT_EXECUTABLE} clone git@github.com:EMsoft-org/SHTfile.git ${SHTfile_SOURCE_DIR} + OUTPUT_VARIABLE CLONE_OUTPUT + RESULT_VARIABLE did_run + ERROR_VARIABLE git_error + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ExternalProjects) + endif() + # One last check. If it does not exist at this point then we simply Abort CMake + if(NOT EXISTS "${SHTfile_SOURCE_DIR}") + message(FATAL_ERROR "SHTfile_SOURCE_DIR does not exist. We attempted to clone it from the GitHub repo but that also seemed\ + to fail. EMsoft can not proceed without the SHTfile directory. Please ask a EMsoft developer for more\ + information about this error. Can you access http://github.com/EMsoft-org/SHTfile.git is\ + a firewall blocking the 'git' protocol? ") + endif() + + endif() +endif() + + # Next up, Set the version of EMsoft that is used through out the project. set(EMsoft_VER_MAJOR "5") @@ -180,9 +217,6 @@ if("${EMsoftSearchDirs}" STREQUAL "") endif() - - - # Set the Application Name to with the correct icons and badges set(CMP_HEADER_DIR ${EMsoft_BINARY_DIR}) set(PROJECT_RESOURCES_DIR "${EMsoft_SOURCE_DIR}/resources") @@ -270,6 +304,10 @@ OPTION(EMsoft_ENABLE_TESTING "Compile the test programs" ON) set(EMsoft_TESTING_DIR "${EMsoft_BINARY_DIR}/Testing") +# ----------------------------------------------------------------------- +# Build SHTfile Project +# ----------------------------------------------------------------------- +add_subdirectory(${SHTfile_SOURCE_DIR} ${EMsoft_BINARY_DIR}/SHTfile) # ----------------------------------------------------------------------- # Set a Global Prefix where everthing is going to get intalled. For OS X we are diff --git a/Source/EMsoftLib/CMakeLists.txt b/Source/EMsoftLib/CMakeLists.txt index fe89aed5..4965288f 100644 --- a/Source/EMsoftLib/CMakeLists.txt +++ b/Source/EMsoftLib/CMakeLists.txt @@ -17,23 +17,27 @@ add_custom_target(EMsoftLib_Generate_StringConstants ALL +if(0) + # fetch SHT file format content + # this could be done with a git submodule but the user would have to call: + # git submodule update + # git clone --recursive + # which is a bit annoying + include(FetchContent) + FetchContent_Declare( + SHTfile + GIT_REPOSITORY "https://github.com/EMsoft-org/SHTfile" + # GIT_TAG "v3.1.2" # just get the most recent version for now + # GIT_PROGRESS TRUE # its currently only 1 file, we probably don't need to print out progress + ) + # set(FETCHCONTENT_QUIET NO) # again only 1 file + FetchContent_MakeAvailable(SHTfile) + FetchContent_GetProperties(SHTfile BINARY_DIR SHTfile_BINARY_DIR) + include_directories(${SHTfile_BINARY_DIR}) +endif() + + -# fetch SHT file format content -# this could be done with a git submodule but the user would have to call: -# git submodule update -# git clone --recursive -# which is a bit annoying -include(FetchContent) -FetchContent_Declare( - SHTfile - GIT_REPOSITORY "https://github.com/EMsoft-org/SHTfile" - # GIT_TAG "v3.1.2" # just get the most recent version for now - # GIT_PROGRESS TRUE # its currently only 1 file, we probably don't need to print out progress -) -# set(FETCHCONTENT_QUIET NO) # again only 1 file -FetchContent_MakeAvailable(SHTfile) -FetchContent_GetProperties(SHTfile BINARY_DIR SHTfile_BINARY_DIR) -include_directories(${SHTfile_BINARY_DIR}) #------------------------------------------------------------------------------ @@ -131,6 +135,7 @@ set(EMsoftLib_C_SRCS set(EMsoftLib_Cpp_SRCS ${EMsoftLib_SOURCE_DIR}/sht_file.cpp + ${EMSphInx_BINARY_DIR}/sht_file.hpp ) if(NOT WIN32 AND BUILD_SHARED_LIBS) @@ -168,7 +173,7 @@ set_target_properties (EMsoftLib_Cpp PROPERTIES # Fortran_MODULE_DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY} FOLDER EMsoftPublic ) - +target_include_directories(EMsoftLib_Cpp PRIVATE ${EMSphInx_BINARY_DIR}) add_library(EMsoftLib ${LIB_TYPE} ${EMsoftLib_SRCS}) target_link_libraries(EMsoftLib @@ -176,9 +181,7 @@ target_link_libraries(EMsoftLib EMsoftLib_Cpp jsonfortran ${OpenCL_LIBRARY} - bcls::bcls - - + bcls::bcls ) if (Fortran_COMPILER_NAME MATCHES "ifort.*") target_link_libraries(EMsoftLib @@ -196,6 +199,7 @@ endif() target_include_directories(EMsoftLib PUBLIC ${CLFortran_INCLUDE_DIRS} ${FFTW3_INCLUDE_DIR}) + set_target_properties (EMsoftLib PROPERTIES LINKER_LANGUAGE Fortran # Fortran_MODULE_DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY} diff --git a/Source/EMsoftLib/sht_file.cpp b/Source/EMsoftLib/sht_file.cpp index 619290be..3738170d 100644 --- a/Source/EMsoftLib/sht_file.cpp +++ b/Source/EMsoftLib/sht_file.cpp @@ -1,36 +1,31 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * - * Copyright (c) 2019-2019, De Graef Group, Carnegie Mellon University * - * All rights reserved. * - * * - * Author: William C. Lenthe * - * * - * This package is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 2 of the * - * License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, check the Free Software Foundation * - * website: * - * * - * * - * Interested in a commercial license? Contact: * - * * - * Center for Technology Transfer and Enterprise Creation * - * 4615 Forbes Avenue, Suite 302 * - * Pittsburgh, PA 15213 * - * * - * phone. : 412.268.7393 * - * email : innovation@cmu.edu * - * website: https://www.cmu.edu/cttec/ * - * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* +* Copyright (c) 2018-2019, Marc De Graef Research Group/Carnegie Mellon University * +* All rights reserved. * +* * +* Redistribution and use in source and binary forms, with or without * +* modification, are permitted provided that the following conditions are met: * +* * +* - Redistributions of source code must retain the above copyright notice, this * +* list of conditions and the following disclaimer. * +* - Redistributions in binary form must reproduce the above copyright notice, * +* this list of conditions and the following disclaimer in the documentation * +* and/or other materials provided with the distribution. * +* - Neither the copyright holder nor the names of its * +* contributors may be used to endorse or promote products derived from * +* this software without specific prior written permission. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * +* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +* * +*/ #include "sht_file.hpp" @@ -48,10 +43,10 @@ extern "C" { //@param iprm: integer parameters {# electrons, electron multiplier, numsx, npx, latgridtype} //@param bw : bandwidth //@param alm: actual harmonics (uncompressed format) - int writeSHTfile_(char * fn, char const * nt, char const * doi, - int32_t * sgN, int32_t * sgS, int32_t * nAt, int32_t * aTy, float * aCd, float * lat, - float * fprm, int32_t * iprm, - int32_t * bw,double * alm) { + int writeSHTfile_(char* fn, const char* nt, const char* doi, + int32_t* sgN, int32_t* sgS, int32_t* nAt, int32_t* aTy, float* aCd, float* lat, + float* fprm, int32_t* iprm, + int32_t* bw,double* alm) { return sht::File::EMsoftEBSDRet(fn, nt, doi, *sgN, *sgS, *nAt, aTy, aCd, lat, fprm, iprm, *bw, alm); } }