Update CMake files for Windows build
[sdk/tools/netcoredbg.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.12.2)
2 project(netcoredbg)
3
4 set(CLR_DIR "${CMAKE_SOURCE_DIR}/../coreclr" CACHE FILEPATH "Path to coreclr directory")
5 set(CLR_BIN_DIR "" CACHE FILEPATH "Path to coreclr bin directory")
6 set(BUILD_MANAGED ON CACHE BOOL "Build managed part")
7 set(DBGSHIM_INSTALL ON CACHE BOOL "Install dbgshim library")
8 if (WIN32)
9     set(CMAKE_CXX_STANDARD 11)
10 else()
11     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-null-conversion")
12 endif()
13
14 function(clr_unknown_arch)
15     message(FATAL_ERROR "Only AMD64, ARM64, ARM, ARMEL, I386 and WASM are supported")
16 endfunction()
17
18 if (WIN32)
19     # For windows it is expected that CLR_CMAKE_HOST_ARCH parameter is passed
20     # to CMAKE to determine build arch.
21     # If it is not passed, detect arch here.
22     if ("${CLR_CMAKE_HOST_ARCH}" STREQUAL "")
23         if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
24             set(CLR_CMAKE_HOST_ARCH x86)
25         else()
26             set(CLR_CMAKE_HOST_ARCH x64)
27         endif()
28     endif()
29 endif()
30
31 # Follow order as in root CoreCLR CMakeLists.txt
32 include(detectplatform.cmake) # from root
33 include(platformdefinitions.cmake) # from root
34 include(compileoptions.cmake) # disabled setting arm compiler flags in Tizen build
35 include(clrdefinitions.cmake)
36
37 if (NOT IS_DIRECTORY "${CLR_DIR}")
38     message(FATAL_ERROR "Unable to find CoreCLR directory")
39 endif()
40
41 set(CLR_CONFIGURATION_TYPES "Debug;Checked;Release;RelWithDebInfo" CACHE STRING "")
42
43 if ("${CLR_BIN_DIR}" STREQUAL "")
44     if (WIN32)
45         set(TARGET_OS_NAME "Windows_NT")
46     elseif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
47         set(TARGET_OS_NAME "OSX")
48     elseif (CMAKE_SYSTEM_NAME STREQUAL Linux)
49         set(TARGET_OS_NAME "Linux")
50     endif()
51
52     # TODO: Search for CMAKE_BUILD_TYPE configuration first
53     # TODO: CLR_CMAKE_TARGET_ARCH may be armel
54     foreach(CONFIG IN LISTS CLR_CONFIGURATION_TYPES)
55         set(CLR_BIN_DIR ${CLR_DIR}/bin/Product/${TARGET_OS_NAME}.${CLR_CMAKE_TARGET_ARCH}.${CONFIG})
56         if (IS_DIRECTORY "${CLR_BIN_DIR}")
57             break()
58         endif()
59     endforeach()
60
61     if (IS_DIRECTORY "${CLR_BIN_DIR}")
62         message(STATUS "CoreCLR bin directory: " ${CLR_BIN_DIR})
63     else()
64         message(FATAL_ERROR "Unable to find CoreCLR bin directory")
65     endif()
66 endif()
67
68 add_subdirectory(src/debug/netcoredbg)