|
| 1 | +# CMake Configuration and build added by Izaak Beekman -- May, 2014 |
| 2 | + |
| 3 | +# Copy right (c) 2014, Izaak Beekman |
| 4 | +# All rights reserved. |
| 5 | + |
| 6 | +# This file is contributed to the json-fortran project, and |
| 7 | +# is licensed under the terms of json-fortran license. The json-fortran |
| 8 | +# license is located in the LICENSE file which must be distributed with |
| 9 | +# this software. The contributing author, Izaak Beekman, retains all |
| 10 | +# rights permitted by the terms of the json-fortran license. |
| 11 | + |
| 12 | +cmake_minimum_required ( VERSION 2.8 FATAL_ERROR ) |
| 13 | + |
| 14 | +# Set the type/configuration of build to perform |
| 15 | +set ( CMAKE_CONFIGURATION_TYPES "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) |
| 16 | +set ( CMAKE_BUILD_TYPE "Release" |
| 17 | + CACHE STRING "Select which configuration to build." ) |
| 18 | +set_property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES} ) |
| 19 | + |
| 20 | + |
| 21 | +enable_language ( Fortran ) |
| 22 | +include ( "cmake/pickFortranCompilerFlags.cmake" ) |
| 23 | + |
| 24 | +# Check for in-source builds and error out if found |
| 25 | +# Provides an advanced option to allow in source builds |
| 26 | +include ( "cmake/checkOutOfSource.cmake" ) |
| 27 | + |
| 28 | +#--------------------- |
| 29 | +# Declare project name |
| 30 | +#--------------------- |
| 31 | +project ( jsonfortran NONE ) |
| 32 | + |
| 33 | +#---------------------------------- |
| 34 | +# Set version (semantic versioning) |
| 35 | +# C.F. semver.org |
| 36 | +#---------------------------------- |
| 37 | +set ( VERSION_MAJOR 1 ) |
| 38 | +set ( VERSION_MINOR 0 ) |
| 39 | +set ( VERSION_PATCH 0 ) |
| 40 | +set ( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" ) |
| 41 | + |
| 42 | +#------------------------------------- |
| 43 | +# Collect source files for the library |
| 44 | +#------------------------------------- |
| 45 | +set ( JF_LIB_SRCS src/json_module.f90 ) |
| 46 | + |
| 47 | +#----------------------------------------- |
| 48 | +# Collect all the mod files into their own |
| 49 | +# directory to ease installation issues |
| 50 | +#----------------------------------------- |
| 51 | +set ( CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/lib" ) |
| 52 | + |
| 53 | +#------------------------------------- |
| 54 | +# Define where our files get installed |
| 55 | +#------------------------------------- |
| 56 | +# Set the package name to be specific to the compiler used, so that |
| 57 | +# versions compiled with different compilers can be installed in parallel |
| 58 | +string ( TOLOWER ${CMAKE_PROJECT_NAME}-${CMAKE_Fortran_COMPILER_ID} PACKAGE_NAME ) |
| 59 | +string ( TOLOWER ${CMAKE_Fortran_COMPILER_ID}-compiler FCOMPILER_DIR ) |
| 60 | +set ( PACKAGE_VERSION "${PACKAGE_NAME}-${VERSION}" ) |
| 61 | + |
| 62 | + |
| 63 | +# Most of this could be 'wrong' for Windows/Cygwin |
| 64 | + |
| 65 | +set ( INSTALL_MOD_DIR "${PACKAGE_VERSION}/lib" ) |
| 66 | +set ( INSTALL_LIB_DIR "${INSTALL_MOD_DIR}" ) |
| 67 | +set( ABS_LIB_INSTALL_DIR "\${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB_DIR}" ) |
| 68 | + |
| 69 | +# Put package export CMake files where they can be found |
| 70 | +# use `find_package ( jsonfortran-${CMAKE_Fortran_COMPILER_ID} <version> REQUIRED )` |
| 71 | +set ( EXPORT_INSTALL_DIR "${PACKAGE_VERSION}/cmake" ) |
| 72 | + |
| 73 | +if ( "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" ) |
| 74 | + set ( ENABLE_DYLIBS_USE_RPATH TRUE CACHE BOOL |
| 75 | + "Enable @rpath install name for dylibs" ) |
| 76 | + mark_as_advanced ( ENABLE_DYLIBS_USE_RPATH ) |
| 77 | +endif ( "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" ) |
| 78 | + |
| 79 | +if ( ENABLE_DYLIBS_USE_RPATH ) |
| 80 | + set ( CMAKE_MACOSX_RPATH TRUE ) |
| 81 | +else ( ENABLE_DYLIBS_USE_RPATH ) |
| 82 | + set ( CMAKE_INSTALL_NAME_DIR |
| 83 | + "${ABS_LIB_INSTALL_DIR}" ) |
| 84 | +endif ( ENABLE_DYLIBS_USE_RPATH ) |
| 85 | + |
| 86 | +#--------------------------------------------- |
| 87 | +# Build a shared and static library by default |
| 88 | +#--------------------------------------------- |
| 89 | + |
| 90 | +set ( LIB_NAME ${CMAKE_PROJECT_NAME} ) |
| 91 | +add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} ) |
| 92 | +add_library ( ${LIB_NAME}-static STATIC ${JF_LIB_SRCS} ) |
| 93 | +set_target_properties ( ${LIB_NAME}-static |
| 94 | + PROPERTIES |
| 95 | + OUTPUT_NAME ${LIB_NAME} |
| 96 | + PREFIX lib |
| 97 | + VERSION ${VERSION} ) |
| 98 | +set_target_properties ( ${LIB_NAME} |
| 99 | + PROPERTIES |
| 100 | + OUTPUT_NAME ${LIB_NAME} |
| 101 | + PREFIX lib |
| 102 | + SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR} |
| 103 | + VERSION ${VERSION} ) |
| 104 | + |
| 105 | +#--------------------------------------------------------------------- |
| 106 | +# Add some tests to ensure that the software is performing as expected |
| 107 | +#--------------------------------------------------------------------- |
| 108 | +# Not implemented yet |
| 109 | + |
| 110 | +#------------------------- |
| 111 | +# Perform the installation |
| 112 | +#------------------------- |
| 113 | + |
| 114 | +install ( TARGETS ${LIB_NAME} ${LIB_NAME}-static |
| 115 | + EXPORT ${PACKAGE_NAME}-targets |
| 116 | + LIBRARY DESTINATION "${INSTALL_LIB_DIR}" |
| 117 | + ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" ) |
| 118 | + |
| 119 | +# Code to fix the dylib install name on Mac. |
| 120 | +include ( cmake/fixupInstallNameDir.cmake ) |
| 121 | + |
| 122 | +install ( DIRECTORY "${CMAKE_Fortran_MODULE_DIRECTORY}/" DESTINATION "${INSTALL_MOD_DIR}" ) |
| 123 | + |
| 124 | +#------------------------------------------ |
| 125 | +# Add portable unistall command to makefile |
| 126 | +#------------------------------------------ |
| 127 | +# Adapted from the CMake Wiki FAQ |
| 128 | +configure_file ( "${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in" "${CMAKE_BINARY_DIR}/uninstall.cmake" |
| 129 | + @ONLY) |
| 130 | + |
| 131 | +add_custom_target ( uninstall |
| 132 | + COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/uninstall.cmake" ) |
| 133 | + |
| 134 | +#----------------------------------------------------- |
| 135 | +# Publicize installed location to other CMake projects |
| 136 | +#----------------------------------------------------- |
| 137 | +install ( EXPORT ${PACKAGE_NAME}-targets DESTINATION "${EXPORT_INSTALL_DIR}" ) |
| 138 | + |
| 139 | +include ( CMakePackageConfigHelpers ) # Standard CMake module |
| 140 | +write_basic_package_version_file( "${CMAKE_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" |
| 141 | + VERSION ${VERSION} |
| 142 | + COMPATIBILITY SameMajorVersion ) |
| 143 | + |
| 144 | +# provides COMPILER_CONSISTENCY_CHECK |
| 145 | +include ( cmake/FCompilerConsistencyCheck.cmake ) |
| 146 | + |
| 147 | +# install package config file |
| 148 | +configure_package_config_file ( |
| 149 | + "${CMAKE_SOURCE_DIR}/cmake/pkg/${CMAKE_PROJECT_NAME}-config.cmake.in" |
| 150 | + "${CMAKE_BINARY_DIR}/pkg/${PACKAGE_NAME}-config.cmake" |
| 151 | + INSTALL_DESTINATION "${EXPORT_INSTALL_DIR}" |
| 152 | + PATH_VARS EXPORT_INSTALL_DIR INSTALL_MOD_DIR ) |
| 153 | + |
| 154 | +# Install the config and version files so that we can find this project with others |
| 155 | +install ( FILES |
| 156 | + "${CMAKE_BINARY_DIR}/pkg/${PACKAGE_NAME}-config.cmake" |
| 157 | + "${CMAKE_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" |
| 158 | + DESTINATION "${EXPORT_INSTALL_DIR}" ) |
| 159 | + |
| 160 | +#---------------------------------------------- |
| 161 | +# Make build tree targets accessible for import |
| 162 | +#---------------------------------------------- |
| 163 | +export ( TARGETS ${LIB_NAME} ${LIB_NAME}-static FILE ${PACKAGE_NAME}-targets.cmake ) |
| 164 | + |
| 165 | +# build tree package config file, NOT installed |
| 166 | +configure_file ( |
| 167 | + "${CMAKE_SOURCE_DIR}/cmake/${CMAKE_PROJECT_NAME}-config.cmake.in" |
| 168 | + "${CMAKE_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" |
| 169 | + @ONLY ) |
| 170 | + |
| 171 | +set ( ENABLE_BUILD_TREE_EXPORT FALSE CACHE BOOL |
| 172 | + "Add the ${PACKAGE_NAME} build tree to the CMake package registry?" ) |
| 173 | +if ( ENABLE_BUILD_TREE_EXPORT ) |
| 174 | + export ( PACKAGE ${PACKAGE_NAME} ) |
| 175 | +endif ( ENABLE_BUILD_TREE_EXPORT ) |
0 commit comments