-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCMakeLists.txt
67 lines (60 loc) · 3.06 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
cmake_minimum_required(VERSION 3.10)
project(kcl-lib VERSION 0.11.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(KCL_LIB_ENABLE_TESTING "Enable building test binary" OFF)
# Get cargo target dir using cargo locate-project
# We should do this because the target dir is different for development and release
execute_process(COMMAND cargo locate-project --workspace --message-format plain
OUTPUT_VARIABLE CARGO_TARGET_DIR
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
string(REGEX REPLACE "/Cargo.toml\n$" "/target" CARGO_TARGET_DIR "${CARGO_TARGET_DIR}")
set(CARGO_MANIFEST ${PROJECT_SOURCE_DIR}/Cargo.toml)
set(RUST_SOURCE_FILE ${PROJECT_SOURCE_DIR}/src/lib.rs)
set(RUST_BRIDGE_CPP ${CARGO_TARGET_DIR}/cxxbridge/kcl-lib-cpp/src/lib.rs.cc)
set(RUST_HEADER_FILE ${CARGO_TARGET_DIR}/cxxbridge/kcl-lib-cpp/src/lib.rs.h)
set(RUST_LIB ${CARGO_TARGET_DIR}/release/${CMAKE_STATIC_LIBRARY_PREFIX}kcl_lib_cpp${CMAKE_STATIC_LIBRARY_SUFFIX})
set(CPP_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include ${CARGO_TARGET_DIR}/cxxbridge/kcl-lib-cpp/src)
file(GLOB_RECURSE CPP_SOURCE_FILE src/*.cpp)
file(GLOB_RECURSE CPP_HEADER_FILE include/*.hpp)
file(GLOB_RECURSE EXAMPLE_SOURCE_FILE examples/*.cpp)
add_custom_command(
OUTPUT ${RUST_BRIDGE_CPP} ${RUST_LIB} ${RUST_HEADER_FILE}
COMMAND cargo build --manifest-path ${CARGO_MANIFEST} --release
USES_TERMINAL
COMMENT "Running cargo build --release..."
)
add_library(kcl-lib-cpp STATIC ${CPP_SOURCE_FILE} ${RUST_BRIDGE_CPP})
target_sources(kcl-lib-cpp PUBLIC ${CPP_HEADER_FILE})
target_sources(kcl-lib-cpp PRIVATE ${RUST_HEADER_FILE})
target_include_directories(kcl-lib-cpp PUBLIC ${CPP_INCLUDE_DIR})
target_link_libraries(kcl-lib-cpp PUBLIC ${RUST_LIB})
target_link_libraries(kcl-lib-cpp PRIVATE ${CMAKE_DL_LIBS})
set_target_properties(kcl-lib-cpp
PROPERTIES ADDITIONAL_CLEAN_FILES ${CARGO_TARGET_DIR}
)
set(EXECUTABLES exec_api exec_with_deps_api override_api update_deps_api validate_api list_options_api get_version_api load_settings_files_api testing_api rename_code_api rename_api lint_path_api format_path_api format_code_api get_schema_type_api list_variables_api load_package_api parse_file_api parse_program_api)
foreach(EXE IN LISTS EXECUTABLES)
add_executable(${EXE} examples/${EXE}.cpp)
target_include_directories(${EXE} PUBLIC ${CPP_INCLUDE_DIR})
target_link_libraries(${EXE} PUBLIC kcl-lib-cpp)
if(WIN32)
target_link_libraries(${EXE} PRIVATE userenv ws2_32 bcrypt)
endif()
if(APPLE)
find_library(CORESERVICES_LIB CoreServices)
target_link_libraries(${EXE} PRIVATE ${CORESERVICES_LIB})
target_link_libraries(${EXE} PRIVATE "-framework CoreFoundation -framework Security")
endif()
endforeach()
# Platform-specific test configuration
if(WIN32)
target_link_libraries(kcl-lib-cpp userenv ws2_32 bcrypt)
set_target_properties(
kcl-lib-cpp
PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreadedDLL"
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}
)
endif()