From 97be4f509198dd110958b4784efa52b35cdfb321 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Thu, 26 Aug 2021 19:50:05 +0800 Subject: [PATCH] update cmakelists --- CMakeLists.txt | 15 ++++++++--- config.sh | 70 ++++++++------------------------------------------ 2 files changed, 23 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ceeb86..1de0ef2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,9 +4,18 @@ cmake_minimum_required(VERSION 3.15.2) project(NETCDF_CXX) message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME}) -if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") - #set(CMAKE_C_COMPILER gcc) - #set(CMAKE_CXX_COMPILER g++) +if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux") + # 配置netcdf C语言库的地址 + set(LIB_NETCDF /usr/local) +elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin" AND ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64") + # 配置netcdf C语言库的地址 + set(LIB_NETCDF /usr/local) +elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin") + # 配置netcdf C语言库的地址 + set(LIB_NETCDF /opt/homebrew) +elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") + set(LIB_NETCDF C:/Program\ Files/netCDF\ 4.8.0) + # 由于不能使用config.sh 我们需要单独为windows单独设置安装地址 set(CMAKE_INSTALL_PREFIX D:/Library) endif() message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX}) diff --git a/config.sh b/config.sh index 13c2404..c97b965 100755 --- a/config.sh +++ b/config.sh @@ -1,65 +1,17 @@ -#!/bin/bash +#!/bin/bash -package=NULL -runtype=configure -buildtype=Release -netcdflib=/usr/local -prefixdir=/opt/stow +cmd=${1} +package=netcdfcxx_legacy +address=/opt/stow targetdir=/usr/local -while getopts "hr:p:b:n:d:t:" arg -do - case $arg in - h) - echo "Install and manage packages with the Stow software." - echo "-r running type: configure (default), build or install." - echo "-p package name." - echo "-b build type: Release (default) or Debug." - echo "-n netCDF library address: /usr/local (default)." - echo "-d install prefix: /opt/stow (default)." - echo "-t target prefix: /opt (default)." - exit 0;; - r) - runtype=${OPTARG};; - p) - package=${OPTARG};; - b) - buildtype=${OPTARG};; - n) - netcdflib=${OPTARG};; - d) - prefixdir=${OPTARG};; - t) - targetdir=${OPTARG};; - ?) - echo "Error: unknow argument." - echo "Use -h option to see help information." - exit 1;; - esac -done - -if [[ ${runtype} == "configure" && ! -d "build/" ]]; then - if [[ ${package} == "NULL" ]]; then - echo "Error: no package name." - echo "Use -h option to see help information." - exit 1 - fi - mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=${prefixdir}/${package} -DCMAKE_BUILD_TYPE=${buildtype} -DLIB_NETCDF=${netcdflib} -elif [[ ${runtype} == "configure" ]]; then - if [[ ${package} == "NULL" ]]; then - echo "Error: no package name." - echo "Use -h option to see help information." - exit 1 - fi - cd build && rm -rf * && cmake .. -DCMAKE_INSTALL_PREFIX=${prefixdir}/${package} -DCMAKE_BUILD_TYPE=${buildtype} -DLIB_NETCDF=${netcdflib} -elif [[ ${runtype} == "build" ]]; then +if [[ ${cmd} == "configure" && ! -d "build/" ]]; then + mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=${address}/${package} -DCMAKE_BUILD_TYPE=Release +elif [[ ${cmd} == "configure" ]]; then + cd build && rm -rf * && cmake .. -DCMAKE_INSTALL_PREFIX=${address}/${package} -DCMAKE_BUILD_TYPE=Release +elif [[ ${cmd} == "build" ]]; then cd build && make -elif [[ ${runtype} == "install" ]]; then - if [[ ${package} == "NULL" ]]; then - echo "Error: no package name." - echo "Use -h option to see help information." - exit 1 - fi +elif [[ ${cmd} == "install" ]]; then cd build && sudo make install - sudo stow --dir=${prefixdir} --target=${targetdir} ${package} + sudo stow --dir=${address} --target=${targetdir} ${package} fi \ No newline at end of file