Skip to content

Commit

Permalink
Merge pull request #557 from jacobwilliams/develop-cmake
Browse files Browse the repository at this point in the history
Develop cmake
  • Loading branch information
jacobwilliams authored May 26, 2024
2 parents 384395a + 6b1235c commit 3a7525f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
if: contains( matrix.gcc_v, 9 )
uses: jwlawson/actions-setup-cmake@v2.0.2
with:
cmake-version: '3.19.x'
cmake-version: '3.28.x'

- name: Install Python
uses: actions/setup-python@v5.1.0 # Use pip to install latest CMake, & FORD/Jin2For, etc.
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
GCOV=gcov-${{matrix.gcc_v}}
mkdir cmake-build
cd cmake-build
cmake ..
cmake -D ENABLE_TESTS=ON ..
make -j 4 check
- name: Compile_with_build_mkdocs
Expand Down
66 changes: 50 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
# this software. The contributing author, Izaak Beekman, retains all
# rights permitted by the terms of the JSON-Fortran license.

cmake_minimum_required ( VERSION 3.5 FATAL_ERROR )
cmake_minimum_required ( VERSION 3.18 FATAL_ERROR )

option (JSONFORTRAN_ENABLE_DOC_GENERATION "Enable doc generation" OFF)
option (JSONFORTRAN_ENABLE_TESTS "Enable tests" OFF)
option (JSONFORTRAN_STATIC_LIBRARY_ONLY "Generate only static library" ON)

# Use MSVS folders to organize projects on windows
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Expand Down Expand Up @@ -164,8 +168,20 @@ endif ()
#---------------------------------------------

set ( LIB_NAME ${PROJECT_NAME} )
add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} )
add_library ( ${LIB_NAME}-static STATIC ${JF_LIB_SRCS} )
if(CMAKE_Fortran_COMPILER_ID STREQUAL IntelLLVM)
add_library ( ${LIB_NAME}-obj OBJECT ${JF_LIB_SRCS} )
set_property(TARGET ${LIB_NAME}-obj PROPERTY POSITION_INDEPENDENT_CODE 1)

add_library ( ${LIB_NAME} SHARED $<TARGET_OBJECTS:${LIB_NAME}-obj> )
add_library ( ${LIB_NAME}-static STATIC $<TARGET_OBJECTS:${LIB_NAME}-obj> )
else()
if (JSONFORTRAN_STATIC_LIBRARY_ONLY)
add_library ( ${LIB_NAME} STATIC ${JF_LIB_SRCS} )
add_library ( ${LIB_NAME}-static STATIC ${JF_LIB_SRCS} )
else()
add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} )
endif()
endif()

# add an alias so that including json-fortran is agnostic
# of find_package or being directly compiled through add_subdirectory
Expand All @@ -187,15 +203,26 @@ target_include_directories(${LIB_NAME}-static
PUBLIC
$<BUILD_INTERFACE:${MODULE_DIR}>
$<INSTALL_INTERFACE:${INSTALL_MOD_DIR}>)
set_target_properties ( ${LIB_NAME}-static
PROPERTIES
OUTPUT_NAME ${LIB_NAME}
if(NOT MSVC_IDE)
PREFIX lib
endif()
VERSION ${PROJECT_VERSION}
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
if(CMAKE_Fortran_COMPILER_ID STREQUAL IntelLLVM)
set_target_properties ( ${LIB_NAME}-static
PROPERTIES
if(NOT MSVC_IDE)
PREFIX lib
endif()
VERSION ${PROJECT_VERSION}
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
else()
set_target_properties ( ${LIB_NAME}-static
PROPERTIES
OUTPUT_NAME ${LIB_NAME}
if(NOT MSVC_IDE)
PREFIX lib
endif()
VERSION ${PROJECT_VERSION}
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
endif()
set_target_properties ( ${LIB_NAME}
PROPERTIES
OUTPUT_NAME ${LIB_NAME}
Expand All @@ -210,8 +237,12 @@ set_target_properties ( ${LIB_NAME}
#-------------------------------------
# Build the documentation with FORD
#-------------------------------------
set ( SKIP_DOC_GEN FALSE CACHE BOOL
"Disable building the API documentation with FORD" )
if (JSONFORTRAN_ENABLE_DOC_GENERATION)
set(SKIP_DOC_GEN FALSE CACHE BOOL "Disable building the API documentation with FORD")
else ()
set(SKIP_DOC_GEN TRUE CACHE BOOL "Disable building the API documentation with FORD" )
endif ()

if ( NOT SKIP_DOC_GEN )
find_program ( FORD ford )
if ( FORD ) # Found
Expand Down Expand Up @@ -284,8 +315,11 @@ endif ()
#--------------------------
# Handle test related stuff
#--------------------------
set ( ENABLE_TESTS TRUE CACHE BOOL
"Enable the JSON-Fortran tests." )
if (JSONFORTRAN_ENABLE_TESTS)
set ( ENABLE_TESTS TRUE CACHE BOOL "Enable the JSON-Fortran tests." )
else ()
set ( ENABLE_TESTS FALSE CACHE BOOL "Enable the JSON-Fortran tests." )
endif ()

#---------------------------------------------------------------------
# Add some tests to ensure that the software is performing as expected
Expand Down

0 comments on commit 3a7525f

Please sign in to comment.