Skip to content

Commit

Permalink
Fix the minimum CMake version (#91)
Browse files Browse the repository at this point in the history
- This closes #89 and possibly relates to #90. 
- The new manually triggered CI job uses the suggestions from #89 to find the minimum CMake version.
- Wrong version of cmake required to compile the library #89 to find the minimum CMake version.
- The minor adjustments in the CMakeLists.txt reduce the needed CMake version to 3.8 instead of 3.18
- The missing CoolProp include directories have also been fixed.
- As pointed out in #85, we may want to bring back the subdirectory notation for GCC and friends, this is also included here.
  • Loading branch information
jowr authored Sep 5, 2023
1 parent ebe3740 commit 8f5df11
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 32 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/cmake_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Minimum CMake version

# only allow manual triggers and the cmake branch
on:
workflow_dispatch:
push:
branches:
- fix/cmake_version

jobs:

min-cmake:
runs-on: ${{ matrix.platform }}
strategy:
matrix:
platform: [ubuntu-latest] #, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3
- name: Get the latest script
run: git clone --recursive https://github.com/nlohmann/cmake_min_version.git cmake_min_version
- name: Prepare the environment
run: |
cd cmake_min_version
python3 -mvenv venv
venv/bin/pip3 install -r requirements.txt
venv/bin/python3 cmake_downloader.py --latest_patch
- name: Run the script
run: |
cd cmake_min_version
venv/bin/python cmake_min_version.py ${GITHUB_WORKSPACE}/Projects
73 changes: 41 additions & 32 deletions Projects/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
cmake_minimum_required(VERSION 3.8.2 FATAL_ERROR) # Due to the use of target_compile_definitions
include(ExternalProject)

CMAKE_POLICY(SET CMP0053 NEW)
Expand Down Expand Up @@ -55,27 +55,37 @@ option(FLUIDPROP "Include the FluidProp library for fluid properties" OFF)

if(COOLPROP)
# Get the CoolProp code
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git")
if(NOT EXISTS "${CMAKE_BINARY_DIR}/coolprop.zip")
set(COOLPROP_SOURCES "${CMAKE_BINARY_DIR}/CoolProp.sources")
#file(REMOVE_RECURSE "${COOLPROP_SOURCES}")
if(EXISTS "${COOLPROP_SOURCES}")
message(STATUS "Using existing CoolProp sources from ${COOLPROP_SOURCES}")
else()
message(STATUS "Updating CoolProp sources in ${COOLPROP_SOURCES}")
set(COOLPROP_SOURCES_GIT "${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git")
if(EXISTS "${COOLPROP_SOURCES_GIT}")
message(STATUS "Using existing CoolProp sources from ${COOLPROP_SOURCES_GIT}")
#file(COPY "${COOLPROP_SOURCES_GIT}" DESTINATION "${COOLPROP_SOURCES}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_directory "${COOLPROP_SOURCES_GIT}" "${COOLPROP_SOURCES}"
)
else()
message(STATUS "Downloading CoolProp sources from the released archive")
file(DOWNLOAD https://sourceforge.net/projects/coolprop/files/CoolProp/6.5.0/source/CoolProp_sources.zip/download "${CMAKE_BINARY_DIR}/coolprop.zip")
#file(DOWNLOAD https://sourceforge.net/projects/coolprop/files/CoolProp/nightly/source/CoolProp_sources.zip/download "${CMAKE_BINARY_DIR}/coolprop.zip")
# Unpack the sources for CoolProp
if(${CMAKE_VERSION} VERSION_LESS "3.18")
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xjf "${CMAKE_BINARY_DIR}/coolprop.zip"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
else()
file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/coolprop.zip)
endif()
file(RENAME "${CMAKE_BINARY_DIR}/source" "${COOLPROP_SOURCES}")
endif()
#file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/coolprop-tmp")
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/source")
# Use CMake to unzip
#file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/coolprop-tmp")
#execute_process(
# COMMAND ${CMAKE_COMMAND} -E tar xjf "${CMAKE_BINARY_DIR}/coolprop.zip"
# WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/coolprop-tmp"
#)
file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/coolprop.zip)
#execute_process(COMMAND unzip ${CMAKE_BINARY_DIR}/coolprop.zip -d "${CMAKE_BINARY_DIR}/coolprop-tmp")
#execute_process(COMMAND sed -i '421s;^;\#;' "${CMAKE_BINARY_DIR}/coolprop-tmp/CoolProp.sources/CMakeLists.txt")
#file(RENAME "${CMAKE_BINARY_DIR}/coolprop-tmp/CoolProp.sources" "${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git")
file(RENAME "${CMAKE_BINARY_DIR}/source" "${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git")
#file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/coolprop-tmp")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/CoolProp")
endif()
# Prepare the CoolProp build, "${COOLPROP_SOURCES}" is ready now
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/CoolProp")
# Configure CMake switches for CoolProp
SET(COOLPROP_STATIC_LIBRARY OFF CACHE BOOL "Force the object library")
SET(COOLPROP_SHARED_LIBRARY OFF CACHE BOOL "Force the object library")
Expand All @@ -91,16 +101,16 @@ if(COOLPROP)
# Enable this for shared libraries (either CoolProp itself or ExternalMedia)
SET(COOLPROP_FPIC ON CACHE BOOL "force -fPIC switch")
# Add the CoolProp sources
ADD_SUBDIRECTORY ("${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git" "${CMAKE_CURRENT_BINARY_DIR}/CoolProp")
list (APPEND INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git")
list (APPEND INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git/include")
list (APPEND INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git/externals/msgpack-c/include")
ADD_SUBDIRECTORY ("${COOLPROP_SOURCES}" "${CMAKE_CURRENT_BINARY_DIR}/CoolProp")
list (APPEND INCLUDE_DIRS "${COOLPROP_SOURCES}")
list (APPEND INCLUDE_DIRS "${COOLPROP_SOURCES}/include")
list (APPEND INCLUDE_DIRS "${COOLPROP_SOURCES}/externals/msgpack-c/include")
# Handle different CoolProp versions
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git/externals/cppformat")
list (APPEND INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git/externals/cppformat")
if(EXISTS "${COOLPROP_SOURCES}/externals/cppformat")
list (APPEND INCLUDE_DIRS "${COOLPROP_SOURCES}/externals/cppformat")
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git/externals/fmtlib")
list (APPEND INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../externals/CoolProp.git/externals/fmtlib")
if(EXISTS "${COOLPROP_SOURCES}/externals/fmtlib/include")
list (APPEND INCLUDE_DIRS "${COOLPROP_SOURCES}/externals/fmtlib/include")
endif()
endif()

Expand Down Expand Up @@ -245,13 +255,12 @@ endif()

set(MODELICA_INSTALL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../Modelica/ExternalMedia/Resources")
INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/Sources/${LIBRARY_HEADER}" DESTINATION "${MODELICA_INSTALL_PATH}/Include")
if(WIN32)
message(STATUS "Installation path: ${MODELICA_INSTALL_PATH}/Library/${MODELICA_PLATFORM}/${MODELICA_COMPILER}")
INSTALL(TARGETS "${LIBRARY_NAME}" DESTINATION "${MODELICA_INSTALL_PATH}/Library/${MODELICA_PLATFORM}/${MODELICA_COMPILER}")
else()
message(STATUS "Installation path: ${MODELICA_INSTALL_PATH}/Library/${MODELICA_PLATFORM}/${MODELICA_COMPILER}")
INSTALL(TARGETS "${LIBRARY_NAME}" DESTINATION "${MODELICA_INSTALL_PATH}/Library/${MODELICA_PLATFORM}/${MODELICA_COMPILER}")
if(NOT WIN32)
# Both OpenModelica and Dymola on Linux DO NOT expect a compiler-specific subdirectory
# NB: This means that subsequent builds for different compilers overwrite the previously installed binaries.
message(STATUS "Installation path: ${MODELICA_INSTALL_PATH}/Library/${MODELICA_PLATFORM}")
# NB: This means that subsequent builds for different compilers overwrite the previously installed default binaries.
message(STATUS "Additional installation path: ${MODELICA_INSTALL_PATH}/Library/${MODELICA_PLATFORM}")
INSTALL(TARGETS "${LIBRARY_NAME}" DESTINATION "${MODELICA_INSTALL_PATH}/Library/${MODELICA_PLATFORM}")
endif()

Expand Down

0 comments on commit 8f5df11

Please sign in to comment.