diff --git a/CMakeLists.txt b/CMakeLists.txt index 81c928c..5a1584b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,17 +117,20 @@ function(asmjit_detect_sanitizers out) set(${out} "${_out_array}" PARENT_SCOPE) endfunction() -function(asmjit_add_target target target_type src deps cflags cflags_dbg cflags_rel) - if ("${target_type}" STREQUAL "EXECUTABLE") - add_executable(${target} ${src}) +function(asmjit_add_target target target_type) + set(single_val "") + set(multi_val SOURCES LIBRARIES CFLAGS CFLAGS_DBG CFLAGS_REL) + cmake_parse_arguments("X" "" "${single_val}" "${multi_val}" ${ARGN}) + + if ("${target_type}" MATCHES "^(EXECUTABLE|TEST)$") + add_executable(${target} ${X_SOURCES}) else() - add_library(${target} ${target_type} ${src}) + add_library(${target} ${target_type} ${X_SOURCES}) endif() - target_link_libraries(${target} PRIVATE ${deps}) + target_link_libraries(${target} PRIVATE ${X_LIBRARIES}) - # target_link_options was added in cmake 3.13, which doesn't work for us. - # target_link_options(${target} PRIVATE ${flags}) + # target_link_options was added in cmake v3.13, don't use it for now... foreach(link_flag ${ASMJIT_SANITIZE_LFLAGS}) set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " ${link_flag}") endforeach() @@ -139,7 +142,11 @@ function(asmjit_add_target target target_type src deps cflags cflags_dbg cflags_ endif() set_property(TARGET ${target} PROPERTY CXX_EXTENSIONS NO) set_property(TARGET ${target} PROPERTY CXX_VISIBILITY_PRESET hidden) - target_compile_options(${target} PRIVATE ${cflags} ${ASMJIT_SANITIZE_CFLAGS} $<$:${cflags_dbg}> $<$>:${cflags_rel}>) + target_compile_options(${target} PRIVATE ${X_CFLAGS} ${ASMJIT_SANITIZE_CFLAGS} $<$:${X_CFLAGS_DBG}> $<$>:${X_CFLAGS_REL}>) + + if ("${target_type}" STREQUAL "TEST") + add_test(NAME ${target} COMMAND ${target}) + endif() endfunction() # ============================================================================= @@ -391,55 +398,67 @@ message(" ASMJIT_PRIVATE_CFLAGS_REL=${ASMJIT_PRIVATE_CFLAGS_REL}") # ============================================================================= if (NOT ASMJIT_EMBED) - # Add 'asmjit' target. + # Add AsmJit target. asmjit_add_target(asmjit "${ASMJIT_TARGET_TYPE}" - "${ASMJIT_SRC}" - "${ASMJIT_DEPS}" - "${ASMJIT_PRIVATE_CFLAGS}" - "${ASMJIT_PRIVATE_CFLAGS_DBG}" - "${ASMJIT_PRIVATE_CFLAGS_REL}") + SOURCES ${ASMJIT_SRC} + LIBRARIES ${ASMJIT_DEPS} + CFLAGS ${ASMJIT_PRIVATE_CFLAGS} + CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} + CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) target_include_directories(asmjit BEFORE INTERFACE ${ASMJIT_INCLUDE_DIRS}) target_compile_options(asmjit INTERFACE ${ASMJIT_CFLAGS}) - - # Add AsmJit::AsmJit target (alias to asmjit). add_library(AsmJit::AsmJit ALIAS asmjit) - # Install 'asmjit' target (shared or static). - install(TARGETS asmjit RUNTIME DESTINATION "bin" - LIBRARY DESTINATION "lib${LIB_SUFFIX}" - ARCHIVE DESTINATION "lib${LIB_SUFFIX}") + # Add AsmJit install instructions (library and public headers). + if (NOT ASMJIT_NO_INSTALL) + install(TARGETS asmjit RUNTIME DESTINATION "bin" + LIBRARY DESTINATION "lib${LIB_SUFFIX}" + ARCHIVE DESTINATION "lib${LIB_SUFFIX}") + foreach(_src_file ${ASMJIT_SRC_LIST}) + if ("${_src_file}" MATCHES "\\.h$" AND NOT "${_src_file}" MATCHES "_p\\.h$") + get_filename_component(_src_dir ${_src_file} PATH) + install(FILES "${ASMJIT_DIR}/src/${_src_file}" DESTINATION "include/${_src_dir}") + endif() + endforeach() + endif() - # Install 'asmjit' header files (private headers are filtered out). - foreach(_src_file ${ASMJIT_SRC_LIST}) - if ("${_src_file}" MATCHES "\\.h$" AND NOT "${_src_file}" MATCHES "_p\\.h$") - get_filename_component(_src_dir ${_src_file} PATH) - install(FILES "${ASMJIT_DIR}/src/${_src_file}" DESTINATION "include/${_src_dir}") - endif() - endforeach() - - # Add 'asmjit' tests. + # Add AsmJit tests. if (ASMJIT_TEST) - set(ASMJIT_TEST_SRC test/asmjit_test_unit.cpp test/broken.cpp test/broken.h) + enable_testing() - asmjit_add_target(asmjit_test_unit EXECUTABLE - "${ASMJIT_SRC};${ASMJIT_TEST_SRC}" - "${ASMJIT_DEPS}" - "${ASMJIT_PRIVATE_CFLAGS}" - "${ASMJIT_PRIVATE_CFLAGS_DBG}" - "${ASMJIT_PRIVATE_CFLAGS_REL}") - target_compile_definitions(asmjit_test_unit PRIVATE ASMJIT_TEST ASMJIT_STATIC) + # Special target that always uses embedded AsmJit. + asmjit_add_target(asmjit_test_unit TEST + SOURCES ${ASMJIT_SRC} + test/asmjit_test_unit.cpp + test/broken.cpp + test/broken.h + LIBRARIES ${ASMJIT_DEPS} + CFLAGS ${ASMJIT_PRIVATE_CFLAGS} + -DASMJIT_TEST + -DASMJIT_STATIC + CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} + CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) + target_include_directories(asmjit_test_unit BEFORE PRIVATE ${ASMJIT_INCLUDE_DIRS}) - foreach(_target asmjit_bench_x86 - asmjit_test_opcode + foreach(_target asmjit_test_opcode asmjit_test_x86_asm asmjit_test_x86_cc asmjit_test_x86_sections) + asmjit_add_target(${_target} TEST + SOURCES test/${_target}.cpp + LIBRARIES AsmJit::AsmJit + CFLAGS ${ASMJIT_PRIVATE_CFLAGS} + CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} + CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) + endforeach() + + foreach(_target asmjit_bench_x86) asmjit_add_target(${_target} EXECUTABLE - "test/${_target}.cpp" - "${ASMJIT_LIBS}" - "${ASMJIT_PRIVATE_CFLAGS}" - "${ASMJIT_PRIVATE_CFLAGS_DBG}" - "${ASMJIT_PRIVATE_CFLAGS_REL}") + SOURCES test/${_target}.cpp + LIBRARIES AsmJit::AsmJit + CFLAGS ${ASMJIT_PRIVATE_CFLAGS} + CFLAGS_DBG ${ASMJIT_PRIVATE_CFLAGS_DBG} + CFLAGS_REL ${ASMJIT_PRIVATE_CFLAGS_REL}) endforeach() endif() endif() diff --git a/src/asmjit/core/api-build_p.h b/src/asmjit/core/api-build_p.h index f1fcd50..2c7ef97 100644 --- a/src/asmjit/core/api-build_p.h +++ b/src/asmjit/core/api-build_p.h @@ -22,4 +22,14 @@ #include "./api-config.h" +// Make sure '#ifdef'ed unit tests are properly highlighted in IDE. +#if !defined(ASMJIT_TEST) && defined(__INTELLISENSE__) + #define ASMJIT_TEST +#endif + +// Include a unit testing package if this is a `asmjit_test_unit` build. +#if defined(ASMJIT_TEST) + #include "../../../test/broken.h" +#endif + #endif // _ASMJIT_CORE_API_BUILD_P_H diff --git a/src/asmjit/core/api-config.h b/src/asmjit/core/api-config.h index 8b4a0d7..556f510 100644 --- a/src/asmjit/core/api-config.h +++ b/src/asmjit/core/api-config.h @@ -537,18 +537,4 @@ #undef ASMJIT_CXX_MSC #undef ASMJIT_CXX_MAKE_VER -// ============================================================================ -// [asmjit::Build - Globals - Unit Testing Boilerplate] -// ============================================================================ - -// IDE: Make sure '#ifdef'ed unit tests are properly highlighted. -#if defined(__INTELLISENSE__) && !defined(ASMJIT_TEST) - #define ASMJIT_TEST -#endif - -// IDE: Make sure '#ifdef'ed unit tests are not disabled by IDE. -#if defined(ASMJIT_TEST) - #include "../../../test/broken.h" -#endif - #endif // _ASMJIT_CORE_API_CONFIG_H diff --git a/test/asmjit.h b/test/asmjit.h deleted file mode 100644 index 36a7588..0000000 --- a/test/asmjit.h +++ /dev/null @@ -1 +0,0 @@ -#include "../src/asmjit/asmjit.h" diff --git a/test/asmjit_bench_x86.cpp b/test/asmjit_bench_x86.cpp index f3a0e7e..3c95b6c 100644 --- a/test/asmjit_bench_x86.cpp +++ b/test/asmjit_bench_x86.cpp @@ -4,10 +4,10 @@ // [License] // Zlib - See LICENSE.md file in the package. +#include #include #include -#include "./asmjit.h" #include "./asmjit_test_misc.h" #include "./asmjit_test_opcode.h" diff --git a/test/asmjit_test_misc.h b/test/asmjit_test_misc.h index 5c6824d..5da49f1 100644 --- a/test/asmjit_test_misc.h +++ b/test/asmjit_test_misc.h @@ -7,7 +7,7 @@ #ifndef _ASMJIT_TEST_MISC_H #define _ASMJIT_TEST_MISC_H -#include "./asmjit.h" +#include namespace asmtest { diff --git a/test/asmjit_test_opcode.cpp b/test/asmjit_test_opcode.cpp index 2de0267..8a1ad5f 100644 --- a/test/asmjit_test_opcode.cpp +++ b/test/asmjit_test_opcode.cpp @@ -8,10 +8,10 @@ // disassembled in your IDE or by your favorite disassembler. Instructions // are grouped by category and then sorted alphabetically. +#include #include #include -#include "./asmjit.h" #include "./asmjit_test_opcode.h" using namespace asmjit; diff --git a/test/asmjit_test_opcode.h b/test/asmjit_test_opcode.h index c1e89af..93741b7 100644 --- a/test/asmjit_test_opcode.h +++ b/test/asmjit_test_opcode.h @@ -7,7 +7,7 @@ #ifndef _ASMJIT_TEST_OPCODE_H #define _ASMJIT_TEST_OPCODE_H -#include "./asmjit.h" +#include namespace asmtest { diff --git a/test/asmjit_test_unit.cpp b/test/asmjit_test_unit.cpp index 4f6b82e..13b7665 100644 --- a/test/asmjit_test_unit.cpp +++ b/test/asmjit_test_unit.cpp @@ -4,7 +4,8 @@ // [License] // Zlib - See LICENSE.md file in the package. -#include "./asmjit.h" +#include +#include "./broken.h" using namespace asmjit; diff --git a/test/asmjit_test_x86_asm.cpp b/test/asmjit_test_x86_asm.cpp index 3f040c8..7108237 100644 --- a/test/asmjit_test_x86_asm.cpp +++ b/test/asmjit_test_x86_asm.cpp @@ -4,12 +4,11 @@ // [License] // Zlib - See LICENSE.md file in the package. +#include #include #include #include -#include "./asmjit.h" - using namespace asmjit; // Signature of the generated function. diff --git a/test/asmjit_test_x86_cc.cpp b/test/asmjit_test_x86_cc.cpp index 6617c7d..31d02e6 100644 --- a/test/asmjit_test_x86_cc.cpp +++ b/test/asmjit_test_x86_cc.cpp @@ -4,12 +4,12 @@ // [License] // Zlib - See LICENSE.md file in the package. +#include #include #include #include #include -#include "./asmjit.h" #include "./asmjit_test_misc.h" #ifdef _MSC_VER diff --git a/test/asmjit_test_x86_sections.cpp b/test/asmjit_test_x86_sections.cpp index e94742b..7cf74b5 100644 --- a/test/asmjit_test_x86_sections.cpp +++ b/test/asmjit_test_x86_sections.cpp @@ -1,4 +1,4 @@ -// [AsmJit] +// [AsmJit]you want // Machine Code Generation for C++. // // [License] @@ -13,14 +13,13 @@ // - Tell the CodeHolder to resolve unresolved links and check whether // all links were resolved. // - Relocate the code -// - Copy the code to the location you want. +// - Copy the code to the destination address. +#include #include #include #include -#include "./asmjit.h" - using namespace asmjit; // The generated function is very simple, it only accesses the built-in data