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 cmakeVS
# 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