-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompileHaskell.cmake
46 lines (34 loc) · 1.68 KB
/
compileHaskell.cmake
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
# how to build the result of the library
# create a target out of the library compilation result
# create an library target out of the library compilation result
# Ensure FindHaskell is run and GHC has been found (or make a custom target ;))
# Windows only atm
function(add_haskell_library target_name header_name)
list(LENGTH ARGN num_source_files)
if(num_source_files LESS 1)
message(FATAL_ERROR "No SOURCES given to target: ${target_name}")
endif()
set(library_file "${CMAKE_CURRENT_BINARY_DIR}/${target_name}.dll")
set(library_link_file "${CMAKE_CURRENT_BINARY_DIR}/${target_name}.dll.a")
set(include_dir "${CMAKE_CURRENT_BINARY_DIR}/include")
set(header_dir "${include_dir}/${header_name}")
# if....Don't think i need to check tbh
file(MAKE_DIRECTORY ${header_dir})
add_custom_command(OUTPUT ${library_file} ${library_link_file}
COMMAND ${HASKELL_EXECUTABLE}
ARGS -shared
-o ${library_file}
-outputdir ${CMAKE_CURRENT_BINARY_DIR}
-stubdir ${header_dir}
${ARGN}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target("${target_name}_target" DEPENDS ${library_file} ${library_link_file})
add_library(${target_name} SHARED IMPORTED GLOBAL)
add_dependencies(${target_name} "${target_name}_target")
# specify where the library is, where the import lib is and where to find the headers
set_target_properties(${target_name}
PROPERTIES
IMPORTED_LOCATION ${library_file}
IMPORTED_IMPLIB ${library_link_file}
INTERFACE_INCLUDE_DIRECTORIES "${include_dir};${HASKELL_INCLUDE_DIR}")
endfunction()