Skip to content

Commit

Permalink
Update get_cmaize.cmake (#98)
Browse files Browse the repository at this point in the history
* Update get_cmaize.cmake

Fixes #97

* versions CMakePPLang too

* bump minimum CMake version

* address Zach's comments
  • Loading branch information
ryanmrichard authored Dec 6, 2023
1 parent 80fcb90 commit 447ed52
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
cmake: [3.14.7, latest, latestrc]
cmake: [3.19.0, latest, latestrc]
env:
cmake_version: ${{ matrix.cmake }}
os: Linux-x86_64
Expand All @@ -28,7 +28,7 @@ jobs:
- name: Configure Project
run: |
cmake -H. -Bbuild -DBUILD_TESTING=ON
- name: Run Unit Tests
run: |
cd build
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ docs/source/make_tutorials.py
!docs/source/tutorials/index.rst
__pycache__/

#CLion project settings
#IDE project settings
.idea/
settings.json
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
set(_ct_min_cmake_version "3.14" CACHE INTERNAL "")
cmake_minimum_required(VERSION "${_ct_min_cmake_version}") #Required for FetchContent_MakeAvailable()
#3.19 needed because of CMaize
set(_ct_min_cmake_version "3.19" CACHE INTERNAL "")
cmake_minimum_required(VERSION "${_ct_min_cmake_version}")
project(CMakeTest VERSION 1.0.0 LANGUAGES NONE)

if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(_ct_min_cmake_version "${_ct_min_cmake_version}" PARENT_SCOPE) #Make sure projects using CMakeTest have this variable
#Make sure projects using CMakeTest have this variable
set(_ct_min_cmake_version "${_ct_min_cmake_version}" PARENT_SCOPE)
endif()

# Add cmake directory to CMake's module path, iff it's not already there
list(FIND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" path_has_cmake)
if(${path_has_cmake} STREQUAL "-1")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
endif()

set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" CACHE STRING "" FORCE)

# Make sure projects including CMakeTest can find it too
if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) #For projects including CMakeTest
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
endif()

include("${PROJECT_SOURCE_DIR}/cmake/get_cmaize.cmake")

include(get_cmakepp_lang)
include(get_cmaize)
include(cmake_test/cmake_test)

if("${BUILD_TESTING}")
Expand Down
2 changes: 2 additions & 0 deletions cmake/get_cmaize.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#]]

include_guard()
include(versions)

#[[
# This function encapsulates the process of getting CMakePP using CMake's
Expand All @@ -39,6 +40,7 @@ function(get_cmaize)
FetchContent_Declare(
cmaize
GIT_REPOSITORY https://github.com/CMakePP/CMaize
GIT_TAG ${CMAIZE_VERSION}
)
FetchContent_MakeAvailable(cmaize)

Expand Down
61 changes: 61 additions & 0 deletions cmake/get_cmakepp_lang.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2023 CMakePP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#[[[ @module
# .. warning::
# This module is only used when building CMakeTest,
# and including it automatically pulls in CMakePPLang through
# FetchContent.
#]]

include_guard()
include(versions)

#[[
# This function encapsulates the process of getting CMakePPLang using CMake's
# FetchContent module. When CMaize supports find_or_build for CMake modules this
# file will be deprecated.
#]]
function(get_cmakepp_lang)
include(
cmakepp_lang/cmakepp_lang
OPTIONAL
RESULT_VARIABLE cmakepp_lang_found
)
if(NOT cmakepp_lang_found)
# Store whether we are building tests or not, then turn off the tests
set(build_testing_old "${BUILD_TESTING}")
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
# Download CMakePP and bring it into scope
include(FetchContent)
FetchContent_Declare(
cmakepp_lang
GIT_REPOSITORY https://github.com/CMakePP/CMakePPLang
GIT_TAG ${CMAKEPP_LANG_VERSION}
)
FetchContent_MakeAvailable(cmakepp_lang)

set(
CMAKE_MODULE_PATH
"${CMAKE_MODULE_PATH}" "${cmakepp_lang_SOURCE_DIR}/cmake"
PARENT_SCOPE
)

# Restore the previous value
set(BUILD_TESTING "${build_testing_old}" CACHE BOOL "" FORCE)
endif()
endfunction()

# Call the function we just wrote to get CMaize
get_cmakepp_lang()
18 changes: 18 additions & 0 deletions cmake/versions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 CMakePP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include_guard()

set(CMAKEPP_LANG_VERSION v1.0.0)
set(CMAIZE_VERSION v0.2.1)

0 comments on commit 447ed52

Please sign in to comment.