Skip to content

Commit

Permalink
Merge pull request #1 from intercreate/fix/define-strings
Browse files Browse the repository at this point in the history
Fix/define strings
  • Loading branch information
JPHutchins authored Jun 8, 2024
2 parents 58e067d + 6d20d43 commit 2f90670
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
54 changes: 27 additions & 27 deletions src/ic_project.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ function(ic_project
endif()
endforeach()

set_definition("${out_client_name}" ${_CLIENT_NAME} PARENT_SCOPE)
set_definition("${out_project_name}" ${_PROJECT_NAME} PARENT_SCOPE)
set_definition("${out_board_name}" "${_BOARD_NAME}" PARENT_SCOPE)
if_set_definition("${out_board_rev}" "${_BOARD_REV}" PARENT_SCOPE)
if_set_definition("${out_fw_version}" "${_FW_VERSION}" PARENT_SCOPE)
if_set_definition("${out_build_type}" "${_BUILD_TYPE}" PARENT_SCOPE)
set_definition_string("${out_client_name}" "${_CLIENT_NAME}" PARENT_SCOPE)
set_definition_string("${out_project_name}" "${_PROJECT_NAME}" PARENT_SCOPE)
set_definition_string("${out_board_name}" "${_BOARD_NAME}" PARENT_SCOPE)
if_set_definition_string("${out_board_rev}" "${_BOARD_REV}" PARENT_SCOPE)
if_set_definition_string("${out_fw_version}" "${_FW_VERSION}" PARENT_SCOPE)
if_set_definition_string("${out_build_type}" "${_BUILD_TYPE}" PARENT_SCOPE)

# Warn about git tag
execute_process(
Expand Down Expand Up @@ -123,72 +123,72 @@ function(ic_project
OUTPUT_VARIABLE git_hash
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set_definition("${out_git_hash}" ${git_hash} PARENT_SCOPE)
set_definition_string("${out_git_hash}" "${git_hash}" PARENT_SCOPE)

# Set git dirty commit
string(FIND ${git_hash} + res)
if(res EQUAL -1)
set_definition("${out_git_dirty}" 0 PARENT_SCOPE)
set_definition_string("${out_git_dirty}" 0 PARENT_SCOPE)
else()
set_definition("${out_git_dirty}" 1 PARENT_SCOPE)
set_definition_string("${out_git_dirty}" 1 PARENT_SCOPE)
endif()

if(${has_git_tag})
# Set the git tag
string(REPLACE "-" ";" fw_version_list ${git_tag})
list(GET fw_version_list 0 git_label)
set_definition("${out_git_tag}" ${git_label} PARENT_SCOPE)
set_definition_string("${out_git_tag}" "${git_label}" PARENT_SCOPE)

# Set the git tag revision
list(LENGTH fw_version_list len)
if (len EQUAL 3)
list(GET fw_version_list 1 git_tag_rev)
set_definition("${out_git_tag_rev}" ${git_tag_rev} PARENT_SCOPE)
set_definition_string("${out_git_tag_rev}" "${git_tag_rev}" PARENT_SCOPE)
else()
set_definition("${out_git_tag_rev}" "" PARENT_SCOPE)
set_definition_string("${out_git_tag_rev}" "" PARENT_SCOPE)
endif()
else()
set_definition("${out_git_tag}" "" PARENT_SCOPE)
set_definition("${out_git_tag_rev}" "" PARENT_SCOPE)
set_definition_string("${out_git_tag}" "" PARENT_SCOPE)
set_definition_string("${out_git_tag_rev}" "" PARENT_SCOPE)
endif()

if(NOT DEFINED ${out_fw_version})
if(${has_git_tag})
if(NOT "${git_tag_rev}" STREQUAL "")
set_definition("${out_fw_version}" "${git_label}-${git_tag_rev}" PARENT_SCOPE)
set_definition_string("${out_fw_version}" "${git_label}-${git_tag_rev}" PARENT_SCOPE)
else()
set_definition("${out_fw_version}" "${git_label}" PARENT_SCOPE)
set_definition_string("${out_fw_version}" "${git_label}" PARENT_SCOPE)
endif()
else()
set_definition("${out_fw_version}" ${git_hash} PARENT_SCOPE)
set_definition_string("${out_fw_version}" "${git_hash}" PARENT_SCOPE)
endif()
endif()

string(TIMESTAMP build_date "%Y%m%d")
set_definition("${out_build_date}" ${build_date} PARENT_SCOPE)
set_definition_string("${out_build_date}" "${build_date}" PARENT_SCOPE)
string(TIMESTAMP timestamp)
set_definition("${out_build_time}" ${timestamp} PARENT_SCOPE)
set_definition_string("${out_build_time}" "${timestamp}" PARENT_SCOPE)

# Set user info
execute_process(
COMMAND git config user.name
OUTPUT_VARIABLE user_name
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set_definition("${out_git_user_name}" ${user_name} PARENT_SCOPE)
set_definition_string("${out_git_user_name}" "${user_name}" PARENT_SCOPE)
execute_process(
COMMAND git config user.email
OUTPUT_VARIABLE user_email
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set_definition("${out_git_user_email}" ${user_email} PARENT_SCOPE)
set_definition_string("${out_git_user_email}" "${user_email}" PARENT_SCOPE)

# Set build environment info
set_definition("${out_c_compiler_id}" ${CMAKE_C_COMPILER_ID} PARENT_SCOPE)
set_definition("${out_c_compiler}" ${CMAKE_C_COMPILER} PARENT_SCOPE)
set_definition("${out_c_compiler_version}" ${CMAKE_C_COMPILER_VERSION} PARENT_SCOPE)
set_definition("${out_host_system_name}" ${CMAKE_HOST_SYSTEM} PARENT_SCOPE)
set_definition("${out_host_system_version}" ${CMAKE_HOST_SYSTEM_VERSION} PARENT_SCOPE)
set_definition_string("${out_c_compiler_id}" "${CMAKE_C_COMPILER_ID}" PARENT_SCOPE)
set_definition_string("${out_c_compiler}" "${CMAKE_C_COMPILER}" PARENT_SCOPE)
set_definition_string("${out_c_compiler_version}" "${CMAKE_C_COMPILER_VERSION}" PARENT_SCOPE)
set_definition_string("${out_host_system_name}" "${CMAKE_HOST_SYSTEM_NAME}" PARENT_SCOPE)
set_definition_string("${out_host_system_version}" "${CMAKE_HOST_SYSTEM_VERSION}" PARENT_SCOPE)

if(NOT "" STREQUAL "${_BOARD_REV}")
set(board_rev_string @${_BOARD_REV})
Expand All @@ -204,7 +204,7 @@ function(ic_project
"${_CLIENT_NAME}_${_PROJECT_NAME}_${_BOARD_NAME}${board_rev_string}_${${out_fw_version}}_${git_hash}_${build_date}${build_type_string}"
)
string(REPLACE " " "_" config_string ${config_string})
set_definition("${out_full_name}" ${config_string} PARENT_SCOPE)
set_definition_string("${out_full_name}" "${config_string}" PARENT_SCOPE)

endfunction()

Expand Down
14 changes: 7 additions & 7 deletions src/ic_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ set() the CMake variable and add_compile_definition()
<value> : the value to set name to
[PARENT_SCOPE] : call set() with PARENT_SCOPE
#]]
macro(set_definition name value)
macro(set_definition_string name value)
if(NOT ${ARGC} EQUAL 2 AND NOT ${ARGC} EQUAL 3)
message(
FATAL_ERROR
"Invalid arguments to set_definition(<name> <value> [PARENT_SCOPE]): (${name} ${value} ${ARGN})"
"Invalid arguments to set_definition_string(<name> <value> [PARENT_SCOPE]): (${name} ${value} ${ARGN})"
)
elseif(${ARGC} EQUAL 3 AND NOT ${ARG2} EQUAL PARENT_SCOPE)
message(
FATAL_ERROR
"Invalid arguments to set_definition(<name> <value> [PARENT_SCOPE]): (${name} ${value} ${ARGN})"
"Invalid arguments to set_definition_string(<name> <value> [PARENT_SCOPE]): (${name} ${value} ${ARGN})"
)
endif()

Expand All @@ -45,19 +45,19 @@ macro(set_definition name value)

set(${name} ${value} ${ARGN})
set(${name} ${value})
add_compile_definitions(${name}=${value})
add_compile_definitions(${name}="${value}")
message(STATUS "${name} = ${value}")
endmacro()

#[[
set_definition() only if value is defined as something other than ""
set_definition_string() only if value is defined as something other than ""
<name> : CMake variable and compile definition name to set
<value> : the value to set name to
[PARENT_SCOPE] : call set() with PARENT_SCOPE
#]]
macro(if_set_definition name value)
macro(if_set_definition_string name value)
if(NOT "" STREQUAL "${value}")
set_definition(${name} ${value} ${ARGN})
set_definition_string(${name} ${value} ${ARGN})
endif()
endmacro()

0 comments on commit 2f90670

Please sign in to comment.