Skip to content

Commit 87eda63

Browse files
committed
Merge branch 'cmake_updates' of https://github.com/K20shores/json-fortran into develop-cmake-updates
2 parents de3c062 + 64cbea5 commit 87eda63

File tree

4 files changed

+82
-75
lines changed

4 files changed

+82
-75
lines changed

.VERSION.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
${PROJECT_VERSION}

CMakeLists.txt

+19-71
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# this software. The contributing author, Izaak Beekman, retains all
1010
# rights permitted by the terms of the JSON-Fortran license.
1111

12-
cmake_minimum_required ( VERSION 2.8.8 FATAL_ERROR )
12+
cmake_minimum_required ( VERSION 3.0 FATAL_ERROR )
1313

1414
# Use MSVS folders to organize projects on windows
1515
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
@@ -34,7 +34,14 @@ include ( "cmake/checkOutOfSource.cmake" )
3434
#---------------------
3535
# Declare project name
3636
#---------------------
37-
project ( jsonfortran NONE )
37+
project (
38+
jsonfortran
39+
VERSION 8.3.0
40+
LANGUAGES Fortran
41+
)
42+
43+
# write the version file
44+
configure_file(${CMAKE_SOURCE_DIR}/.VERSION.in ${CMAKE_SOURCE_DIR}/.VERSION)
3845

3946
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
4047
option(JSON_FORTRAN_USE_OpenCoarrays
@@ -70,16 +77,6 @@ elseif(${JSON_INT_KIND} MATCHES "INT64")
7077
add_definitions(-DINT64)
7178
endif()
7279

73-
#----------------------------------
74-
# Get version (semantic versioning)
75-
# C.F. semver.org
76-
#----------------------------------
77-
file ( STRINGS "${PROJECT_SOURCE_DIR}/.VERSION" VERSION )
78-
string( REPLACE "." ";" VERSION_LIST ${VERSION} )
79-
list(GET VERSION_LIST 0 VERSION_MAJOR)
80-
list(GET VERSION_LIST 1 VERSION_MINOR)
81-
list(GET VERSION_LIST 2 VERSION_PATCH)
82-
set(PROJECT_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
8380
message ( STATUS "CMake build configuration for JSON-Fortran ${PROJECT_VERSION}" )
8481

8582
#-------------------------------------
@@ -170,6 +167,11 @@ set ( LIB_NAME ${PROJECT_NAME} )
170167
add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} )
171168
add_library ( ${LIB_NAME}-static STATIC ${JF_LIB_SRCS} )
172169

170+
# add an alias so that including json-fortran is agnostic
171+
# of find_package or being directly compiled through add_subdirectory
172+
add_library ( ${PACKAGE_NAME}::${LIB_NAME} ALIAS ${LIB_NAME} )
173+
add_library ( ${PACKAGE_NAME}::${LIB_NAME}-static ALIAS ${LIB_NAME}-static )
174+
173175
if(JSON_FORTRAN_USE_OpenCoarrays)
174176
target_link_libraries(${LIB_NAME}
175177
PRIVATE OpenCoarrays::caf_mpi_static)
@@ -191,7 +193,7 @@ set_target_properties ( ${LIB_NAME}-static
191193
if(NOT MSVC_IDE)
192194
PREFIX lib
193195
endif()
194-
VERSION ${VERSION}
196+
VERSION ${PROJECT_VERSION}
195197
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
196198
Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
197199
set_target_properties ( ${LIB_NAME}
@@ -200,8 +202,8 @@ set_target_properties ( ${LIB_NAME}
200202
if(NOT MSVC_IDE)
201203
PREFIX lib
202204
endif()
203-
SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR}
204-
VERSION ${VERSION}
205+
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
206+
VERSION ${PROJECT_VERSION}
205207
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
206208
Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR} )
207209

@@ -446,60 +448,6 @@ add_custom_target ( uninstall
446448
#-----------------------------------------------------
447449
# Publicize installed location to other CMake projects
448450
#-----------------------------------------------------
449-
install ( EXPORT ${PACKAGE_NAME}-targets
450-
NAMESPACE ${PACKAGE_NAME}::
451-
DESTINATION "${EXPORT_INSTALL_DIR}" )
452-
453-
include ( CMakePackageConfigHelpers ) # Standard CMake module
454-
write_basic_package_version_file( "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
455-
VERSION ${VERSION}
456-
COMPATIBILITY SameMajorVersion )
457-
458-
# provides COMPILER_CONSISTENCY_CHECK
459-
include ( cmake/FCompilerConsistencyCheck.cmake )
460-
461-
# install package config file
462-
configure_package_config_file (
463-
"${PROJECT_SOURCE_DIR}/cmake/pkg/${PROJECT_NAME}-config.cmake.in"
464-
"${PROJECT_BINARY_DIR}/pkg/${PACKAGE_NAME}-config.cmake"
465-
INSTALL_DESTINATION "${EXPORT_INSTALL_DIR}"
466-
PATH_VARS EXPORT_INSTALL_DIR INSTALL_MOD_DIR )
467-
468-
# Install the config and version files so that we can find this project with others
469-
install ( FILES
470-
"${PROJECT_BINARY_DIR}/pkg/${PACKAGE_NAME}-config.cmake"
471-
"${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
472-
DESTINATION "${EXPORT_INSTALL_DIR}" )
473-
474-
#----------------------------------------------
475-
# Make build tree targets accessible for import
476-
#----------------------------------------------
477-
export ( TARGETS ${LIB_NAME} ${LIB_NAME}-static FILE ${PACKAGE_NAME}-targets.cmake )
478-
479-
# build tree package config file, NOT installed
480-
configure_file (
481-
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
482-
"${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake"
483-
@ONLY )
484-
485-
set ( ENABLE_BUILD_TREE_EXPORT FALSE CACHE BOOL
486-
"Add the ${PACKAGE_NAME} build tree to the CMake package registry?" )
487-
if ( ENABLE_BUILD_TREE_EXPORT )
488-
export ( PACKAGE ${PACKAGE_NAME} )
489-
endif ()
490-
491-
# pkg-config stuff
492-
configure_file(
493-
"${CMAKE_CURRENT_SOURCE_DIR}/json-fortran.pc.cmake.in"
494-
"${CMAKE_CURRENT_BINARY_DIR}/json-fortran.pc"
495-
@ONLY
496-
)
497-
install(FILES
498-
"${CMAKE_CURRENT_BINARY_DIR}/json-fortran.pc"
499-
DESTINATION "${INSTALL_LIB_DIR}/pkgconfig"
500-
)
501-
502-
if(MSVC_IDE)
503-
INCLUDE_DIRECTORIES("src")
504-
SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fpp")
451+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
452+
add_subdirectory(packaging)
505453
endif()

packaging/CMakeLists.txt

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
install ( EXPORT ${PACKAGE_NAME}-targets
2+
NAMESPACE ${PACKAGE_NAME}::
3+
DESTINATION "${EXPORT_INSTALL_DIR}" )
4+
5+
include ( CMakePackageConfigHelpers ) # Standard CMake module
6+
write_basic_package_version_file( "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
7+
VERSION ${PROJECT_VERSION}
8+
COMPATIBILITY SameMajorVersion )
9+
10+
# provides COMPILER_CONSISTENCY_CHECK
11+
include ( ${PROJECT_SOURCE_DIR}/cmake/FCompilerConsistencyCheck.cmake )
12+
13+
# install package config file
14+
configure_package_config_file (
15+
"${PROJECT_SOURCE_DIR}/cmake/pkg/${PROJECT_NAME}-config.cmake.in"
16+
"${PROJECT_BINARY_DIR}/pkg/${PACKAGE_NAME}-config.cmake"
17+
INSTALL_DESTINATION "${EXPORT_INSTALL_DIR}"
18+
PATH_VARS EXPORT_INSTALL_DIR INSTALL_MOD_DIR )
19+
20+
# Install the config and version files so that we can find this project with others
21+
install ( FILES
22+
"${PROJECT_BINARY_DIR}/pkg/${PACKAGE_NAME}-config.cmake"
23+
"${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
24+
DESTINATION "${EXPORT_INSTALL_DIR}" )
25+
26+
#----------------------------------------------
27+
# Make build tree targets accessible for import
28+
#----------------------------------------------
29+
export ( TARGETS ${LIB_NAME} ${LIB_NAME}-static FILE ${PACKAGE_NAME}-targets.cmake )
30+
31+
# build tree package config file, NOT installed
32+
configure_file (
33+
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
34+
"${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake"
35+
@ONLY )
36+
37+
set ( ENABLE_BUILD_TREE_EXPORT FALSE CACHE BOOL
38+
"Add the ${PACKAGE_NAME} build tree to the CMake package registry?" )
39+
if ( ENABLE_BUILD_TREE_EXPORT )
40+
export ( PACKAGE ${PACKAGE_NAME} )
41+
endif ()
42+
43+
# pkg-config stuff
44+
configure_file(
45+
"${PROJECT_SOURCE_DIR}/json-fortran.pc.cmake.in"
46+
"${CMAKE_CURRENT_BINARY_DIR}/json-fortran.pc"
47+
@ONLY
48+
)
49+
install(FILES
50+
"${CMAKE_CURRENT_BINARY_DIR}/json-fortran.pc"
51+
DESTINATION "${INSTALL_LIB_DIR}/pkgconfig"
52+
)
53+
54+
if(MSVC_IDE)
55+
INCLUDE_DIRECTORIES("src")
56+
SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fpp")
57+
endif()

pages/development-resources/release-checklist.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ remain accurate.
1414
1. Look at the latest [changes committed to GitHub since the
1515
last release](https://github.com/jacobwilliams/json-fortran/compare/{!.VERSION!}...HEAD),
1616
{!.VERSION!}. This will only be accurate if you have
17-
not yet updated `.VERSION`. If you *have* updated
18-
`.VERSION` then edit the URL manually to view the
17+
not yet updated the project version in cmake. If you *have* updated
18+
the product version in cmake and run cmake (and therefore `.VERSION`) then edit the URL manually to view the
1919
changes.
2020
1. Run the
2121
[`github_changelog_generator`](https://github.com/github-changelog-generator/github-changelog-generator)
@@ -51,8 +51,9 @@ remain accurate.
5151
string
5252
1. Add `pages/releases/index.md` to the git index: `git add pages/releases/index.md`
5353
1. Update the version string in remaining files requiring manual edits:
54-
1. Edit the `.VERSION` file
55-
1. Edit the CMake example on line 141 of `README.md`
54+
1. Edit the product version in cmake
55+
1. Run cmake to product the .VERSION file
56+
1. Edit the CMake example on line 142 of `README.md`
5657
1. Edit the `json_fortran_version` string in `json_module.F90`
5758
1. Add these files to the git index: `git add .VERSION README.md ./src/json_module.F90`
5859
1. Commit the changes to the master branch: `git commit`

0 commit comments

Comments
 (0)