Skip to content

Commit

Permalink
cmake: set PROJECT_EC_FLAGS to be GLOBAL property
Browse files Browse the repository at this point in the history
Declare PROJECT_EC_FLAGS to be a global property
to simplify code for target_compile_options.

Signed-off-by: Sergei Korneichuk <[email protected]>
  • Loading branch information
kernelchuk authored and arnopo committed Oct 3, 2022
1 parent 9a814da commit d077e28
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ option (WITH_DEFAULT_LOGGER "Build with default logger" ON)

option (WITH_DOC "Build with documentation" ON)

set (PROJECT_EC_FLAGS "-Wall -Werror -Wextra" CACHE STRING "")
set (GLOBAL PROPERTY "PROJECT_EC_FLAGS" "-Wall -Werror -Wextra" CACHE STRING "")
# vim: expandtab:ts=2:sw=2:smartindent
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_throughput_demod.c)

get_property (_linker_options GLOBAL PROPERTY TEST_LINKER_OPTIONS)
add_executable (${_app0}.elf ${_src0})
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (${_app0}.elf PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
get_property (_ec_flgs GLOBAL PROPERTY "PROJECT_EC_FLAGS")
target_compile_options (${_app0}.elf PUBLIC ${_ec_flgs})
target_link_libraries(${_app0}.elf -Wl,-Map=${_app0}.map -Wl,--gc-sections -T\"${_linker_script}\" -Wl,--start-group ${_deps} -Wl,--end-group)
install (TARGETS ${_app0}.elf RUNTIME DESTINATION bin)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ list(APPEND _src0 ${CMAKE_CURRENT_SOURCE_DIR}/shmem_throughput_demod.c)

get_property (_linker_options GLOBAL PROPERTY TEST_LINKER_OPTIONS)
add_executable (${_app0}.elf ${_src0})
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (${_app0}.elf PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
get_property (_ec_flgs GLOBAL PROPERTY "PROJECT_EC_FLAGS")
target_compile_options (${_app0}.elf PUBLIC ${_ec_flgs})
target_link_libraries(${_app0}.elf -Wl,-Map=${_app0}.map -Wl,--gc-sections -T\"${_linker_script}\" -Wl,--start-group ${_deps} -Wl,--end-group)
install (TARGETS ${_app0}.elf RUNTIME DESTINATION bin)

Expand Down
11 changes: 3 additions & 8 deletions examples/system/linux/zynqmp/zynqmp_amp_demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ link_directories (${_list})
collector_list (_deps PROJECT_LIB_DEPS)

set (_src_common ${CMAKE_CURRENT_SOURCE_DIR}/sys_init.c)
get_property (_ec_flgs GLOBAL PROPERTY "PROJECT_EC_FLAGS")
foreach (_app libmetal_amp_demo libmetal_amp_demod)
set (_src ${CMAKE_CURRENT_SOURCE_DIR}/${_app}.c)
list(APPEND _src ${_src_common})
Expand All @@ -18,10 +19,7 @@ foreach (_app libmetal_amp_demo libmetal_amp_demod)
list(APPEND _src ${CMAKE_CURRENT_SOURCE_DIR}/shmem_throughput_demo.c)
if (WITH_SHARED_LIB)
add_executable (${_app}-share ${_src})
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (${_app}-share PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
target_compile_options (${_app}-share PUBLIC ${_ec_flgs})
target_link_libraries (${_app}-share ${PROJECT_NAME}-shared ${_deps})
install (TARGETS ${_app}-share RUNTIME DESTINATION bin)
add_dependencies (${_app}-share ${PROJECT_NAME}-shared)
Expand All @@ -30,10 +28,7 @@ foreach (_app libmetal_amp_demo libmetal_amp_demod)
if (WITH_STATIC_LIB)
if (${PROJECT_SYSTEM} STREQUAL "linux")
add_executable (${_app}-static ${_src})
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (${_app}-static PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
target_compile_options (${_app}-static PUBLIC ${_ec_flgs})
target_link_libraries (${_app}-static ${PROJECT_NAME}-static ${_deps})
install (TARGETS ${_app}-static RUNTIME DESTINATION bin)
endif (${PROJECT_SYSTEM} STREQUAL "linux")
Expand Down
12 changes: 4 additions & 8 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ if (WITH_DEFAULT_LOGGER)
add_definitions (-DDEFAULT_LOGGER_ON)
endif (WITH_DEFAULT_LOGGER)

get_property (_ec_flgs GLOBAL PROPERTY "PROJECT_EC_FLAGS")

if (WITH_ZEPHYR)
zephyr_library_named(metal)
add_dependencies(metal offsets_h)
Expand All @@ -77,10 +79,7 @@ else (WITH_ZEPHYR)
add_library (${_lib} SHARED ${_sources})
target_link_libraries (${_lib} ${_deps})
install (TARGETS ${_lib} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (${_lib} PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
target_compile_options (${_lib} PUBLIC ${_ec_flgs})
set_target_properties (${_lib} PROPERTIES
OUTPUT_NAME "${PROJECT_NAME}"
VERSION "${PROJECT_VERSION}"
Expand All @@ -93,10 +92,7 @@ else (WITH_ZEPHYR)
set (_lib ${PROJECT_NAME}-static)
add_library (${_lib} STATIC ${_sources})
install (TARGETS ${_lib} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (${_lib} PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
target_compile_options (${_lib} PUBLIC ${_ec_flgs})
set_target_properties (${_lib} PROPERTIES
OUTPUT_NAME "${PROJECT_NAME}"
)
Expand Down
12 changes: 4 additions & 8 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ collector_list (_deps PROJECT_LIB_DEPS)

collector_list (_srcs PROJECT_LIB_TESTS)

get_property (_ec_flgs GLOBAL PROPERTY "PROJECT_EC_FLAGS")

if (WITH_ZEPHYR)
set (_tfiles "")
foreach (f ${_srcs})
Expand All @@ -38,10 +40,7 @@ else (WITH_ZEPHYR)
add_executable (test-${_lib} ${_srcs})
target_link_libraries (test-${_lib} ${_deps} ${_lib})
install (TARGETS test-${_lib} RUNTIME DESTINATION bin)
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (test-${_lib} PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
target_compile_options (test-${_lib} PUBLIC ${_ec_flgs})
add_dependencies (test-${_lib} ${PROJECT_NAME}-shared)
if (WITH_TESTS_EXEC)
add_test (test-${_lib} test-${_lib})
Expand All @@ -54,10 +53,7 @@ else (WITH_ZEPHYR)
add_executable (test-${_lib} ${_srcs})
target_link_libraries (test-${_lib} -Wl,-Map=test-${_lib}.map ${_linker_options} -Wl,--start-group ${_lib} ${_deps} -Wl,--end-group)
install (TARGETS test-${_lib} RUNTIME DESTINATION bin)
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (test-${_lib} PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
target_compile_options (test-${_lib} PUBLIC ${_ec_flgs})
add_dependencies (test-${_lib} ${PROJECT_NAME}-static)
if (WITH_TESTS_EXEC)
add_test (test-${_lib} test-${_lib})
Expand Down

0 comments on commit d077e28

Please sign in to comment.