| ... | @@ -175,23 +175,6 @@ if(ZIG_STATIC_CURSES) | ... | @@ -175,23 +175,6 @@ if(ZIG_STATIC_CURSES) |
| 175 | list(APPEND LLVM_LIBRARIES "${CURSES}") | 175 | list(APPEND LLVM_LIBRARIES "${CURSES}") |
| 176 | endif() | 176 | endif() |
| 177 | | 177 | |
| 178 | set(ZIG_CPP_LIB_DIR "${CMAKE_BINARY_DIR}/zigcpp") | | |
| 179 | | | |
| 180 | # Handle multi-config builds and place each into a common lib. The VS generator | | |
| 181 | # for example will append a Debug folder by default if not explicitly specified. | | |
| 182 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ZIG_CPP_LIB_DIR}) | | |
| 183 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ZIG_CPP_LIB_DIR}) | | |
| 184 | foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES}) | | |
| 185 | string(TOUPPER ${CONFIG_TYPE} CONFIG_TYPE) | | |
| 186 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_TYPE} ${ZIG_CPP_LIB_DIR}) | | |
| 187 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFIG_TYPE} ${ZIG_CPP_LIB_DIR}) | | |
| 188 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG_TYPE} ${CMAKE_BINARY_DIR}) | | |
| 189 | endforeach(CONFIG_TYPE CMAKE_CONFIGURATION_TYPES) | | |
| 190 | | | |
| 191 | include_directories(${LLVM_INCLUDE_DIRS}) | | |
| 192 | include_directories(${LLD_INCLUDE_DIRS}) | | |
| 193 | include_directories(${CLANG_INCLUDE_DIRS}) | | |
| 194 | | | |
| 195 | find_package(Threads) | 178 | find_package(Threads) |
| 196 | | 179 | |
| 197 | set(ZIG_CONFIG_H_OUT "${CMAKE_BINARY_DIR}/config.h") | 180 | set(ZIG_CONFIG_H_OUT "${CMAKE_BINARY_DIR}/config.h") |
| ... | @@ -200,6 +183,7 @@ set(ZIG_CONFIG_ZIG_OUT "${CMAKE_BINARY_DIR}/config.zig") | ... | @@ -200,6 +183,7 @@ set(ZIG_CONFIG_ZIG_OUT "${CMAKE_BINARY_DIR}/config.zig") |
| 200 | set(ZIG_WASM2C_SOURCES | 183 | set(ZIG_WASM2C_SOURCES |
| 201 | "${CMAKE_SOURCE_DIR}/stage1/wasm2c.c" | 184 | "${CMAKE_SOURCE_DIR}/stage1/wasm2c.c" |
| 202 | ) | 185 | ) |
| | 186 | # Sync with "zig_cpp_sources" in build.zig |
| 203 | set(ZIG_CPP_SOURCES | 187 | set(ZIG_CPP_SOURCES |
| 204 | # These are planned to stay even when we are self-hosted. | 188 | # These are planned to stay even when we are self-hosted. |
| 205 | "${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp" | 189 | "${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp" |
| ... | @@ -713,36 +697,64 @@ configure_file ( | ... | @@ -713,36 +697,64 @@ configure_file ( |
| 713 | "${ZIG_CONFIG_ZIG_OUT}" | 697 | "${ZIG_CONFIG_ZIG_OUT}" |
| 714 | ) | 698 | ) |
| 715 | | 699 | |
| 716 | include_directories( | 700 | # zigcpp target |
| 717 | ${CMAKE_SOURCE_DIR} | | |
| 718 | ${CMAKE_BINARY_DIR} | | |
| 719 | "${CMAKE_SOURCE_DIR}/src" | | |
| 720 | ) | | |
| 721 | | 701 | |
| 722 | if(MSVC) | 702 | set(ZIGCPP_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/zigcpp") |
| 723 | set(EXE_CXX_FLAGS "/std:c++17") | | |
| 724 | else() | | |
| 725 | set(EXE_CXX_FLAGS "-std=c++17 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Wno-type-limits -Wno-missing-braces -Wno-comment") | | |
| 726 | if(MINGW) | | |
| 727 | set(EXE_CXX_FLAGS "${EXE_CXX_FLAGS} -Wno-format") | | |
| 728 | endif() | | |
| 729 | endif() | | |
| 730 | | 703 | |
| 731 | add_library(zigcpp STATIC ${ZIG_CPP_SOURCES}) | 704 | add_library(zigcpp STATIC ${ZIG_CPP_SOURCES}) |
| 732 | if(ZIG_PIE) | | |
| 733 | set(ZIGCPP_CXX_FLAGS "${EXE_CXX_FLAGS} -fno-stack-protector -fPIC") | | |
| 734 | else() | | |
| 735 | set(ZIGCPP_CXX_FLAGS "${EXE_CXX_FLAGS} -fno-stack-protector") | | |
| 736 | endif() | | |
| 737 | set_target_properties(zigcpp PROPERTIES COMPILE_FLAGS ${ZIGCPP_CXX_FLAGS}) | | |
| 738 | | 705 | |
| 739 | target_link_libraries(zigcpp LINK_PUBLIC | 706 | # Sync with minimum C++ standard required to build LLVM |
| | 707 | # and with "exe_cflags" in build.zig |
| | 708 | target_compile_features(zigcpp PRIVATE cxx_std_17) |
| | 709 | set_target_properties(zigcpp PROPERTIES POSITION_INDEPENDENT_CODE ${ZIG_PIE}) |
| | 710 | |
| | 711 | if(NOT MSVC) |
| | 712 | if(MINGW) |
| | 713 | target_compile_options(zigcpp PRIVATE -Wno-format) |
| | 714 | endif() |
| | 715 | # Sync content below with "exe_cflags" in build.zig |
| | 716 | target_compile_definitions(zigcpp PUBLIC |
| | 717 | __STDC_CONSTANT_MACROS |
| | 718 | __STDC_FORMAT_MACROS |
| | 719 | __STDC_LIMIT_MACROS |
| | 720 | |
| | 721 | _GNU_SOURCE |
| | 722 | ) |
| | 723 | target_compile_options(zigcpp PRIVATE |
| | 724 | -fno-exceptions |
| | 725 | -fno-rtti |
| | 726 | -fno-stack-protector |
| | 727 | |
| | 728 | -fvisibility-inlines-hidden |
| | 729 | |
| | 730 | -Wno-type-limits |
| | 731 | -Wno-missing-braces |
| | 732 | -Wno-comment |
| | 733 | ) |
| | 734 | endif() |
| | 735 | |
| | 736 | target_include_directories(zigcpp PUBLIC |
| | 737 | ${CLANG_INCLUDE_DIRS} |
| | 738 | ${LLVM_INCLUDE_DIRS} |
| | 739 | ${LLD_INCLUDE_DIRS} |
| | 740 | ) |
| | 741 | target_link_libraries(zigcpp PUBLIC |
| 740 | ${CLANG_LIBRARIES} | 742 | ${CLANG_LIBRARIES} |
| 741 | ${LLD_LIBRARIES} | 743 | ${LLD_LIBRARIES} |
| 742 | ${LLVM_LIBRARIES} | 744 | ${LLVM_LIBRARIES} |
| 743 | ${CMAKE_THREAD_LIBS_INIT} | 745 | ${CMAKE_THREAD_LIBS_INIT} |
| 744 | ) | 746 | ) |
| 745 | | 747 | |
| | 748 | # Handle multi-config builds and place each into a common lib. The VS generator |
| | 749 | # for example will append a Debug folder by default if not explicitly specified. |
| | 750 | set_target_properties(zigcpp PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${ZIGCPP_OUTPUT_DIR}) |
| | 751 | foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES}) |
| | 752 | string(TOUPPER ${CONFIG_TYPE} CONFIG_TYPE) |
| | 753 | set_target_properties(zigcpp PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_TYPE} ${ZIGCPP_OUTPUT_DIR}) |
| | 754 | endforeach() |
| | 755 | |
| | 756 | # end of zigcpp target |
| | 757 | |
| 746 | string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" ZIG_HOST_TARGET_OS) | 758 | string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" ZIG_HOST_TARGET_OS) |
| 747 | if(ZIG_HOST_TARGET_OS STREQUAL "darwin") | 759 | if(ZIG_HOST_TARGET_OS STREQUAL "darwin") |
| 748 | set(ZIG_HOST_TARGET_OS "macos") | 760 | set(ZIG_HOST_TARGET_OS "macos") |