-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
111 lines (82 loc) · 4.96 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
cmake_minimum_required(VERSION 3.0)
project(libload LANGUAGES CXX VERSION 1.0.0)
include(CPack)
include(CTest)
include(GNUInstallDirs)
option(LIBLOAD_ENABLE_ARCH_X86_64 "Enable x86_64 support" ON)
option(LIBLOAD_ENABLE_FORMAT_PE32 "Enable module support for the PE format" OFF)
option(LIBLOAD_ENABLE_FORMAT_PE64 "Enable module support for the PE+ format" OFF)
configure_file(src/config.hpp.cmake src/config.hpp)
find_package(Boost REQUIRED COMPONENTS iostreams unit_test_framework)
add_library(load src/code_chunk.cpp
src/mapped_file.cpp
src/load_module.cpp
src/module_provider.cpp)
if(WIN32)
target_sources(load PRIVATE src/platform/windows/current_process.cpp
src/platform/windows/local_process.cpp
src/platform/windows/system_module.cpp)
endif()
add_library(LibLoad::load ALIAS load)
target_compile_features(load PUBLIC cxx_std_17)
target_link_libraries(load PUBLIC ${Boost_IOSTREAMS_LIBRARY})
add_library(loadhlp INTERFACE)
get_filename_component(loadhlp_root_dir ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE)
if (${LIBLOAD_ENABLE_ARCH_X86_64})
target_sources(load PRIVATE src/arch/x64/code_generator.cpp)
endif()
if(${LIBLOAD_ENABLE_FORMAT_PE32} OR ${LIBLOAD_ENABLE_FORMAT_PE64})
find_package(PEPlus REQUIRED)
target_sources(load PRIVATE src/pe/load_module.cpp)
target_link_libraries(load PRIVATE PEPlus::peplus)
endif()
install(TARGETS load EXPORT load_targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT load_targets FILE LibLoadConfig.cmake NAMESPACE LibLoad::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
export(EXPORT load_targets FILE LibLoadTargets.cmake NAMESPACE LibLoad::)
include(GenerateExportHeader)
generate_export_header(load EXPORT_FILE_NAME include/load/export.hpp)
configure_file(include/load/version.hpp.cmake include/load/version.hpp)
target_include_directories(load PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include> ${Boost_INCLUDE_DIRS})
target_include_directories(loadhlp INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include)
install(DIRECTORY include/load DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN *.hpp)
install(FILES ${CMAKE_BINARY_DIR}/include/load/version.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/load)
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/LibLoadConfig.cmake LibLoadConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
write_basic_package_version_file(LibLoadConfigVersion.cmake VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES ${CMAKE_BINARY_DIR}/LibLoadTargets.cmake
${CMAKE_BINARY_DIR}/LibLoadConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libload)
configure_file(include/load/version.hpp.cmake include/load/version.hpp)
install(DIRECTORY include/load DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN *.hpp)
install(FILES ${CMAKE_BINARY_DIR}/include/load/version.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/load)
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/LibLoadConfig.cmake LibLoadConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
write_basic_package_version_file(LibLoadConfigVersion.cmake VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES ${CMAKE_BINARY_DIR}/LibLoadTargets.cmake
${CMAKE_BINARY_DIR}/LibLoadConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libload)
add_library(sample_module MODULE test/sample_module.cpp)
set_target_properties(sample_module PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON
SUFFIX .llm)
add_executable(test_loadmodule test/test_loadmodule.cpp)
target_include_directories(test_loadmodule PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(test_loadmodule LibLoad::load ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_test(NAME LoadModule COMMAND "$<TARGET_FILE:test_loadmodule>"
WORKING_DIRECTORY "$<TARGET_FILE_DIR:sample_module>")
add_executable(test_codegenerator test/test_codegenerator.cpp)
target_include_directories(test_codegenerator PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(test_codegenerator LibLoad::load ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_test(NAME CodeGenerator COMMAND "$<TARGET_FILE:test_codegenerator>")