Skip to content

Commit

Permalink
Add windows DLL support
Browse files Browse the repository at this point in the history
(with AVX2 flag removed currently)
  • Loading branch information
wurp authored and fatchanghao committed Aug 13, 2019
1 parent 4959283 commit e395cd3
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 16 deletions.
18 changes: 8 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ else()
endif()

if(CMAKE_BUILD_TYPE MATCHES RELEASE|RELWITHDEBINFO|MINSIZEREL)
message(STATUS "using release build")
set(RELEASE_BUILD TRUE)
else()
set(RELEASE_BUILD FALSE)
Expand Down Expand Up @@ -109,11 +110,9 @@ option(BUILD_SHARED_LIBS "Build shared libs instead of static" OFF)
option(BUILD_STATIC_AND_SHARED "Build shared libs as well as static" OFF)

if (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS)
if (WIN32)
message(FATAL_ERROR "Windows DLLs currently not supported")
else()
message(STATUS "Building shared libraries")
endif()
else()
message(STATUS "Building static libraries")
endif()

if (NOT BUILD_SHARED_LIBS)
Expand Down Expand Up @@ -151,9 +150,6 @@ if(MSVC OR MSVC_IDE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O3 /Qstd=c99 /Qrestrict /wd4267 /Qdiag-disable:remark")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Qstd=c++11 /Qrestrict /QxHost /wd4267 /wd4800 /Qdiag-disable:remark -DBOOST_DETAIL_NO_CONTAINER_FWD -D_SCL_SECURE_NO_WARNINGS")
else()
# todo: change these as required
set(ARCH_C_FLAGS "/arch:AVX2")
set(ARCH_CXX_FLAGS "/arch:AVX2")
set(MSVC_WARNS "/wd4101 /wd4146 /wd4172 /wd4200 /wd4244 /wd4267 /wd4307 /wd4334 /wd4805 /wd4996 -D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /O2 ${MSVC_WARNS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 ${MSVC_WARNS} /wd4800 -DBOOST_DETAIL_NO_CONTAINER_FWD")
Expand Down Expand Up @@ -1298,12 +1294,14 @@ endif()
if (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS)
if (NOT FAT_RUNTIME)
add_library(hs_runtime_shared SHARED src/hs_version.c
src/hs_valid_platform.c $<TARGET_OBJECTS:hs_exec_shared>)
src/hs_valid_platform.c $<TARGET_OBJECTS:hs_exec_shared>
hs_runtime.def)
else()
add_library(hs_runtime_shared SHARED src/hs_version.c
src/hs_valid_platform.c
$<TARGET_OBJECTS:hs_exec_common_shared>
${RUNTIME_SHLIBS})
${RUNTIME_SHLIBS}
hs_runtime.def)
endif()
set_target_properties(hs_runtime_shared PROPERTIES
VERSION ${LIB_VERSION}
Expand Down Expand Up @@ -1349,7 +1347,7 @@ if (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS)
${RUNTIME_SHLIBS})
endif ()

add_library(hs_shared SHARED ${hs_shared_SRCS})
add_library(hs_shared SHARED ${hs_shared_SRCS} hs.def)

add_dependencies(hs_shared ragel_Parser)
set_target_properties(hs_shared PROPERTIES
Expand Down
43 changes: 43 additions & 0 deletions hs.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
; Hyperscan DLL export definitions

LIBRARY hs

EXPORTS
hs_alloc_scratch
hs_clone_scratch
hs_close_stream
hs_compile
hs_compile_ext_multi
hs_compile_multi
hs_compress_stream
hs_copy_stream
hs_database_info
hs_database_size
hs_deserialize_database
hs_deserialize_database_at
hs_expand_stream
hs_expression_ext_info
hs_expression_info
hs_free_compile_error
hs_free_database
hs_free_scratch
hs_open_stream
hs_populate_platform
hs_reset_and_copy_stream
hs_reset_and_expand_stream
hs_reset_stream
hs_scan
hs_scan_stream
hs_scan_vector
hs_scratch_size
hs_serialize_database
hs_serialized_database_info
hs_serialized_database_size
hs_set_allocator
hs_set_database_allocator
hs_set_misc_allocator
hs_set_scratch_allocator
hs_set_stream_allocator
hs_stream_size
hs_valid_platform
hs_version
36 changes: 36 additions & 0 deletions hs_runtime.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; Hyperscan DLL export definitions

LIBRARY hs_runtime

EXPORTS
hs_alloc_scratch
hs_clone_scratch
hs_close_stream
hs_compress_stream
hs_copy_stream
hs_database_info
hs_database_size
hs_deserialize_database
hs_deserialize_database_at
hs_expand_stream
hs_free_database
hs_free_scratch
hs_open_stream
hs_reset_and_copy_stream
hs_reset_and_expand_stream
hs_reset_stream
hs_scan
hs_scan_stream
hs_scan_vector
hs_scratch_size
hs_serialize_database
hs_serialized_database_info
hs_serialized_database_size
hs_set_allocator
hs_set_database_allocator
hs_set_misc_allocator
hs_set_scratch_allocator
hs_set_stream_allocator
hs_stream_size
hs_valid_platform
hs_version
10 changes: 6 additions & 4 deletions tools/hsbench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ if (BUILD_CHIMERA)
engine_pcre.cpp
engine_pcre.h
)
endif()

add_executable(hsbench ${hsbench_SOURCES})
if (BUILD_CHIMERA)
add_executable(hsbench ${hsbench_SOURCES})
include_directories(${PCRE_INCLUDE_DIRS})
if(NOT WIN32)
target_link_libraries(hsbench hs chimera ${PCRE_LDFLAGS} databaseutil
Expand All @@ -69,6 +66,11 @@ if (BUILD_CHIMERA)
expressionutil ${SQLITE3_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT})
endif()
else()
if(WIN32 AND (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS))
add_executable(hsbench ${hsbench_SOURCES} $<TARGET_OBJECTS:hs_compile_shared> $<TARGET_OBJECTS:hs_exec_shared>)
else()
add_executable(hsbench ${hsbench_SOURCES})
endif()
target_link_libraries(hsbench hs databaseutil expressionutil
${SQLITE3_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT})
endif()
6 changes: 5 additions & 1 deletion tools/hscheck/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ if (BUILD_CHIMERA)
target_link_libraries(hscheck hs chimera pcre expressionutil)
endif()
else()
add_executable(hscheck ${hscheck_SOURCES})
if(WIN32 AND (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS))
add_executable(hscheck ${hscheck_SOURCES} $<TARGET_OBJECTS:hs_compile_shared> $<TARGET_OBJECTS:hs_exec_shared>)
else()
add_executable(hscheck ${hscheck_SOURCES})
endif()
if(NOT WIN32)
target_link_libraries(hscheck hs expressionutil pthread)
else()
Expand Down
6 changes: 5 additions & 1 deletion tools/hsdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ include_directories(${PROJECT_SOURCE_DIR}/util)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}")

add_executable(hsdump main.cpp)
if(WIN32 AND (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS))
add_executable(hsdump main.cpp $<TARGET_OBJECTS:hs_compile_shared> $<TARGET_OBJECTS:hs_exec_shared>)
else()
add_executable(hsdump main.cpp)
endif()
target_link_libraries(hsdump hs expressionutil crosscompileutil)

4 changes: 4 additions & 0 deletions unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ set(unit_internal_SOURCES
internal/main.cpp
)

if(WIN32 AND (BUILD_STATIC_AND_SHARED OR BUILD_SHARED_LIBS))
add_executable(unit-internal ${unit_internal_SOURCES} $<TARGET_OBJECTS:hs_compile_shared> $<TARGET_OBJECTS:hs_exec_shared>)
else()
add_executable(unit-internal ${unit_internal_SOURCES})
endif()
set_target_properties(unit-internal PROPERTIES COMPILE_FLAGS "${HS_CXX_FLAGS}")
target_link_libraries(unit-internal hs corpusomatic)
endif(NOT (RELEASE_BUILD OR FAT_RUNTIME))
Expand Down

0 comments on commit e395cd3

Please sign in to comment.