update cmakelists

This commit is contained in:
2021-08-27 18:38:01 +08:00
parent 97be4f5091
commit 2f66a01b14
4 changed files with 20 additions and 42 deletions

View File

@@ -1,29 +1,19 @@
cmake_minimum_required(VERSION 3.15.2)
# 设置工程名称和语言
project(NETCDF_CXX)
# 设置编译类型
set(CMAKE_BUILD_TYPE Release)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
# 设置windows安装地址
set(CMAKE_INSTALL_PREFIX D:/Library)
else()
# 设置Linux/Unix系统安装地址
set(CMAKE_INSTALL_PREFIX /opt/stow/netcdfcxx_legacy)
endif()
message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
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})
# 设置netcdf c接口的库文件地址
set(LIB_NETCDF_INC ${LIB_NETCDF}/include)
set(LIB_NETCDF_LIB ${LIB_NETCDF}/lib)
message(STATUS "netCDF directory: " ${LIB_NETCDF})
# 添加源文件地址
add_subdirectory(src/)

View File

@@ -1,17 +0,0 @@
#!/bin/bash
cmd=${1}
package=netcdfcxx_legacy
address=/opt/stow
targetdir=/usr/local
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 [[ ${cmd} == "install" ]]; then
cd build && sudo make install
sudo stow --dir=${address} --target=${targetdir} ${package}
fi

View File

@@ -1,9 +1,11 @@
# 设定源文件文件夹
aux_source_directory(lib/ NETCDF_SRC)
# netcdf安装后的动态库与静态库的地址不一样 需要手动在cmake生成的VS工程内添加下面的库地址
# 方法如下gctl->属性->链接器->附件库目录选择编辑并选择netcdf的可执行文件地址
#set(LIB_NETCDF_BIN C:/Program\ Files/netCDF\ 4.8.0/bin)
include_directories(${LIB_NETCDF_INC})
# 寻找netCDF库地址
find_package(netCDF REQUIRED)
if(netCDF_FOUND)
include_directories(${netCDF_INCLUDE_DIR})
endif()
# 设置编译选项
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
@@ -25,7 +27,7 @@ set_target_properties(netcdfcxx_legacy_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
# 设置动态库的版本号
set_target_properties(netcdfcxx_legacy PROPERTIES VERSION 1.0 SOVERSION 1.0)
find_library(NETCDF_LIBRARY netcdf ${LIB_NETCDF_LIB})
find_library(NETCDF_LIBRARY ${netCDF_LIBRARIES} ${netCDF_LIB_DIR})
target_link_libraries(netcdfcxx_legacy PUBLIC ${NETCDF_LIBRARY})
target_link_libraries(netcdfcxx_legacy_static ${NETCDF_LIBRARY})

3
stow_config.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
sudo stow --dir=/opt/stow --target=/usr/local netcdfcxx_legacy