Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a helper to remove a compile option from targets #23

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions everest-cmake-config-version.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
set(PACKAGE_VERSION 0.5.1)
set(PACKAGE_VERSION 0.6.0)

if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
elseif (PACKAGE_FIND_VERSION_MAJOR STREQUAL "0")
if (PACKAGE_FIND_VERSION_MINOR GREATER "5")
if (PACKAGE_FIND_VERSION_MINOR GREATER "6")
set(PACKAGE_VERSION_UNSUITABLE TRUE)
else ()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
Expand Down
1 change: 1 addition & 0 deletions everest-cmake-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ if (everest_cmake_FOUND)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/edm.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/helpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/python-package-helpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/python-virtualenv.cmake")

Expand Down
46 changes: 46 additions & 0 deletions helpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function(ev_remove_target_compile_option)
set(one_value_args
PREFIX # removes all compile options with this prefix
EXACT # removes an option only if it matches exactly
)

set(multi_value_args
TARGETS
)

cmake_parse_arguments(
"args"
""
"${one_value_args}"
"${multi_value_args}"
${ARGN}
)

foreach(target ${args_TARGETS})
set(COMPILE_OPTIONS_TO_REMOVE "")
get_target_property(TARGET_COMPILE_OPTIONS "${target}" COMPILE_OPTIONS)
# find applicable compile options for this target
foreach(compile_option ${TARGET_COMPILE_OPTIONS})
# collect compile options with a certain prefix
if(NOT "${args_PREFIX}" STREQUAL "")
string(FIND "${compile_option}" "${args_PREFIX}" POSITION)
if("${POSITION}" EQUAL "0")
list(APPEND COMPILE_OPTIONS_TO_REMOVE "${compile_option}")
endif()
endif()
# collect compile options with an exact match
if(NOT "${args_EXACT}" STREQUAL "")
if("${args_EXACT}" STREQUAL "${compile_option}")
message(STATUS "FOUND IT! ${compile_option} equals ${args_EXACT}")
list(APPEND COMPILE_OPTIONS_TO_REMOVE "${compile_option}")
endif()
endif()
endforeach()

# remove the collected compile options from the target
foreach(compile_option ${COMPILE_OPTIONS_TO_REMOVE})
list(REMOVE_ITEM TARGET_COMPILE_OPTIONS "${compile_option}")
endforeach()
set_target_properties("${target}" PROPERTIES COMPILE_OPTIONS "${TARGET_COMPILE_OPTIONS}")
endforeach()
endfunction()