From 9e8cfcf80881bd1c63876ae707cfeddee7447881 Mon Sep 17 00:00:00 2001
From: Ward Fisher <wfisher@unidata.ucar.edu>
Date: Wed, 29 Aug 2012 18:58:08 +0000
Subject: [PATCH] Additional CMake support, CPack support.

---
 CMakeLists.txt         | 51 ++++++++++++++++++++++++++++--------------
 FixBundle.cmake.in     |  4 ++--
 include/CMakeLists.txt |  3 +++
 liblib/CMakeLists.txt  |  3 ++-
 nctest/CMakeLists.txt  |  4 ++--
 5 files changed, 43 insertions(+), 22 deletions(-)
 create mode 100644 include/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4a55d7a57..9a9ce46f6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,8 +4,6 @@ cmake_minimum_required(VERSION 2.8.8)
 #Project Name
 project(NetCDF C)
 SET(NetCDF_VERSION 4.2.1)
-SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYRIGHT")
-SET(CPACK_PACKAGE_VERSION "4.3")
 ENABLE_TESTING()
 INCLUDE(CTest)
 
@@ -24,6 +22,7 @@ ADD_DEFINITIONS()
 
 ### Verbose make, for debugging.
 #SET(CMAKE_VERBOSE_MAKEFILE ON)
+SET(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 #Add custom CMake Module
 SET (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/"
@@ -38,13 +37,8 @@ INCLUDE (${CMAKE_ROOT}/Modules/CheckCXXSourceCompiles.cmake)
 INCLUDE (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
 INCLUDE (${CMAKE_ROOT}/Modules/CheckSymbolExists.cmake)
 INCLUDE (${CMAKE_ROOT}/Modules/FindPkgConfig.cmake)
-SET(CMAKE_INCLUDE_CURRENT_DIR ON)
-IF(APPLE)
-  SET(CPACK_SOURCE_GENERATOR "TBZ2")
-  SET(CPACK_GENERATOR "DragNDrop")
-  SET(CPACK_BINARY_DRAGNDROP ON CACHE BOOL "")
-  SET(CPACK_BINARY_PACKAGEMAKER OFF CACHE BOOL "")
-ENDIF()
+INCLUDE (${CMAKE_ROOT}/Modules/GetPrerequisites.cmake)
+
 
 #####
 # A basic script used to convert m4 files
@@ -446,6 +440,7 @@ INCLUDE_DIRECTORIES(${NetCDF_SOURCE_DIR}/oc2)
 #add_subdirectory(h5_test)
 #add_subdirectory(man4)
 #add_subdirectory(man4/images)
+add_subdirectory("include")
 add_subdirectory(libdispatch)
 add_subdirectory(libsrc)
 
@@ -463,11 +458,11 @@ IF (BUILD_CDMREMOTE)
 ENDIF()
 
 add_subdirectory(liblib)
+MESSAGE(STATUS "Linking with: ${ALL_TLL_LIBS}") 
 
 # Enable Utilities.
 
 IF (BUILD_UTILITIES)
-	MESSAGE(STATUS "Linking with: ${ALL_TLL_LIBS}") 
 	ADD_SUBDIRECTORY(ncgen)
 	ADD_SUBDIRECTORY(ncgen3)
 	ADD_SUBDIRECTORY(ncdump)
@@ -502,10 +497,13 @@ ENDIF()
 #####
 INSTALL(FILES ${NetCDF_BINARY_DIR}/config.h
 	DESTINATION include)
-INSTALL(FILES ${NetCDF_SOURCE_DIR}/include/netcdf.h
-  DESTINATION include)
-
-INSTALL(FILES ${ALL_TLL_LIBS} DESTINATION deps)
+#INSTALL(FILES ${NetCDF_SOURCE_DIR}/include/netcdf.h
+#  DESTINATION include)
+INSTALL(DIRECTORY include DESTINATION include)
+IF(ENABLE_DOXYGEN)	
+	INSTALL(DIRECTORY man4 DESTINATION man4)
+ENDIF()
+#INSTALL(FILES ${ALL_TLL_LIBS} DESTINATION deps)
 
 # Subdirectory CMakeLists.txt files should specify their own
 # 'install' files.
@@ -516,11 +514,16 @@ CONFIGURE_FILE(
   ${CMAKE_CURRENT_BINARY_DIR}/FixBundle.cmake
   @ONLY
 )
+#INSTALL(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/FixBundle.cmake)
+
 #####
+# Various options for CPACK
+#####
+
+##
 # Declare exclusions list used when building a source file.
-# NOTE!! This list uses regular expressions, NOT wildcards!!
-# 
-##### 
+# NOTE!! This list uses regular expressions, NOT wildcards!! 
+## 
 SET (CPACK_SOURCE_IGNORE_FILES "${CPACK_SOURCE_IGNORE_FILES}"
 	"Makefile\\\\.in$"
 	"${CMAKE_BINARY_DIR}/*"
@@ -529,6 +532,20 @@ SET (CPACK_SOURCE_IGNORE_FILES "${CPACK_SOURCE_IGNORE_FILES}"
 	"my.*sh"
 	".*~" 
 )
+
+IF(APPLE)
+  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/COPYRIGHT
+	${CMAKE_CURRENT_BINARY_DIR}/COPYRIGHT.txt
+	@ONLY
+  )
+  SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/COPYRIGHT.txt")
+   
+  SET(CPACK_PACKAGE_VERSION "4.3")
+  SET(CPACK_SOURCE_GENERATOR "TBZ2")
+  SET(CPACK_GENERATOR "PackageMaker" "STGZ" "TBZ2" "TGZ" "ZIP")
+ENDIF()
+
+
 MESSAGE(STATUS "CPACK_SOURCE_IGNORE_FILES: ${CPACK_SOURCE_IGNORE_FILES}")
 # CPack inclusion must come last.
 INCLUDE(CPack)
diff --git a/FixBundle.cmake.in b/FixBundle.cmake.in
index 0a417f81d..02d43428e 100644
--- a/FixBundle.cmake.in
+++ b/FixBundle.cmake.in
@@ -2,10 +2,10 @@ INCLUDE(BundleUtilities)
 
 # Set bundle to the full path name of the executable
 
-SET (BUNDLE "${CMAKE_INSTALL_PREFIX}/ncdump@CMAKE_EXECUTABLE_SUFFIX@"
+SET (BUNDLE "${CMAKE_INSTALL_PREFIX}/ncdump@CMAKE_EXECUTABLE_SUFFIX@")
 
 SET (OTHER_LIBS "")
 
 SET (DIRS "@LIBRARY_OUTPUT_PATH@")
 
-fixup_bundle("${BUNDLE}" "${OTHER_LIBS}" "${DIRS}")
\ No newline at end of file
+fixup_bundle("${BUNDLE}" "${OTHER_LIBS}" "${DIRS}")
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
new file mode 100644
index 000000000..6f136d697
--- /dev/null
+++ b/include/CMakeLists.txt
@@ -0,0 +1,3 @@
+SET(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+INCLUDE_DIRECTORIES(".")
diff --git a/liblib/CMakeLists.txt b/liblib/CMakeLists.txt
index b27779b08..8b20c64a6 100644
--- a/liblib/CMakeLists.txt
+++ b/liblib/CMakeLists.txt
@@ -49,6 +49,7 @@ IF(ENABLE_PNETCDF AND PNETCDF)
 	#TARGET_LINK_LIBRARIES(netcdf ${PNETCDF})
 ENDIF()
 TARGET_LINK_LIBRARIES(netcdf ${TLL_LIBS})
-INSTALL(TARGETS netcdf DESTINATION lib)
+INSTALL(TARGETS netcdf DESTINATION lib EXPORT netcdf-targets)
+INSTALL(EXPORT netcdf-targets DESTINATION ".")
 #include(CPack)
 SET(ALL_TLL_LIBS ${TLL_LIBS} PARENT_SCOPE)
diff --git a/nctest/CMakeLists.txt b/nctest/CMakeLists.txt
index a37926d12..6f8132e91 100644
--- a/nctest/CMakeLists.txt
+++ b/nctest/CMakeLists.txt
@@ -13,8 +13,8 @@ ADD_EXECUTABLE(tst_rename tst_rename.c)
 TARGET_LINK_LIBRARIES(nctest netcdf)
 TARGET_LINK_LIBRARIES(tst_rename netcdf)
 
-INSTALL(TARGETS nctest DESTINATION bin)
-INSTALL(TARGETS tst_rename DESTINATION bin)
+#INSTALL(TARGETS nctest DESTINATION bin)
+#INSTALL(TARGETS tst_rename DESTINATION bin)
 ## Tests
 #ADD_TEST(run_tests.sh ${CMAKE_SOURCE_PATH}/run_tests.sh)