Skip to content

Commit

Permalink
use cmake configure_file to avoid constant full rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Nov 4, 2021
1 parent ae55354 commit efc4435
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 31 deletions.
37 changes: 14 additions & 23 deletions contrib/windows-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ check_include_file("dirent.h" HAVE_DIRENT_H)
check_include_file("unistd.h" HAVE_UNISTD_H)
check_symbol_exists(mkstemp "stdlib.h" HAVE_MKSTEMP)

set(SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
# disable x86 by default
set(HWLOC_X86_32_ARCH)
set(HWLOC_X86_64_ARCH)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
# "AMD64" on Windows, "x86_64" on Linux
set(HWLOC_X86_64_ARCH 1)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86" OR CMAKE_SYSTEM_PROCESSOR MATCHES "i.86")
# "x86" on Windows, "i.86" on Linux
set(HWLOC_X86_32_ARCH 1)
endif()

try_run(
_have_cpuid
compileOK
Expand All @@ -45,35 +57,14 @@ endif()

configure_file(${TOPDIR}/contrib/windows/hwloc_config.h include/hwloc/autogen/config.h COPYONLY)
configure_file(${TOPDIR}/contrib/windows/static-components.h include/static-components.h COPYONLY)
if(MSVConly)
configure_file(${TOPDIR}/contrib/windows/private_config.h include/private/autogen/config.h COPYONLY)
else()
configure_file(${TOPDIR}/contrib/windows/private_config.h.in include/private/autogen/config.h)
endif()

file(READ ${CMAKE_CURRENT_BINARY_DIR}/include/private/autogen/config.h PRIVATE_CONFIG_H)
string(REPLACE "#define SIZEOF_VOID_P 8" "#define SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")

# disable x86 entirely by default
string(REPLACE "#define HWLOC_X86_32_ARCH 1" "/* #undef HWLOC_X86_32_ARCH */" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")
string(REPLACE "#define HWLOC_X86_64_ARCH 1" "/* #undef HWLOC_X86_64_ARCH */" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")
# and now reenable x86-36 or x86-64 if detected
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
# "AMD64" on Windows, "x86_64" on Linux
string(REPLACE "/* #undef HWLOC_X86_64_ARCH */" "#define HWLOC_X86_64_ARCH 1" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86" OR CMAKE_SYSTEM_PROCESSOR MATCHES "i.86")
# "x86" on Windows, "i.86" on Linux
string(REPLACE "/* #undef HWLOC_X86_32_ARCH */" "#define HWLOC_X86_32_ARCH 1" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")
endif()
configure_file(${TOPDIR}/contrib/windows/private_config.h.in include/private/autogen/config.h)

# the following lines are disabled until we are sure they are safe with old build environmentx
# - snprintf() returned broken values in the past, hwloc detects it during configure (see 7a4ee26510c06b55fc04aaccbfa18d0ca3b87198)
# string(REPLACE "#define HAVE_DECL_SNPRINTF 0" "#define HAVE_DECL_SNPRINTF 1" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")
# - strtoull() had some issues in the past (see 9559bd08b79ef63dce45df87fb7f875b73ecb512)
# string(REPLACE "#define HAVE_DECL_STRTOULL 0" "#define HAVE_DECL_STRTOULL 1" PRIVATE_CONFIG_H "${PRIVATE_CONFIG_H}")

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/include/private/autogen/config.h "${PRIVATE_CONFIG_H}")

# Library

add_compile_options("$<$<CONFIG:DEBUG>:-DHWLOC_DEBUG=1>")
Expand Down Expand Up @@ -186,7 +177,7 @@ endif()
# Misc

foreach(target IN ITEMS libhwloc ${TOOLS} ${LSTOPOS})
target_compile_definitions(${target} PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(${target} PRIVATE $<$<BOOL:${MSVC}>:_CRT_SECURE_NO_WARNINGS>)
endforeach(target)

# Install
Expand Down
16 changes: 8 additions & 8 deletions contrib/windows/private_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

#define DECLSPEC_EXPORTS

#cmakedefine HWLOC_HAVE_MSVC_CPUIDEX
#cmakedefine HWLOC_HAVE_MSVC_CPUIDEX @HWLOC_HAVE_MSVC_CPUIDEX@

#cmakedefine HAVE_MKSTEMP
#cmakedefine HAVE_MKSTEMP @HAVE_MKSTEMP@

#cmakedefine HWLOC_HAVE_X86_CPUID
#cmakedefine HWLOC_HAVE_X86_CPUID @HWLOC_HAVE_X86_CPUID@

/* Define to 1 if the system has the type `CACHE_DESCRIPTOR'. */
#define HAVE_CACHE_DESCRIPTOR 0
Expand Down Expand Up @@ -132,7 +132,7 @@
#define HAVE_DECL__SC_PAGE_SIZE 0

/* Define to 1 if you have the <dirent.h> header file. */
#cmakedefine HAVE_DIRENT_H
#cmakedefine HAVE_DIRENT_H @HAVE_DIRENT_H@

/* Define to 1 if you have the <dlfcn.h> header file. */
/* #undef HAVE_DLFCN_H */
Expand Down Expand Up @@ -330,7 +330,7 @@
/* #undef HAVE_UNAME */

/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H
#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@

/* Define to 1 if you have the `uselocale' function. */
/* #undef HAVE_USELOCALE */
Expand Down Expand Up @@ -564,10 +564,10 @@
#define HWLOC_WIN_SYS 1

/* Define to 1 on x86_32 */
/* #undef HWLOC_X86_32_ARCH */
#cmakedefine HWLOC_X86_32_ARCH @HWLOC_X86_32_ARCH@

/* Define to 1 on x86_64 */
#define HWLOC_X86_64_ARCH 1
#cmakedefine HWLOC_X86_64_ARCH @HWLOC_X86_64_ARCH@

/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
Expand Down Expand Up @@ -601,7 +601,7 @@
#define SIZEOF_UNSIGNED_LONG 4

/* The size of `void *', as computed by sizeof. */
#define SIZEOF_VOID_P 8
#cmakedefine SIZEOF_VOID_P @SIZEOF_VOID_P@

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
Expand Down

0 comments on commit efc4435

Please sign in to comment.