9
9
# this software. The contributing author, Izaak Beekman, retains all
10
10
# rights permitted by the terms of the JSON-Fortran license.
11
11
12
- cmake_minimum_required ( VERSION 2.8.8 FATAL_ERROR )
12
+ cmake_minimum_required ( VERSION 3.0 FATAL_ERROR )
13
13
14
14
# Use MSVS folders to organize projects on windows
15
15
set_property (GLOBAL PROPERTY USE_FOLDERS ON )
@@ -34,7 +34,14 @@ include ( "cmake/checkOutOfSource.cmake" )
34
34
#---------------------
35
35
# Declare project name
36
36
#---------------------
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 )
38
45
39
46
if (CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
40
47
option (JSON_FORTRAN_USE_OpenCoarrays
@@ -70,16 +77,6 @@ elseif(${JSON_INT_KIND} MATCHES "INT64")
70
77
add_definitions (-DINT64)
71
78
endif ()
72
79
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} " )
83
80
message ( STATUS "CMake build configuration for JSON-Fortran ${PROJECT_VERSION} " )
84
81
85
82
#-------------------------------------
@@ -170,6 +167,11 @@ set ( LIB_NAME ${PROJECT_NAME} )
170
167
add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} )
171
168
add_library ( ${LIB_NAME} -static STATIC ${JF_LIB_SRCS} )
172
169
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
+
173
175
if (JSON_FORTRAN_USE_OpenCoarrays)
174
176
target_link_libraries (${LIB_NAME}
175
177
PRIVATE OpenCoarrays::caf_mpi_static)
@@ -191,7 +193,7 @@ set_target_properties ( ${LIB_NAME}-static
191
193
if (NOT MSVC_IDE )
192
194
PREFIX lib
193
195
endif ()
194
- VERSION ${VERSION }
196
+ VERSION ${PROJECT_VERSION }
195
197
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib
196
198
Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
197
199
set_target_properties ( ${LIB_NAME}
@@ -200,8 +202,8 @@ set_target_properties ( ${LIB_NAME}
200
202
if (NOT MSVC_IDE )
201
203
PREFIX lib
202
204
endif ()
203
- SOVERSION ${VERSION_MAJOR } .${VERSION_MINOR }
204
- VERSION ${VERSION }
205
+ SOVERSION ${PROJECT_VERSION_MAJOR } .${PROJECT_VERSION_MINOR }
206
+ VERSION ${PROJECT_VERSION }
205
207
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib
206
208
Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR} )
207
209
@@ -446,60 +448,6 @@ add_custom_target ( uninstall
446
448
#-----------------------------------------------------
447
449
# Publicize installed location to other CMake projects
448
450
#-----------------------------------------------------
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)
505
453
endif ()
0 commit comments