Skip to content

Commit

Permalink
cmake: use OBJECT libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
GBuella committed Aug 28, 2017
1 parent bf64cfc commit 4fab456
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
23 changes: 15 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# can use the internal interface of the libraries (linking
# with syscall_intercept_base instead of the actual lib ), without
# the library trying to hotpatch libc every time.
add_library(syscall_intercept_base_c STATIC ${SOURCES_C})
add_library(syscall_intercept_base_asm STATIC ${SOURCES_ASM})
add_library(syscall_intercept_base_c OBJECT ${SOURCES_C})
add_library(syscall_intercept_base_asm OBJECT ${SOURCES_ASM})
add_library(syscall_intercept_base_entry OBJECT src/entry.c)

if(HAS_NOUNUSEDARG)
target_compile_options(syscall_intercept_base_asm BEFORE
Expand All @@ -94,15 +95,21 @@ endif()
set_property(TARGET syscall_intercept_base_c
APPEND PROPERTY COMPILE_FLAGS ${capstone_CFLAGS})

target_link_libraries(syscall_intercept_base_c
${CMAKE_DL_LIBS} ${capstone_LIBRARIES})

add_library(syscall_intercept_shared SHARED src/entry.c)
add_library(syscall_intercept_shared SHARED
$<TARGET_OBJECTS:syscall_intercept_base_c>
$<TARGET_OBJECTS:syscall_intercept_base_asm>
$<TARGET_OBJECTS:syscall_intercept_base_entry>)
add_library(syscall_intercept_static STATIC
$<TARGET_OBJECTS:syscall_intercept_base_c>
$<TARGET_OBJECTS:syscall_intercept_base_asm>
$<TARGET_OBJECTS:syscall_intercept_base_entry>)

target_link_libraries(syscall_intercept_shared
syscall_intercept_base_c syscall_intercept_base_asm)
add_library(syscall_intercept_static STATIC src/entry.c)
PRIVATE ${CMAKE_DL_LIBS} ${capstone_LIBRARIES})

target_link_libraries(syscall_intercept_static
syscall_intercept_base_c syscall_intercept_base_asm)
INTERFACE ${CMAKE_DL_LIBS} ${capstone_LIBRARIES})

set_target_properties(syscall_intercept_shared
PROPERTIES VERSION ${SYSCALL_INTERCEPT_VERSION}
Expand Down
8 changes: 5 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ include_directories(${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/test)

set(CMAKE_ASM_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY})

add_executable(asm_pattern asm_pattern.c)
add_executable(asm_pattern asm_pattern.c
$<TARGET_OBJECTS:syscall_intercept_base_c>
$<TARGET_OBJECTS:syscall_intercept_base_asm>)

target_link_libraries(asm_pattern
PRIVATE ${CMAKE_DL_LIBS} ${capstone_LDFLAGS}
syscall_intercept_base_c syscall_intercept_base_asm)
PRIVATE ${CMAKE_DL_LIBS} ${capstone_LDFLAGS})

set(asm_patterns
nosyscall
Expand Down

0 comments on commit 4fab456

Please sign in to comment.