[CMAKE] Fix host tools build on x86-64 mingw
authorJérôme Gardou <jerome.gardou@reactos.org>
Fri, 15 Nov 2019 13:07:46 +0000 (14:07 +0100)
committerJérôme Gardou <zefklop@users.noreply.github.com>
Fri, 15 Nov 2019 15:22:06 +0000 (16:22 +0100)
Dynamically check for sys/types.h and pid_t in wine config.h
Use TARGET_xxx defines instead of _X86_ as this is undefined by GCC
Add some sense in include directories management by using interface
libraries

19 files changed:
CMakeLists.txt
dll/win32/dbghelp/CMakeLists.txt
dll/win32/dbghelp/compat.h
sdk/include/host/CMakeLists.txt [new file with mode: 0644]
sdk/include/host/config.h.in [moved from sdk/include/host/config.h with 95% similarity]
sdk/lib/3rdparty/zlib/CMakeLists.txt
sdk/lib/cmlib/CMakeLists.txt
sdk/lib/inflib/CMakeLists.txt
sdk/tools/CMakeLists.txt
sdk/tools/cabman/CMakeLists.txt
sdk/tools/fatten/CMakeLists.txt
sdk/tools/kbdtool/CMakeLists.txt
sdk/tools/log2lines/CMakeLists.txt
sdk/tools/mkhive/CMakeLists.txt
sdk/tools/rsym/CMakeLists.txt
sdk/tools/unicode/CMakeLists.txt
sdk/tools/widl/CMakeLists.txt
sdk/tools/wpp/CMakeLists.txt
sdk/tools/xml2sdb/CMakeLists.txt

index aa2fefd..73b4e69 100644 (file)
@@ -88,8 +88,7 @@ if(NOT CMAKE_CROSSCOMPILING)
             add_definitions(/Dinline=__inline)
         endif()
     endif()
-
-    include_directories(sdk/include/host)
+    add_subdirectory(sdk/include/host)
 
     if(NOT MSVC)
         add_subdirectory(dll/win32/dbghelp)
index 319d38c..f1790d0 100644 (file)
@@ -7,10 +7,6 @@ endif()
 if(NOT CMAKE_CROSSCOMPILING)
     add_definitions(-DDBGHELP_STATIC_LIB)
 
-    if(ARCH STREQUAL "i386")
-        add_definitions(-D_X86_)
-    endif()
-
     include_directories(
         ${REACTOS_SOURCE_DIR}/tools
         ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib)
@@ -32,6 +28,7 @@ if(NOT CMAKE_CROSSCOMPILING)
     endif()
 
     add_library(dbghelphost ${SOURCE})
+    target_link_libraries(dbghelphost PRIVATE host_includes)
 else()
     add_definitions(
         -D__WINESRC__
index a356585..b662cdd 100644 (file)
@@ -200,7 +200,7 @@ typedef struct _EXCEPTION_RECORD {
   DWORD NumberParameters;
   ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
-#if defined(_X86_)
+#if defined(TARGET_i386)
 #define SIZE_OF_80387_REGISTERS        80
 #define CONTEXT_i386   0x10000
 #define CONTEXT_i486   0x10000
@@ -257,7 +257,11 @@ typedef struct _CONTEXT {
   BYTE ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
 } CONTEXT, *PCONTEXT;
 
-#else /* ARM? */
+#elif defined TARGET_amd64
+
+#error "Please define the CONTEXT structure for amd64 platform"
+
+#elif defined TARGET_arm /* ARM? */
 
 /* The following flags control the contents of the CONTEXT structure. */
 
@@ -356,6 +360,10 @@ typedef struct _CONTEXT {
 BOOLEAN CDECL            RtlAddFunctionTable(RUNTIME_FUNCTION*,DWORD,DWORD);
 BOOLEAN CDECL            RtlDeleteFunctionTable(RUNTIME_FUNCTION*);
 PRUNTIME_FUNCTION WINAPI RtlLookupFunctionEntry(ULONG_PTR,DWORD*,UNWIND_HISTORY_TABLE*);
+#else
+
+#error "Unknown target platform"
+
 #endif
 
 typedef
diff --git a/sdk/include/host/CMakeLists.txt b/sdk/include/host/CMakeLists.txt
new file mode 100644 (file)
index 0000000..216e012
--- /dev/null
@@ -0,0 +1,19 @@
+
+include(CheckIncludeFile)
+include(CheckTypeSize)
+
+# check for <sys/types.h>
+CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
+
+# check for pid_t definition
+if (HAVE_SYS_TYPES_H)
+    set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h")
+    #this sets HAVE_PID_T
+    CHECK_TYPE_SIZE("pid_t" PID_T)
+    unset(CMAKE_EXTRA_INCLUDE_FILES)
+endif()
+
+configure_file(config.h.in config.h @ONLY)
+
+add_library(host_includes INTERFACE)
+target_include_directories(host_includes INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
similarity index 95%
rename from sdk/include/host/config.h
rename to sdk/include/host/config.h.in
index e6bb8af..5ba4eaa 100644 (file)
@@ -3,6 +3,12 @@
 
 #define __WINE_CONFIG_H
 
+/* Define to 1 if you have the <sys/types.h> header file. */
+#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@
+
+/* Define to 1 if the system has the type `pid_t'. */
+#cmakedefine HAVE_PID_T 1
+
 #define HAVE_SPAWNVP 1
 
 /* Define to 1 if you have the `z' library (-lz). */
index e507fe2..c68a46e 100644 (file)
@@ -1,6 +1,5 @@
 
 add_definitions(-DNO_VIZ)
-include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib)
 
 list(APPEND SOLO_SOURCE
     adler32.c
@@ -35,11 +34,15 @@ list(APPEND MINIZIP_SOURCE
 
 if(CMAKE_CROSSCOMPILING)
     add_library(zlib ${SOURCE} ${SOLO_SOURCE})
+    target_include_directories(zlib PRIVATE ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib)
     add_library(zlib_solo ${SOLO_SOURCE})
     add_target_compile_definitions(zlib_solo Z_SOLO)
+    target_include_directories(zlib_solo PRIVATE ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib)
     add_library(minizip ${MINIZIP_SOURCE})
     add_dependencies(minizip psdk)
+    target_include_directories(minizip PRIVATE ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib)
 else()
     add_library(zlibhost ${SOLO_SOURCE})
     add_target_compile_definitions(zlibhost Z_SOLO)
+    target_include_directories(zlibhost PUBLIC ${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib)
 endif()
index 2183935..c94674f 100644 (file)
@@ -26,10 +26,11 @@ else()
         -D__NO_CTYPE_INLINES
         -DCMLIB_HOST)
     add_library(cmlibhost ${SOURCE})
+    target_include_directories(cmlibhost INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
 
     if(NOT MSVC)
         add_target_compile_flags(cmlibhost "-fshort-wchar -Wno-multichar")
     endif()
 
-    target_link_libraries(cmlibhost unicode)
+    target_link_libraries(cmlibhost PRIVATE host_includes)
 endif()
index bf8086a..1688d69 100644 (file)
@@ -23,10 +23,11 @@ else()
 
     add_definitions(-D__NO_CTYPE_INLINES -DINFLIB_HOST -D_CRT_SECURE_NO_WARNINGS)
     add_library(inflibhost ${SOURCE})
+    target_include_directories(inflibhost INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
 
     if(NOT MSVC)
         add_target_compile_flags(inflibhost "-fshort-wchar -Wpointer-arith -Wwrite-strings")
     endif()
 
-    target_link_libraries(inflibhost unicode)
+    target_link_libraries(inflibhost PRIVATE host_includes)
 endif()
index d893725..7fab47e 100644 (file)
@@ -19,6 +19,8 @@ add_host_tool(gendib gendib/gendib.c)
 add_host_tool(geninc geninc/geninc.c)
 add_host_tool(mkshelllink mkshelllink/mkshelllink.c)
 add_host_tool(obj2bin obj2bin/obj2bin.c)
+target_link_libraries(obj2bin PRIVATE host_includes)
+
 add_host_tool(spec2def spec2def/spec2def.c)
 add_host_tool(utf16le utf16le/utf16le.cpp)
 
index f684c73..938478b 100644 (file)
@@ -7,6 +7,5 @@ list(APPEND SOURCE
     raw.cxx
     CCFDATAStorage.cxx)
 
-include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib)
 add_host_tool(cabman ${SOURCE})
-target_link_libraries(cabman zlibhost)
+target_link_libraries(cabman PRIVATE host_includes zlibhost)
index e3d507f..902db72 100644 (file)
@@ -4,3 +4,4 @@ add_host_tool(fatten
     fatfs/diskio.c
     fatfs/ff.c
     fatfs/option/ccsbcs.c)
+target_link_libraries(fatten PRIVATE host_includes)
index a8adaa2..c525926 100644 (file)
@@ -1,2 +1,3 @@
 
 add_host_tool(kbdtool data.c main.c output.c parser.c)
+target_link_libraries(kbdtool PRIVATE host_includes)
index e32f0bb..bc74e8e 100644 (file)
@@ -14,4 +14,4 @@ list(APPEND SOURCE
 
 include_directories(${REACTOS_SOURCE_DIR}/sdk/tools/rsym)
 add_host_tool(log2lines ${SOURCE})
-target_link_libraries(log2lines rsym_common)
+target_link_libraries(log2lines PRIVATE host_includes rsym_common)
index 5f9446f..7f1845d 100644 (file)
@@ -1,11 +1,4 @@
 
-add_definitions(-DMKHIVE_HOST)
-
-include_directories(
-    ${REACTOS_SOURCE_DIR}/sdk/lib/inflib
-    ${REACTOS_SOURCE_DIR}/sdk/lib/cmlib
-    ${REACTOS_SOURCE_DIR}/sdk/lib/rtl)
-
 list(APPEND SOURCE
     binhive.c
     cmi.c
@@ -15,9 +8,10 @@ list(APPEND SOURCE
     rtl.c)
 
 add_host_tool(mkhive ${SOURCE})
-
+target_include_directories(mkhive PRIVATE ${REACTOS_SOURCE_DIR}/sdk/lib/rtl)
+target_compile_definitions(mkhive PRIVATE -DMKHIVE_HOST)
 if(NOT MSVC)
     add_target_compile_flags(mkhive "-fshort-wchar")
 endif()
 
-target_link_libraries(mkhive unicode cmlibhost inflibhost)
+target_link_libraries(mkhive PRIVATE host_includes unicode cmlibhost inflibhost)
index 26e6d2e..370f74e 100644 (file)
@@ -1,9 +1,9 @@
 
 include_directories(${REACTOS_SOURCE_DIR}/sdk/tools)
-add_library(rsym_common rsym_common.c)
+add_library(rsym_common STATIC rsym_common.c)
+target_link_libraries(rsym_common PRIVATE host_includes)
 
 if(ARCH STREQUAL "i386")
-    add_definitions(-D_X86_)
     add_host_tool(rsym rsym.c)
 elseif(ARCH STREQUAL "amd64")
     add_host_tool(rsym rsym64.c)
@@ -11,5 +11,6 @@ elseif(ARCH STREQUAL "arm")
     add_executable(rsym rsym64.c)
 endif()
 
-target_link_libraries(rsym rsym_common dbghelphost zlibhost unicode)
-add_host_tool(raddr2line rsym_common.c raddr2line.c)
+target_link_libraries(rsym PRIVATE host_includes rsym_common dbghelphost zlibhost unicode)
+add_host_tool(raddr2line raddr2line.c)
+target_link_libraries(raddr2line PRIVATE host_includes rsym_common)
index 8e6c09f..7e75861 100644 (file)
@@ -83,7 +83,8 @@ list(APPEND SOURCE
     wctomb.c
     wctype.c)
 
-add_library(unicode ${SOURCE})
+add_library(unicode STATIC ${SOURCE})
+target_link_libraries(unicode PRIVATE host_includes)
 
 if(MSVC)
     # Disable warning "'<': signed/unsigned mismatch"
index a37a80d..51e7356 100644 (file)
@@ -34,7 +34,7 @@ list(APPEND SOURCE
 # Taken from widl.rbuild
 add_definitions(-DINT16=SHORT)
 add_host_tool(widl ${SOURCE})
-target_link_libraries(widl wpphost)
+target_link_libraries(widl PRIVATE host_includes wpphost)
 
 if(MSVC)
     # Disable warning "'>': signed/unsigned mismatch"
index 39f3b2d..4eef72c 100644 (file)
@@ -28,7 +28,6 @@ if(CMAKE_CROSSCOMPILING)
         -Dstrtoll=_strtoi64
         -Dopen=_open
         -Dclose=_close)
-
     include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/wine)
 endif()
 
@@ -42,4 +41,5 @@ if(CMAKE_CROSSCOMPILING)
     add_library(wpp ${SOURCE})
 else()
     add_library(wpphost ${SOURCE})
+    target_link_libraries(wpphost PRIVATE host_includes)
 endif()
index 15e2fc7..8c302ce 100644 (file)
@@ -13,6 +13,7 @@ include_directories(
     ${REACTOS_SOURCE_DIR}/dll/appcompat/apphelp
     ${REACTOS_SOURCE_DIR}/sdk/include/reactos/appcompat)
 add_host_tool(xml2sdb ${SOURCE})
+target_link_libraries(xml2sdb PRIVATE host_includes)
 
 if(MSVC)
     # Disable warning "'=': conversion from 'a' to 'b', possible loss of data"