Skip to content

Commit

Permalink
more consistent option names (#37)
Browse files Browse the repository at this point in the history
* rename options

* update CPM

* fix cmake

* fix cmake
  • Loading branch information
TheLartians authored Apr 14, 2019
1 parent 20c68a3 commit 522a1bb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ before_install:
- cmake --version

install:
- cmake -H. -Bbuild -DBUILD_LARS_PARSER_GLUE_EXTENSION=On
- cmake -H. -Bbuild -DLARS_PARSER_BUILD_GLUE_EXTENSION=On
- cmake --build build
- sudo cmake --build build --target install

Expand Down
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ endif()

# ---- Configuration variables ----

option(BUILD_LARS_PARSER_EXAMPLES "Enable examples" OFF)
option(ENABLE_LARS_PARSER_TESTS "Enable tests" OFF)
option(BUILD_LARS_PARSER_GLUE_EXTENSION "Build LarsParser Glue extension" OFF)
option(LARS_PARSER_BUILD_EXAMPLES "Enable examples" OFF)
option(LARS_PARSER_ENABLE_TESTS "Enable tests" OFF)
option(LARS_PARSER_BUILD_GLUE_EXTENSION "Build LarsParser Glue extension" OFF)

# ---- Dependencies ----

if(${ENABLE_LARS_PARSER_TESTS})
set(BUILD_LARS_PARSER_GLUE_EXTENSION ON)
if(${LARS_PARSER_ENABLE_TESTS})
set(LARS_PARSER_BUILD_GLUE_EXTENSION ON)
endif()

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake)
Expand All @@ -35,7 +35,7 @@ CPMAddPackage(
VERSION 0.7
)

if(${BUILD_LARS_PARSER_GLUE_EXTENSION})
if(${LARS_PARSER_BUILD_GLUE_EXTENSION})
CPMAddPackage(
NAME Glue
GIT_REPOSITORY https://github.com/TheLartians/Glue.git
Expand Down Expand Up @@ -66,7 +66,7 @@ SET(sources
"${CMAKE_CURRENT_SOURCE_DIR}/source/peg.cpp"
)

if(${BUILD_LARS_PARSER_GLUE_EXTENSION})
if(${LARS_PARSER_BUILD_GLUE_EXTENSION})
LIST(APPEND headers "${CMAKE_CURRENT_SOURCE_DIR}/include/lars/parser/extension.h")
LIST(APPEND sources "${CMAKE_CURRENT_SOURCE_DIR}/source/extension.cpp")
endif()
Expand All @@ -76,7 +76,7 @@ set_target_properties(LarsParser PROPERTIES COMPILE_FLAGS "-Wall -pedantic -Wext

target_link_libraries(LarsParser PRIVATE LHC)

if(${BUILD_LARS_PARSER_GLUE_EXTENSION})
if(${LARS_PARSER_BUILD_GLUE_EXTENSION})
target_link_libraries(LarsParser PUBLIC Glue)
endif()

Expand Down Expand Up @@ -140,7 +140,7 @@ ENDIF()

# ---- Tests ----

if(${ENABLE_LARS_PARSER_TESTS})
if(${LARS_PARSER_ENABLE_TESTS})
ENABLE_TESTING()
add_subdirectory(tests)
endif()
Expand Down
43 changes: 34 additions & 9 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@ if(CPM_DIRECTORY)
endif()
endif()

option(CPM_LOCAL_PACKAGES_ONLY "Use only locally installed packages" OFF)
option(CPM_REMOTE_PACKAGES_ONLY "Always download packages" OFF)

set(CPM_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "")
set(CPM_PACKAGES "" CACHE INTERNAL "")

include(FetchContent)
include(CMakeParseArguments)

option(CPM_LOCAL_PACKAGES_ONLY "Use only locally installed packages" OFF)
option(CPM_REMOTE_PACKAGES_ONLY "Always download packages" OFF)
function(CPMRegisterPackage PACKAGE VERSION)
LIST(APPEND CPM_PACKAGES ${CPM_ARGS_NAME})
set(CPM_PACKAGES ${CPM_PACKAGES} CACHE INTERNAL "")
set(PACKAGE_VERSION_VARIABLE "CPM_PACKAGE_${PACKAGE}_VERSION")
set(${PACKAGE_VERSION_VARIABLE} ${VERSION} CACHE INTERNAL "")
endfunction()

function(CPMGetPreviousPackageVersion PACKAGE)
set(PACKAGE_VERSION_VARIABLE "CPM_PACKAGE_${PACKAGE}_VERSION")
set(CPM_PREVIOUS_PACKAGE_VERSION "${${PACKAGE_VERSION_VARIABLE}}" PARENT_SCOPE)
endfunction()

function(CPMAddPackage)

Expand All @@ -24,26 +35,40 @@ function(CPMAddPackage)
GIT_TAG
)

cmake_parse_arguments(CPM_ARGS QUIET "${oneValueArgs}" "" ${ARGN})
set(multiValueArgs
OPTIONS
)

cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if (NOT CPM_ARGS_GIT_TAG)
set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION})
endif()

if (${CPM_ARGS_NAME} IN_LIST CPM_PACKAGES)
message(STATUS "CPM: not adding ${CPM_ARGS_NAME}@${CPM_ARGS_GIT_TAG}: already addded package ${CPM_ARGS_NAME}")
CPMGetPreviousPackageVersion(${CPM_ARGS_NAME})
message(STATUS "CPM: SKIP ${CPM_ARGS_NAME}@${CPM_ARGS_GIT_TAG}: already addded package ${CPM_ARGS_NAME}@${CPM_PREVIOUS_PACKAGE_VERSION}")
return()
endif()

LIST(APPEND CPM_PACKAGES ${CPM_ARGS_NAME})
set(CPM_PACKAGES ${CPM_PACKAGES} CACHE INTERNAL "")
CPMRegisterPackage(${CPM_ARGS_NAME} ${CPM_ARGS_GIT_TAG})

if (CPM_ARGS_OPTIONS)
foreach(OPTION ${CPM_ARGS_OPTIONS})
string(REGEX MATCH "^[^ ]+" OPTION_KEY ${OPTION})
string(LENGTH ${OPTION_KEY} OPTION_KEY_LENGTH)
math(EXPR OPTION_KEY_LENGTH "${OPTION_KEY_LENGTH}+1")
string(SUBSTRING ${OPTION} "${OPTION_KEY_LENGTH}" "-1" OPTION_VALUE)
set(${OPTION_KEY} ${OPTION_VALUE} CACHE INTERNAL "")
endforeach()
endif()

if (NOT ${CPM_REMOTE_PACKAGES_ONLY})
find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION} QUIET)
set(CPM_PACKAGE_FOUND ${CPM_ARGS_NAME}_FOUND)

if(${CPM_PACKAGE_FOUND})
message(STATUS "CPM: using local package ${CPM_ARGS_NAME}@${CPM_ARGS_VERSION}")
message(STATUS "CPM: ADD local package ${CPM_ARGS_NAME}@${CPM_ARGS_VERSION}")
set_target_properties(${CPM_ARGS_NAME}
PROPERTIES
IMPORTED_GLOBAL True
Expand All @@ -54,7 +79,7 @@ function(CPMAddPackage)

if (NOT ${CPM_LOCAL_PACKAGES_ONLY})

message(STATUS "CPM: fetching package ${CPM_ARGS_NAME}@${CPM_ARGS_GIT_TAG}")
message(STATUS "CPM: ADD remote package ${CPM_ARGS_NAME}@${CPM_ARGS_GIT_TAG}")

set(CPM_PACKAGE_CONTENT ${CPM_ARGS_NAME}_CONTENT)

Expand Down
2 changes: 1 addition & 1 deletion cmake/LarsParserConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include(CMakeFindDependencyMacro)

find_dependency(LHC)

if(@BUILD_LARS_PARSER_GLUE_EXTENSION@)
if(@LARS_PARSER_BUILD_GLUE_EXTENSION@)
find_dependency(Glue)
endif()

Expand Down

0 comments on commit 522a1bb

Please sign in to comment.