Skip to content

Commit

Permalink
Allowing for certain configuration macros being defined conditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed May 21, 2017
1 parent 9fa5653 commit 684a0d9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
20 changes: 10 additions & 10 deletions CMakeLists.txt
Expand Up @@ -1151,7 +1151,7 @@ if(WIN32)
hpx_add_target_compile_option(-Zo CONFIGURATIONS RelWithDebInfo)
if(HPX_WITH_DATAPAR_VC)
hpx_add_target_compile_option(-std:c++latest)
hpx_add_config_define(_HAS_AUTO_PTR_ETC 1)
hpx_add_config_cond_define(_HAS_AUTO_PTR_ETC 1)
endif()
endif()

Expand All @@ -1168,7 +1168,7 @@ if(WIN32)

# Update 2 requires to set _ENABLE_ATOMIC_ALIGNMENT_FIX for it to compile
# atomics
hpx_add_config_define(_ENABLE_ATOMIC_ALIGNMENT_FIX)
hpx_add_config_cond_define(_ENABLE_ATOMIC_ALIGNMENT_FIX)

# Update 3 allows to flag rvalue misuses and enforces strict string const-
# qualification conformance
Expand All @@ -1191,13 +1191,13 @@ if(WIN32)
##############################################################################
add_definitions(-D_WINDOWS)
add_definitions(-D_WIN32)
hpx_add_config_define(_WIN32_WINNT 0x0601)
hpx_add_config_define(_SCL_SECURE_NO_WARNINGS)
hpx_add_config_define(_CRT_SECURE_NO_WARNINGS)
hpx_add_config_define(_SCL_SECURE_NO_DEPRECATE)
hpx_add_config_define(_CRT_SECURE_NO_DEPRECATE)
hpx_add_config_define(_CRT_NONSTDC_NO_WARNINGS)
hpx_add_config_define(_WINSOCK_DEPRECATED_NO_WARNINGS)
hpx_add_config_cond_define(_WIN32_WINNT 0x0601)
hpx_add_config_cond_define(_SCL_SECURE_NO_WARNINGS)
hpx_add_config_cond_define(_CRT_SECURE_NO_WARNINGS)
hpx_add_config_cond_define(_SCL_SECURE_NO_DEPRECATE)
hpx_add_config_cond_define(_CRT_SECURE_NO_DEPRECATE)
hpx_add_config_cond_define(_CRT_NONSTDC_NO_WARNINGS)
hpx_add_config_cond_define(_WINSOCK_DEPRECATED_NO_WARNINGS)

##############################################################################
# Boost
Expand All @@ -1213,7 +1213,7 @@ if(WIN32)
if(NOT HPX_WITH_GENERIC_CONTEXT_COROUTINES)
hpx_add_config_define(HPX_HAVE_FIBER_BASED_COROUTINES)
endif()
hpx_add_config_define(PSAPI_VERSION 1)
hpx_add_config_cond_define(PSAPI_VERSION 1)
endif()

# Configure Warnings
Expand Down
31 changes: 28 additions & 3 deletions cmake/HPX_AddDefinitions.cmake
Expand Up @@ -11,6 +11,7 @@
# ---------------------------------------------------------------------
# on startup, this is unset, but we'll set it to an empty string anyway
set_property(GLOBAL PROPERTY HPX_CONFIG_DEFINITIONS "")
set_property(GLOBAL PROPERTY HPX_CONFIG_COND_DEFINITIONS "")

function(hpx_add_config_define definition)

Expand All @@ -22,6 +23,16 @@ function(hpx_add_config_define definition)

endfunction()

function(hpx_add_config_cond_define definition)

if(ARGN)
set_property(GLOBAL APPEND PROPERTY HPX_CONFIG_COND_DEFINITIONS "${definition} ${ARGN}")
else()
set_property(GLOBAL APPEND PROPERTY HPX_CONFIG_COND_DEFINITIONS "${definition}")
endif()

endfunction()

# ---------------------------------------------------------------------
# Function to add config defines to a list that depends on a namespace variable
# #defines that match the namespace can later be written out to a file
Expand Down Expand Up @@ -56,8 +67,8 @@ function(write_config_defines_file)
"${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})

if (${OPTION_NAMESPACE} STREQUAL "default")
get_property(DEFINITIONS_VAR GLOBAL PROPERTY
HPX_CONFIG_DEFINITIONS)
get_property(DEFINITIONS_VAR GLOBAL PROPERTY HPX_CONFIG_DEFINITIONS)
get_property(COND_DEFINITIONS_VAR GLOBAL PROPERTY HPX_CONFIG_COND_DEFINITIONS)
else()
get_property(DEFINITIONS_VAR GLOBAL PROPERTY
HPX_CONFIG_DEFINITIONS_${OPTION_NAMESPACE})
Expand All @@ -70,7 +81,21 @@ function(write_config_defines_file)

set(hpx_config_defines "\n")
foreach(def ${DEFINITIONS_VAR})
set(hpx_config_defines "${hpx_config_defines}#define ${def} ${${def}_define}\n")#"
set(hpx_config_defines "${hpx_config_defines}#define ${def}\n")#"
endforeach()

if(DEFINED COND_DEFINITIONS_VAR)
list(SORT COND_DEFINITIONS_VAR)
list(REMOVE_DUPLICATES COND_DEFINITIONS_VAR)
set(hpx_config_defines "${hpx_config_defines}\n")
endif()
foreach(def ${COND_DEFINITIONS_VAR})
string(FIND ${def} " " _pos)
if(NOT ${_pos} EQUAL 0)
string(SUBSTRING ${def} 0 ${_pos} defname)
endif()
set(hpx_config_defines
"${hpx_config_defines}#if !defined(${defname})\n#define ${def}\n#endif\n")#"
endforeach()

# if the user has not specified a template, generate a proper header file
Expand Down

0 comments on commit 684a0d9

Please sign in to comment.