Skip to content

Commit

Permalink
Include Path / Library Fix (Bareflank#581)
Browse files Browse the repository at this point in the history
This patch fixes two specific issues with extensions:
- The init_project macro was including <path>/../include which it
shouldn't be because we don't know how an extension will be setup, and
this could accidentially include unintended files.
- The add_vmm_exectuable provided to way to link shared and static
libraries at the same time, and as a result, was cumbersome to use.

Signed-off-by: “rianquinn” <“rianquinn@gmail.com”>
  • Loading branch information
rianquinn authored and JaredWright committed Mar 2, 2018
1 parent 389dd0c commit f66a919
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
4 changes: 3 additions & 1 deletion bfdummy/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ cmake_minimum_required(VERSION 3.6)
project(bfdummy C CXX)

include(${SOURCE_CMAKE_DIR}/project.cmake)
init_project()
init_project(
INCLUDES ${CMAKE_CURRENT_LIST_DIR}/../include
)

add_subdirectory(libs)
4 changes: 2 additions & 2 deletions bfdummy/src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ init_project(
)

list(APPEND LIBRARIES
${CMAKE_INSTALL_PREFIX}/lib/libdummy_lib1_shared.so
${CMAKE_INSTALL_PREFIX}/lib/libdummy_lib2_shared.so
dummy_lib1
dummy_lib2
)

add_vmm_executable(dummy_main
Expand Down
1 change: 1 addition & 0 deletions bfm/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ list(APPEND BFM_CXX_FLAGS

include(${SOURCE_CMAKE_DIR}/project.cmake)
init_project(
INCLUDES ${CMAKE_CURRENT_LIST_DIR}/../include
CXX_FLAGS ${BFM_CXX_FLAGS}
)

Expand Down
1 change: 1 addition & 0 deletions bfunwind/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ project(bfunwind C CXX)

include(${SOURCE_CMAKE_DIR}/project.cmake)
init_project(
INCLUDES ${CMAKE_CURRENT_LIST_DIR}/../include
TIDY_EXCLUSIONS -cppcoreguidelines-pro*
)

Expand Down
56 changes: 32 additions & 24 deletions scripts/cmake/macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -666,23 +666,23 @@ endfunction(right_justify)

# Private
#
macro(add_custom_target_category TEXT)
function(add_custom_target_category TEXT)
if(NOT WIN32)
add_custom_command(
TARGET info
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color " "
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green "${TEXT}:"
)
endif()
endmacro(add_custom_target_category)
endfunction(add_custom_target_category)

# ------------------------------------------------------------------------------
# add_custom_target_info
# ------------------------------------------------------------------------------

# Private
#
macro(add_custom_target_info)
function(add_custom_target_info)
if(NOT WIN32)
set(oneVal TARGET COMMENT)
cmake_parse_arguments(ARG "" "${oneVal}" "" ${ARGN})
Expand All @@ -705,7 +705,7 @@ macro(add_custom_target_info)
)
endif()
endif()
endmacro(add_custom_target_info)
endfunction(add_custom_target_info)

# ------------------------------------------------------------------------------
# add_subproject
Expand Down Expand Up @@ -957,7 +957,6 @@ macro(init_project)
${SOURCE_BFVMM_DIR}/include
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/../include
)

if(NOT PREFIX STREQUAL "vmm")
Expand All @@ -982,11 +981,11 @@ endmacro(init_project)

# Private
#
macro(validate_build)
function(validate_build)
if(BUILD_VALIDATOR_ERROR)
message(FATAL_ERROR "Build validation failed")
endif()
endmacro(validate_build)
endfunction(validate_build)

# Invalidate Config
#
Expand Down Expand Up @@ -1016,7 +1015,7 @@ endmacro(invalid_config)
# @param DEFINES The definitions to add to the library
# @param DEPENDS The dependency for the library. "_shared" is added for you
#
macro(add_shared_library NAME)
function(add_shared_library NAME)
set(options ALWAYS)
set(multiVal SOURCES DEFINES DEPENDS)
cmake_parse_arguments(ARG "${options}" "" "${multiVal}" ${ARGN})
Expand All @@ -1037,7 +1036,7 @@ macro(add_shared_library NAME)
target_link_libraries(${NAME}_shared ${DEPENDS})
install(TARGETS ${NAME}_shared DESTINATION lib)
endif()
endmacro(add_shared_library)
endfunction(add_shared_library)

# Add Static Library
#
Expand All @@ -1049,7 +1048,7 @@ endmacro(add_shared_library)
# @param SOURCES The source files for the library
# @param DEFINES The definitions to add to the library
#
macro(add_static_library NAME)
function(add_static_library NAME)
set(options ALWAYS)
set(multiVal SOURCES DEFINES)
cmake_parse_arguments(ARG "${options}" "" "${multiVal}" ${ARGN})
Expand All @@ -1064,7 +1063,7 @@ macro(add_static_library NAME)
target_compile_definitions(${NAME}_static PRIVATE ${ARG_DEFINES})
install(TARGETS ${NAME}_static DESTINATION lib)
endif()
endmacro(add_static_library)
endfunction(add_static_library)

# ------------------------------------------------------------------------------
# add_vmm
Expand All @@ -1082,7 +1081,7 @@ endmacro(add_static_library)
# a null.cpp file will be compiled for you.
# @param DEFINES Additional definitions to add to the executable
#
macro(add_vmm_executable NAME)
function(add_vmm_executable NAME)
set(options NOVMMLIBS)
set(multiVal LIBRARIES SOURCES DEFINES)
cmake_parse_arguments(ARG "${options}" "" "${multiVal}" ${ARGN})
Expand All @@ -1100,8 +1099,13 @@ macro(add_vmm_executable NAME)
add_executable(${NAME}_shared ${ARG_SOURCES})
target_compile_definitions(${NAME}_shared PRIVATE ${ARG_DEFINES})

set(LIBRARIES "")
foreach(d ${ARG_LIBRARIES})
list(APPEND LIBRARIES "${CMAKE_INSTALL_PREFIX}/lib/lib${d}_shared.so")
endforeach(d)

if(NOT ARG_NOVMMLIBS)
list(APPEND ARG_LIBRARIES
list(APPEND LIBRARIES
--whole-archive ${CMAKE_INSTALL_PREFIX}/lib/libbfvmm_entry_static.a --no-whole-archive
${CMAKE_INSTALL_PREFIX}/lib/libbfvmm_vcpu_shared.so
${CMAKE_INSTALL_PREFIX}/lib/libbfvmm_hve_shared.so
Expand All @@ -1111,7 +1115,7 @@ macro(add_vmm_executable NAME)
)
endif()

list(APPEND ARG_LIBRARIES
list(APPEND LIBRARIES
${CMAKE_INSTALL_PREFIX}/lib/libc++.so
${CMAKE_INSTALL_PREFIX}/lib/libc++abi.so
${CMAKE_INSTALL_PREFIX}/lib/libbfpthread_shared.so
Expand All @@ -1121,16 +1125,21 @@ macro(add_vmm_executable NAME)
${CMAKE_INSTALL_PREFIX}/lib/libbfsyscall_shared.so
)

target_link_libraries(${NAME}_shared ${ARG_LIBRARIES})
target_link_libraries(${NAME}_shared ${LIBRARIES})
install(TARGETS ${NAME}_shared DESTINATION bin)
endif()

if(BUILD_STATIC_LIBS)
add_executable(${NAME}_static ${ARG_SOURCES})
target_compile_definitions(${NAME}_static PRIVATE ${ARG_DEFINES})

set(LIBRARIES "")
foreach(d ${ARG_LIBRARIES})
list(APPEND LIBRARIES "${CMAKE_INSTALL_PREFIX}/lib/lib${d}_static.a")
endforeach(d)

if(NOT ARG_NOVMMLIBS)
list(APPEND ARG_LIBRARIES
list(APPEND LIBRARIES
--whole-archive ${CMAKE_INSTALL_PREFIX}/lib/libbfvmm_entry_static.a --no-whole-archive
${CMAKE_INSTALL_PREFIX}/lib/libbfvmm_vcpu_static.a
${CMAKE_INSTALL_PREFIX}/lib/libbfvmm_hve_static.a
Expand All @@ -1140,7 +1149,7 @@ macro(add_vmm_executable NAME)
)
endif()

list(APPEND ARG_LIBRARIES
list(APPEND LIBRARIES
${CMAKE_INSTALL_PREFIX}/lib/libc++.a
${CMAKE_INSTALL_PREFIX}/lib/libc++abi.a
${CMAKE_INSTALL_PREFIX}/lib/libbfpthread_static.a
Expand All @@ -1150,11 +1159,10 @@ macro(add_vmm_executable NAME)
${CMAKE_INSTALL_PREFIX}/lib/libbfsyscall_static.a
)


target_link_libraries(${NAME}_static ${ARG_LIBRARIES})
target_link_libraries(${NAME}_static ${LIBRARIES})
install(TARGETS ${NAME}_static DESTINATION bin)
endif()
endmacro(add_vmm_executable)
endfunction(add_vmm_executable)

# ------------------------------------------------------------------------------
# set_bfm_vmm
Expand Down Expand Up @@ -1203,7 +1211,7 @@ endmacro(set_bfm_vmm)
# a directory. Nomrally FILENAME should still match the filename being
# used.
#
macro(do_test FILENAME)
function(do_test FILENAME)
set(multiVal DEFINES DEPENDS SOURCES)
cmake_parse_arguments(ARG "" "" "${multiVal}" ${ARGN})

Expand All @@ -1225,7 +1233,7 @@ macro(do_test FILENAME)
if(CYGWIN OR WIN32)
target_link_libraries(test_${NAME} setupapi)
endif()
endmacro(do_test)
endfunction(do_test)

# ------------------------------------------------------------------------------
# print_xxx
Expand All @@ -1245,7 +1253,7 @@ endfunction(print_banner)

# Private
#
macro(print_usage)
function(print_usage)
message(STATUS "${Green} Bareflank is ready to build, usage:${ColorReset}")
message(STATUS "${Yellow} ${BUILD_COMMAND}${ColorReset}")
message(STATUS "")
Expand All @@ -1260,4 +1268,4 @@ macro(print_usage)
message(STATUS "${Yellow} cmake --build . --target clean-all${ColorReset}")
message(STATUS "")
endif()
endmacro(print_usage)
endfunction(print_usage)

0 comments on commit f66a919

Please sign in to comment.