From 71aa4b185535e05614e1e3c10fd193714ac98726 Mon Sep 17 00:00:00 2001
From: John Biddiscombe <biddisco@cscs.ch>
Date: Thu, 12 Jan 2017 14:13:47 +0100
Subject: [PATCH] CMake fixes (#137)

* Fix CMakeLists to handle build as a subproject

When several CMake generated projects are build together, it is common
practice to have a 'superproject' CMakeLists that uses
  add_subdir(proj1)
  add_subdir(proj2)
  ...
where each subproject is a self contained CMake based project
(Example proj1=HPX, proj2=nestmc, proj3=another, ...)

CMAKE_SOURCE_DIR always points to the top level directory which
is the superproject dir in this case, whereas PROJECT_SOURCE_DIR
always points to the root of the current project() in the CMakeLists
so one shouod use PROJECT_SOURCE_DIR as this gets the relative paths
correct.

* Add option to turn off auto generation from *.mod files

* Fix #134 : Change CMake WITH_OPTION to NMC_WITH_OPTION, compiler #define to NMC_HAVE_OPTION

1) The user may select an option by saying NMC_WITH_XXX

2) This may trigger CMake to use find_package(...) or setup some
other variables. CMake can then set variable NMC_HAVE_XXX and add a
what has actually been used.

3) Code should use #ifdef NMC_HAVE_XXX to check for a feature

Old CMake/define      New CMake                 Compiler #define
----------------      ---------                 ----------------
THREADING_MODEL       NMC_THREAD_MODEL
    WITH_TBB          NMC_WITH_TBB              NMC_HAVE_TBB
    WITH_OMP          NMC_WITH_OMP              NMC_HAVE_OMP
    WITH_SERIAL       NMC_WITH_SERiAL           NMC_HAVE_SERIAL

WITH_MPI              NMC_WITH_MPI              NMC_HAVE_MPI
WITH_CUDA             NMC_WITH_CUDA             NMC_HAVE_CUDA
WITH_GPU                                        NMC_HAVE_GPU
WITH_ASSERTIONS       NMC_WITH_ASSERTIONS       NMC_HAVE_ASSERTIONS
WITH_TRACE            NMC_WITH_TRACE            NMC_HAVE_TRACE
WITH_PROFILING        NMC_WITH_PROFILING        NMC_HAVE_PROFILING

Other user visible CMake vars
-----------------------------
VECTORIZE_TARGET            -> NMC_VECTORIZE_TARGET
USE_OPTIIZED_KERNELS        -> NMC_USE_OPTIIZED_KERNELS
BUILD_VALIDATION_DATA       -> NMC_BUILD_VALIDATION_DATA
BUILD_JULIA_VALIDATION_DATA -> NMC_BUILD_JULIA_VALIDATION_DATA
BUILD_NRN_VALIDATION_DATA   -> NMC_BUILD_NRN_VALIDATION_DATA
VALIDATION_DATA_DIR         -> NMC_VALIDATION_DATA_DIR

Variables such as NMC_THREADING_MODEL and NMC_VECTORIZE_TARGET now use
enumerated cmake values so you can toggle between them in ccmake gui.
SYSTEM_TYPE_CRAY/BGQ        -> NMC_SYSTEM_TYPE (Generic/Cray/BGQ)

* Use generator expression for modcc path

Some IDE's (like Xcode for example), override the CMake binary paths
and add /Debug or /Release etc so rules that have hard coded paths
to binaries will fail.
---
 .gitignore                                    |   2 +
 .ycm_extra_conf.py                            |   4 +-
 CMakeLists.txt                                | 180 +++++++++++-------
 README.md                                     |  20 +-
 mechanisms/CMakeLists.txt                     |   4 +-
 miniapp/CMakeLists.txt                        |   4 +-
 miniapp/miniapp.cpp                           |   4 +-
 src/CMakeLists.txt                            |   9 +-
 src/backends/fvm.hpp                          |   2 +-
 src/communication/global_policy.hpp           |   4 +-
 src/communication/mpi_global_policy.hpp       |   4 +-
 src/memory/allocator.hpp                      |  10 +-
 src/memory/gpu.hpp                            |   2 +-
 src/memory/host_coordinator.hpp               |   6 +-
 src/memory/memory.hpp                         |   4 +-
 src/memory/wrappers.hpp                       |   6 +-
 src/profiling/profiler.cpp                    |   6 +-
 src/profiling/profiler.hpp                    |   4 +-
 src/threading/omp.hpp                         |   4 +-
 src/threading/serial.hpp                      |   4 +-
 src/threading/tbb.hpp                         |   4 +-
 src/threading/threading.hpp                   |   6 +-
 src/util/debug.hpp                            |   6 +-
 src/util/range.hpp                            |   4 +-
 tests/global_communication/CMakeLists.txt     |   2 +-
 .../test_mpi_gather_all.cpp                   |   4 +-
 tests/modcc/CMakeLists.txt                    |   2 +-
 tests/performance/io/CMakeLists.txt           |   2 +-
 tests/unit/CMakeLists.txt                     |  16 +-
 tests/unit/test_range.cpp                     |   4 +-
 tests/validation/CMakeLists.txt               |  10 +-
 validation/CMakeLists.txt                     |   4 +-
 validation/ref/numeric/CMakeLists.txt         |   2 +-
 33 files changed, 205 insertions(+), 144 deletions(-)

diff --git a/.gitignore b/.gitignore
index bb339027..0232728e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -62,3 +62,5 @@ build*
 
 commit.msg
 
+# eclipse remote sync folders
+.ptp-sync-folder
diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py
index 37abca70..035b3ed1 100644
--- a/.ycm_extra_conf.py
+++ b/.ycm_extra_conf.py
@@ -36,7 +36,7 @@ import ycm_core
 # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
 flags = [
     '-DNDEBUG',
-    '-DWITH_TBB',
+    '-DNMC_HAVE_TBB',
     '-std=c++11',
     '-x',
     'c++',
@@ -54,7 +54,7 @@ flags = [
     'modcc',
     '-I',
     '/cm/shared/apps/cuda/8.0.44/include',
-    '-DWITH_CUDA'
+    '-DNMC_HAVE_CUDA'
 ]
 
 # Set this to the absolute path to the folder (NOT the file!) containing the
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 521c5a80..d4cd87e4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ enable_language(CXX)
 set(SAVED_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
 
 # compilation flags
-set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
+set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
 include("CompilerOptions")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXOPT_DEBUG} ${CXXOPT_CXX11} ${CXXOPT_PTHREAD} ${CXXOPT_WALL}")
 
@@ -19,45 +19,67 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS "YES")
 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
 
-# enable assertions?
-set(WITH_ASSERTIONS OFF CACHE BOOL "enable EXPECTS() assertions in code")
-if(WITH_ASSERTIONS)
-    add_definitions("-DWITH_ASSERTIONS")
+#----------------------------------------------------------
+# Option to enable assertions
+#----------------------------------------------------------
+option(NMC_WITH_ASSERTIONS "enable EXPECTS() assertions in code" OFF)
+if(NMC_WITH_ASSERTIONS)
+    add_definitions("-DNMC_HAVE_ASSERTIONS")
 endif()
 
-# enable traces?
-set(WITH_TRACE OFF CACHE BOOL "enable TRACE() macros in code")
-if(WITH_TRACE)
-    add_definitions("-DWITH_TRACE")
+#----------------------------------------------------------
+# Option to enable traces
+#----------------------------------------------------------
+option(NMC_WITH_TRACE "enable TRACE() macros in code" OFF)
+if(NMC_WITH_TRACE)
+    add_definitions("-DNMC_HAVE_TRACE")
 endif()
 
-# list of libraries to be linked against targets
+#----------------------------------------------------------
+# Option to disable auto running of modcc compiler
+#----------------------------------------------------------
+option(NMC_AUTO_RUN_MODCC_ON_CHANGES
+  "Rerun modcc compiler whenever *.mod file or modcc compiler change" ON)
+
+#----------------------------------------------------------
+# prepare list of libraries/includes needed by external libs
+#----------------------------------------------------------
 set(EXTERNAL_LIBRARIES "")
+set(EXTERNAL_INCLUDES "")
+
+#----------------------------------------------------------
+# Threading model selection
+#----------------------------------------------------------
+set(NMC_THREADING_MODEL "serial" CACHE STRING "set the threading model, one of serial/tbb/omp")
+set_property(CACHE NMC_THREADING_MODEL PROPERTY STRINGS serial tbb omp)
 
-#threading model selection
-set(THREADING_MODEL "serial" CACHE STRING "set the threading model, one of serial/tbb/omp")
-if(THREADING_MODEL MATCHES "tbb")
+if(NMC_THREADING_MODEL MATCHES "tbb")
     # TBB support
     find_package(TBB REQUIRED)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TBB_DEFINITIONS}")
-    add_definitions(-DWITH_TBB)
+    add_definitions(-DNMC_HAVE_TBB)
+    set(NMC_HAVE_TBB TRUE)
     list(APPEND EXTERNAL_LIBRARIES ${TBB_LIBRARIES})
+    list(APPEND EXTERNAL_INCLUDES ${TBB_INCLUDE_DIRS})
 
-elseif(THREADING_MODEL MATCHES "omp")
+elseif(NMC_THREADING_MODEL MATCHES "omp")
     # OpenMP support
     find_package(OpenMP REQUIRED)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
-    add_definitions(-DWITH_OMP)
+    add_definitions(-DNMC_HAVE_OMP)
+    set(NMC_HAVE_OMP TRUE)
 
-elseif(THREADING_MODEL MATCHES "serial")
+elseif(NMC_THREADING_MODEL MATCHES "serial")
     #setup previously done
 
 else()
-    message( FATAL_ERROR "-- Threading model '${THREADING_MODEL}' not supported, use one of serial/tbb/omp")
+    message( FATAL_ERROR "-- Threading model '${NMC_THREADING_MODEL}' not supported, use one of serial/tbb/omp")
 
 endif()
 
+#----------------------------------------------------------
 # libunwind for pretty printing stack traces
+#----------------------------------------------------------
 find_package(Unwind)
 if(UNWIND_FOUND)
     add_definitions(-DWITH_UNWIND)
@@ -65,9 +87,11 @@ if(UNWIND_FOUND)
     list(APPEND EXTERNAL_LIBRARIES ${UNWIND_LIBRARIES})
 endif()
 
+#----------------------------------------------------------
 # CUDA support
-set(WITH_CUDA OFF CACHE BOOL "use CUDA for GPU offload" )
-if(WITH_CUDA)
+#----------------------------------------------------------
+option(NMC_WITH_CUDA "use CUDA for GPU offload" OFF)
+if(NMC_WITH_CUDA)
     find_package(CUDA REQUIRED)
 
     # Turn off annoying and incorrect warnings generated in the JSON file.
@@ -75,90 +99,111 @@ if(WITH_CUDA)
     set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-Xcudafe \"--diag_suppress=not_used_in_template_function_params\";-Xcudafe \"--diag_suppress=cast_to_qualified_type\")
 
     # set the CUDA target specfic flags
-    # code regions protected by WITH_CUDA should only be available to the CUDA
-    # compiler, which regions protected by WITH_GPU are visible to both host
+    # code regions protected by NMC_HAVE_CUDA should only be available to the CUDA
+    # compiler, which regions protected by NMC_HAVE_GPU are visible to both host
     # and device compiler when targetting GPU.
-    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-DWITH_CUDA)
-    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-DWITH_GPU)
+    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-DNMC_HAVE_CUDA)
+    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-DNMC_HAVE_GPU)
     set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-arch=sm_35)
     #set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-arch=sm_60)
 
-    add_definitions(-DWITH_GPU)
+    add_definitions(-DNMC_HAVE_GPU)
     include_directories(SYSTEM ${CUDA_INCLUDE_DIRS})
     list(APPEND EXTERNAL_LIBRARIES ${CUDA_LIBRARIES})
 endif()
 
-# BGQ systems
-set(SYSTEM_BGQ OFF CACHE BOOL "Flags for BlueGene Q")
+#----------------------------------------------------------
+# Cray/BGQ/Generic Linux/other flag?
+#----------------------------------------------------------
+set(NMC_SYSTEM_TYPE "Generic" CACHE STRING 
+    "Choose a system type to customize flags")
+set_property(CACHE NMC_SYSTEM_TYPE PROPERTY STRINGS Generic Cray BGQ )
+
+# Cray specific flags
+if(${NMC_SYSTEM_TYPE} MATCHES "Cray")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -dynamic")
+endif()
 
+#----------------------------------------------------------
 # MPI support
-set(WITH_MPI OFF CACHE BOOL "use MPI for distrubuted parallelism")
-if(WITH_MPI)
+#----------------------------------------------------------
+option(NMC_WITH_MPI "use MPI for distrubuted parallelism" OFF)
+
+if(NMC_WITH_MPI)
     find_package(MPI REQUIRED)
     include_directories(SYSTEM ${MPI_C_INCLUDE_PATH})
-    add_definitions(-DWITH_MPI)
+    add_definitions(-DNMC_HAVE_MPI)
     # unfortunate workaround for C++ detection in system mpi.h
     add_definitions(-DMPICH_SKIP_MPICXX=1 -DOMPI_SKIP_MPICXX=1)
     set_property(DIRECTORY APPEND_STRING PROPERTY COMPILE_OPTIONS "${MPI_C_COMPILE_FLAGS}")
 
-   if(SYSTEM_BGQ)
+    # BGQ specific flags
+   if(${NMC_SYSTEM_TYPE} MATCHES "BGQ" )
      add_definitions(-DMPICH2_CONST=const)
    endif()
 endif()
 
+#----------------------------------------------------------
 # Internal profiler support
-set(WITH_PROFILING OFF CACHE BOOL "use built-in profiling of miniapp" )
-if(WITH_PROFILING)
-    add_definitions(-DWITH_PROFILING)
-endif()
-
-# Cray systems
-set(SYSTEM_CRAY OFF CACHE BOOL "add flags for compilation on Cray systems")
-if(SYSTEM_CRAY)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -dynamic")
+#----------------------------------------------------------
+option(NMC_WITH_PROFILING "use built-in profiling of miniapp" OFF)
+if(NMC_WITH_PROFILING)
+    add_definitions(-DNMC_HAVE_PROFILING)
 endif()
 
+#----------------------------------------------------------
 # vectorization target
-set(VECTORIZE_TARGET "none" CACHE STRING "CPU target for vectorization {KNL,AVX,AVX2}")
+#----------------------------------------------------------
+set(NMC_VECTORIZE_TARGET "none" CACHE STRING "CPU target for vectorization {KNL,AVX,AVX2}")
+set_property(CACHE NMC_VECTORIZE_TARGET PROPERTY STRINGS none KNL AVX AVX2)
 
-if(VECTORIZE_TARGET STREQUAL "KNL")
+if(NMC_VECTORIZE_TARGET STREQUAL "KNL")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXOPT_KNL}")
-elseif(VECTORIZE_TARGET STREQUAL "AVX")
+elseif(NMC_VECTORIZE_TARGET STREQUAL "AVX")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXOPT_AVX}")
-elseif(VECTORIZE_TARGET STREQUAL "AVX2")
+elseif(NMC_VECTORIZE_TARGET STREQUAL "AVX2")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXOPT_AVX2}")
 endif()
 
+#----------------------------------------------------------
 # whether to generate optimized kernels from NMODL
-set(USE_OPTIMIZED_KERNELS OFF CACHE BOOL "generate optimized code that vectorizes with the Intel compiler")
+#----------------------------------------------------------
+option(NMC_USE_OPTIMIZED_KERNELS
+    "generate optimized code that vectorizes with the Intel compiler" OFF)
 
+#----------------------------------------------------------
 # Only build modcc if it has not already been installed.
 # This is useful if cross compiling for KNL, when it is not desirable to compile
 # modcc with the same flags that are used for the KNL target.
+#----------------------------------------------------------
 set(use_external_modcc OFF)
 find_program(MODCC_BIN modcc)
-if(MODCC_BIN STREQUAL "MODCC_BIN-NOTFOUND")
-    set(modcc "${CMAKE_BINARY_DIR}/modcc/modcc")
-else()
+if(MODCC_BIN)
     set(use_external_modcc ON)
     set(modcc "${MODCC_BIN}")
+else()
+    set(modcc $<TARGET_FILE:modcc>)
 endif()
 
+#----------------------------------------------------------
 # Validation data generation
-
+#----------------------------------------------------------
 # destination directory for generated data
-set(VALIDATION_DATA_DIR "${CMAKE_SOURCE_DIR}/validation/data" CACHE PATH "location of generated validation data")
+set(NMC_VALIDATION_DATA_DIR "${PROJECT_SOURCE_DIR}/validation/data" CACHE PATH
+  "location of generated validation data")
 
+#----------------------------------------------------------
 # Whether to build validation data at all
-set(BUILD_VALIDATION_DATA ON CACHE BOOL "generate validation data")
+#----------------------------------------------------------
+option(NMC_BUILD_VALIDATION_DATA "generate validation data" ON)
 
 # Whether to attempt to use julia to build validation data
 find_program(JULIA_BIN julia)
 if(JULIA_BIN STREQUAL "JULIA_BIN-NOTFOUND")
     message(STATUS "julia not found; will not automatically build validation data sets from julia scripts")
-    set(BUILD_JULIA_VALIDATION_DATA FALSE)
+    set(NMC_BUILD_JULIA_VALIDATION_DATA FALSE)
 else()
-    set(BUILD_JULIA_VALIDATION_DATA TRUE)
+    set(NMC_BUILD_JULIA_VALIDATION_DATA TRUE)
 endif()
 
 # Whether to attempt to use nrniv to build validation data
@@ -166,23 +211,30 @@ endif()
 find_program(NRNIV_BIN nrniv)
 if(NRNIV_BIN STREQUAL "NRNIV_BIN-NOTFOUND")
     message(STATUS "nrniv not found; will not automatically build NEURON validation data sets")
-    set(BUILD_NRN_VALIDATION_DATA FALSE)
+    set(NMC_BUILD_NRN_VALIDATION_DATA FALSE)
 else()
-    set(BUILD_NRN_VALIDATION_DATA TRUE)
+    set(NMC_BUILD_NRN_VALIDATION_DATA TRUE)
 endif()
 
-include_directories(${CMAKE_SOURCE_DIR}/tclap)
-include_directories(${CMAKE_SOURCE_DIR}/include)
-include_directories(${CMAKE_SOURCE_DIR}/src)
-include_directories(${CMAKE_SOURCE_DIR}/miniapp)
-include_directories(${CMAKE_SOURCE_DIR}/modcc)
-include_directories(${CMAKE_SOURCE_DIR})
-if( "${WITH_TBB}" STREQUAL "ON" )
-    include_directories(${TBB_INCLUDE_DIRS})
+#----------------------------------------------------------
+# Setup include dirs
+#----------------------------------------------------------
+include_directories(
+    "${PROJECT_SOURCE_DIR}/tclap"
+    "${PROJECT_SOURCE_DIR}/include"
+    "${PROJECT_SOURCE_DIR}/src"
+    "${PROJECT_SOURCE_DIR}/miniapp"
+    "${PROJECT_SOURCE_DIR}/modcc"
+    "${PROJECT_SOURCE_DIR}")
+if(EXTERNAL_INCLUDES)
+  include_directories("${EXTERNAL_INCLUDES}")
 endif()
 
+#----------------------------------------------------------
+# Setup subdirs
+#----------------------------------------------------------
 # only include validation data if flag is set
-if(BUILD_VALIDATION_DATA)
+if(NMC_BUILD_VALIDATION_DATA)
     add_subdirectory(validation)
 endif()
 
diff --git a/README.md b/README.md
index ba282f78..3f11b5cd 100644
--- a/README.md
+++ b/README.md
@@ -41,13 +41,13 @@ cd tests
 
 ## MPI
 
-Set the `WITH_MPI` option either via the ccmake interface, or via the command line as shown below.
+Set the `NMC_WITH_MPI` option either via the ccmake interface, or via the command line as shown below.
 To ensure that CMake detects MPI correctly, you should specify the MPI wrapper for the compiler by setting the `CXX` and `CC` environment variables.
 
 ```
 export CXX=mpicxx
 export CC=mpicc
-cmake <path to CMakeLists.txt> -DWITH_MPI=ON
+cmake <path to CMakeLists.txt> -DNMC_WITH_MPI=ON
 ```
 
 ## TBB
@@ -58,7 +58,7 @@ The scripts set the `TBB_ROOT` environment variable, which is used by the CMake
 
 ```
 source <path to TBB installation>/tbbvars.sh
-cmake <path to CMakeLists.txt> -DWITH_TBB=ON
+cmake <path to CMakeLists.txt> -DNMC_THREADING_MODEL=tbb
 ```
 
 ### TBB on Cray systems
@@ -82,10 +82,10 @@ export CXX=`which CC`
 export CC=`which cc`
 
 # multithreading only
-cmake <path to CMakeLists.txt> -DWITH_TBB=ON -DSYSTEM_CRAY=ON
+cmake <path to CMakeLists.txt> -DNMC_THREADING_MODEL=tbb -DSYSTEM_CRAY=ON
 
 # multithreading and MPI
-cmake <path to CMakeLists.txt> -DWITH_TBB=ON -DWITH_MPI=ON -DSYSTEM_CRAY=ON
+cmake <path to CMakeLists.txt> -DNMC_THREADING_MODEL=tbb -DNMC_WITH_MPI=ON -DSYSTEM_CRAY=ON
 ```
 
 ## targeting KNL
@@ -143,18 +143,18 @@ cd build_knl
 # run cmake with all the magic flags
 export CC=`which icc`
 export CXX=`which icpc`
-cmake <path to CMakeLists.txt> -DCMAKE_BUILD_TYPE=release -DWITH_TBB=ON -DWITH_PROFILING=ON -DVECTORIZE_TARGET=KNL -DUSE_OPTIMIZED_KERNELS=ON
+cmake <path to CMakeLists.txt> -DCMAKE_BUILD_TYPE=release -DNMC_THREADING_MODEL=tbb -DNMC_WITH_PROFILING=ON -DNMC_VECTORIZE_TARGET=KNL -DNMC_USE_OPTIMIZED_KERNELS=ON
 make -j
 ```
 
 The flags passed into cmake are described:
   - `-DCMAKE_BUILD_TYPE=release` : build in release mode with `-O3`.
-  - `-WITH_TBB=ON` : use TBB for threading on multi-core
-  - `-DWITH_PROFILING=ON` : use internal profilers that print profiling report at end
-  - `-DVECTORIZE_TARGET=KNL` : generate AVX512 instructions, alternatively you can use:
+  - `-DNMC_THREADING_MODEL=tbb` : use TBB for threading on multi-core
+  - `-DNMC_WITH_PROFILING=ON` : use internal profilers that print profiling report at end
+  - `-DNMC_VECTORIZE_TARGET=KNL` : generate AVX512 instructions, alternatively you can use:
     - `AVX2` for Haswell & Broadwell
     - `AVX` for Sandy Bridge and Ivy Bridge
-  - `-DUSE_OPTIMIZED_KERNELS=ON` : tell the source to source compiler to generate optimized kernels that use Intel extensions
+  - `-DNMC_USE_OPTIMIZED_KERNELS=ON` : tell the source to source compiler to generate optimized kernels that use Intel extensions
     - without these vectorized code will not be generated.
 
 #### run tests
diff --git a/mechanisms/CMakeLists.txt b/mechanisms/CMakeLists.txt
index 71c4643f..10fdae9e 100644
--- a/mechanisms/CMakeLists.txt
+++ b/mechanisms/CMakeLists.txt
@@ -4,7 +4,7 @@ include(BuildModules.cmake)
 set(mechanisms pas hh expsyn exp2syn)
 
 set(modcc_opt)
-if(USE_OPTIMIZED_KERNELS) # generate optimized kernels
+if(NMC_USE_OPTIMIZED_KERNELS) # generate optimized kernels
     set(modcc_opt "-O")
 endif()
 
@@ -20,7 +20,7 @@ build_modules(
     TARGET build_all_mods
 )
 
-if(WITH_CUDA)
+if(NMC_WITH_CUDA)
     set(mech_dir "${CMAKE_CURRENT_SOURCE_DIR}/gpu")
     file(MAKE_DIRECTORY "${mech_dir}")
     build_modules(
diff --git a/miniapp/CMakeLists.txt b/miniapp/CMakeLists.txt
index 73fecd73..65973201 100644
--- a/miniapp/CMakeLists.txt
+++ b/miniapp/CMakeLists.txt
@@ -11,7 +11,7 @@ set(MINIAPP_SOURCES_CUDA
     miniapp_recipes.cpp
 )
 
-if(WITH_CUDA)
+if(NMC_WITH_CUDA)
     cuda_add_executable(miniapp.exe ${MINIAPP_SOURCES_CUDA} ${HEADERS})
     target_link_libraries(miniapp.exe LINK_PUBLIC gpu)
 else()
@@ -21,7 +21,7 @@ endif()
 target_link_libraries(miniapp.exe LINK_PUBLIC nestmc)
 target_link_libraries(miniapp.exe LINK_PUBLIC ${EXTERNAL_LIBRARIES})
 
-if(WITH_MPI)
+if(NMC_WITH_MPI)
     target_link_libraries(miniapp.exe LINK_PUBLIC ${MPI_C_LIBRARIES})
     set_property(TARGET miniapp.exe APPEND_STRING PROPERTY LINK_FLAGS "${MPI_C_LINK_FLAGS}")
 endif()
diff --git a/miniapp/miniapp.cpp b/miniapp/miniapp.cpp
index 64a009af..6094631b 100644
--- a/miniapp/miniapp.cpp
+++ b/miniapp/miniapp.cpp
@@ -29,7 +29,7 @@
 using namespace nest::mc;
 
 using global_policy = communication::global_policy;
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
 using lowered_cell = fvm::fvm_multicell<gpu::backend>;
 #else
 using lowered_cell = fvm::fvm_multicell<multicore::backend>;
@@ -181,7 +181,7 @@ void banner() {
     std::cout << "  starting miniapp\n";
     std::cout << "  - " << threading::description() << " threading support\n";
     std::cout << "  - communication policy: " << global_policy::name() << "\n";
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
     std::cout << "  - gpu support: on\n";
 #else
     std::cout << "  - gpu support: off\n";
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 22f0fa32..09a61691 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -16,14 +16,17 @@ set(CUDA_SOURCES
     memory/fill.cu
 )
 
-if(${WITH_MPI})
+if(NMC_WITH_MPI)
     set(BASE_SOURCES ${BASE_SOURCES} communication/mpi.cpp)
 endif()
 
 add_library(nestmc ${BASE_SOURCES} ${HEADERS})
 
-add_dependencies(nestmc build_all_mods)
-if(WITH_CUDA)
+if (NMC_AUTO_RUN_MODCC_ON_CHANGES)
+  add_dependencies(nestmc build_all_mods)
+endif()
+
+if(NMC_WITH_CUDA)
     cuda_add_library(gpu ${CUDA_SOURCES})
     set(NESTMC_LIBRARIES ${NESTMC_LIBRARIES} gpu)
     add_dependencies(gpu build_all_gpu_mods)
diff --git a/src/backends/fvm.hpp b/src/backends/fvm.hpp
index 6ccf0e3d..1cdc16d6 100644
--- a/src/backends/fvm.hpp
+++ b/src/backends/fvm.hpp
@@ -2,6 +2,6 @@
 
 #include "fvm_multicore.hpp"
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
     #include "fvm_gpu.hpp"
 #endif
diff --git a/src/communication/global_policy.hpp b/src/communication/global_policy.hpp
index b771e8ed..a36128df 100644
--- a/src/communication/global_policy.hpp
+++ b/src/communication/global_policy.hpp
@@ -1,6 +1,6 @@
 #pragma once
 
-#ifdef WITH_MPI
+#ifdef NMC_HAVE_MPI
     #include "communication/mpi_global_policy.hpp"
 #else
     #include "communication/serial_global_policy.hpp"
@@ -10,7 +10,7 @@ namespace nest {
 namespace mc {
 namespace communication {
 
-#ifdef WITH_MPI
+#ifdef NMC_HAVE_MPI
 using global_policy = nest::mc::communication::mpi_global_policy;
 #else
 using global_policy = nest::mc::communication::serial_global_policy;
diff --git a/src/communication/mpi_global_policy.hpp b/src/communication/mpi_global_policy.hpp
index d12beb63..b2b9dd7c 100644
--- a/src/communication/mpi_global_policy.hpp
+++ b/src/communication/mpi_global_policy.hpp
@@ -1,7 +1,7 @@
 #pragma once
 
-#ifndef WITH_MPI
-#error "mpi_global_policy.hpp should only be compiled in a WITH_MPI build"
+#ifndef NMC_HAVE_MPI
+#error "mpi_global_policy.hpp should only be compiled in a NMC_HAVE_MPI build"
 #endif
 
 #include <cstdint>
diff --git a/src/memory/allocator.hpp b/src/memory/allocator.hpp
index 7cce2613..dcba9267 100644
--- a/src/memory/allocator.hpp
+++ b/src/memory/allocator.hpp
@@ -2,7 +2,7 @@
 
 #include <limits>
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
 #include <cuda.h>
 #include <cuda_runtime.h>
 #endif
@@ -138,7 +138,7 @@ namespace impl {
     }
 #endif
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
     namespace cuda {
         template <size_type Alignment>
         class pinned_policy {
@@ -212,7 +212,7 @@ namespace impl {
             }
         };
     } // namespace cuda
-#endif // #ifdef WITH_CUDA
+#endif // #ifdef NMC_HAVE_CUDA
 } // namespace impl
 
 template<typename T, typename Policy >
@@ -286,7 +286,7 @@ namespace util {
         }
     };
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
     template <size_t Alignment>
     struct type_printer<impl::cuda::pinned_policy<Alignment>>{
         static std::string print() {
@@ -325,7 +325,7 @@ template <class T, size_t alignment=(512/8)>
 using hbw_allocator = allocator<T, impl::knl::hbw_policy<alignment>>;
 #endif
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
 // for pinned allocation set the default alignment to correspond to the
 // alignment of a page (4096 bytes), because pinned memory is allocated at page
 // boundaries.
diff --git a/src/memory/gpu.hpp b/src/memory/gpu.hpp
index f526c5a7..c0b7cef8 100644
--- a/src/memory/gpu.hpp
+++ b/src/memory/gpu.hpp
@@ -1,6 +1,6 @@
 #pragma once
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
 
 #include <string>
 #include <cstdint>
diff --git a/src/memory/host_coordinator.hpp b/src/memory/host_coordinator.hpp
index 13cf3d55..e9cb0698 100644
--- a/src/memory/host_coordinator.hpp
+++ b/src/memory/host_coordinator.hpp
@@ -11,7 +11,7 @@
 #include "allocator.hpp"
 #include "util.hpp"
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
 #include "gpu.hpp"
 #endif
 
@@ -23,7 +23,7 @@ namespace memory {
 template <typename T, class Allocator>
 class host_coordinator;
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
 template <typename T, class Allocator>
 class device_coordinator;
 #endif
@@ -124,7 +124,7 @@ public:
         std::copy(from.begin(), from.end(), to.begin());
     }
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
     // copy memory from device to host
     template <class Alloc>
     void copy(
diff --git a/src/memory/memory.hpp b/src/memory/memory.hpp
index cb96e739..e5261958 100644
--- a/src/memory/memory.hpp
+++ b/src/memory/memory.hpp
@@ -6,7 +6,7 @@
 #include "definitions.hpp"
 #include "host_coordinator.hpp"
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
 #include "device_coordinator.hpp"
 #endif
 
@@ -29,7 +29,7 @@ std::ostream& operator<< (std::ostream& o, host_view<T> const& v) {
     return o;
 }
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
 // specialization for pinned vectors. Use a host_coordinator, because memory is
 // in the host memory space, and all of the helpers (copy, set, etc) are the
 // same with and without page locked memory
diff --git a/src/memory/wrappers.hpp b/src/memory/wrappers.hpp
index 1d7f9861..ab463a23 100644
--- a/src/memory/wrappers.hpp
+++ b/src/memory/wrappers.hpp
@@ -5,7 +5,7 @@
 
 #include <memory/memory.hpp>
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
 #include <cuda.h>
 #include <cuda_runtime.h>
 #endif
@@ -96,7 +96,7 @@ namespace util {
         return is_on_host<typename std::decay<T>::type>::value;
     }
 
-    #ifdef WITH_CUDA
+    #ifdef NMC_HAVE_CUDA
     template <typename T>
     struct is_on_gpu : std::false_type {};
 
@@ -132,7 +132,7 @@ auto on_host(const C& c) -> decltype(make_const_view(c)) {
     return make_const_view(c);
 }
 
-#ifdef WITH_CUDA
+#ifdef NMC_HAVE_CUDA
 template <
     typename C,
     typename = typename std::enable_if<util::is_on_gpu_v<C>()>::type
diff --git a/src/profiling/profiler.cpp b/src/profiling/profiler.cpp
index 90af76af..896e7bcf 100644
--- a/src/profiling/profiler.cpp
+++ b/src/profiling/profiler.cpp
@@ -1,6 +1,6 @@
 #include <numeric>
 
-#ifdef WITH_GPU
+#ifdef NMC_HAVE_GPU
     #include <cuda_profiler_api.h>
 #endif
 
@@ -23,7 +23,7 @@ namespace util {
 // profiler.
 // It is a simple wrapper around the API calls with a mutex to ensure correct
 // behaviour when multiple threads attempt to start or stop the profiler.
-#ifdef WITH_GPU
+#ifdef NMC_HAVE_GPU
 namespace gpu {
     bool is_running_nvprof = false;
     std::mutex gpu_profiler_mutex;
@@ -303,7 +303,7 @@ profiler_node profiler::performance_tree() {
 }
 
 
-#ifdef WITH_PROFILING
+#ifdef NMC_HAVE_PROFILING
 namespace data {
     profiler_wrapper profilers_(profiler("root"));
 }
diff --git a/src/profiling/profiler.hpp b/src/profiling/profiler.hpp
index 2db847f9..b000de67 100644
--- a/src/profiling/profiler.hpp
+++ b/src/profiling/profiler.hpp
@@ -203,7 +203,7 @@ private:
     region_type* current_region_ = &root_region_;
 };
 
-#ifdef WITH_PROFILING
+#ifdef NMC_HAVE_PROFILING
 namespace data {
     using profiler_wrapper = nest::mc::threading::enumerable_thread_specific<profiler>;
     extern profiler_wrapper profilers_;
@@ -226,7 +226,7 @@ void profiler_enter(const char* n);
 /// enter nested profiler regions in a single call
 template <class...Args>
 void profiler_enter(const char* n, Args... args) {
-#ifdef WITH_PROFILING
+#ifdef NMC_HAVE_PROFILING
     get_profiler().enter(n);
     profiler_enter(args...);
 #endif
diff --git a/src/threading/omp.hpp b/src/threading/omp.hpp
index ad43e82b..d056e6b5 100644
--- a/src/threading/omp.hpp
+++ b/src/threading/omp.hpp
@@ -1,7 +1,7 @@
 #pragma once
 
-#if !defined(WITH_OMP)
-    #error "this header can only be loaded if WITH_OMP is set"
+#if !defined(NMC_HAVE_OMP)
+    #error "this header can only be loaded if NMC_HAVE_OMP is set"
 #endif
 
 #include <omp.h>
diff --git a/src/threading/serial.hpp b/src/threading/serial.hpp
index de9e3180..b8b51009 100644
--- a/src/threading/serial.hpp
+++ b/src/threading/serial.hpp
@@ -1,7 +1,7 @@
 #pragma once
 
-#if !defined(WITH_SERIAL)
-    #error "this header can only be loaded if WITH_SERIAL is set"
+#if !defined(NMC_HAVE_SERIAL)
+    #error "this header can only be loaded if NMC_HAVE_SERIAL is set"
 #endif
 
 #include <algorithm>
diff --git a/src/threading/tbb.hpp b/src/threading/tbb.hpp
index 91a7b59b..1156bf4b 100644
--- a/src/threading/tbb.hpp
+++ b/src/threading/tbb.hpp
@@ -1,7 +1,7 @@
 #pragma once
 
-#if !defined(WITH_TBB)
-    #error this header can only be loaded if WITH_TBB is set
+#if !defined(NMC_HAVE_TBB)
+    #error this header can only be loaded if NMC_HAVE_TBB is set
 #endif
 
 #include <string>
diff --git a/src/threading/threading.hpp b/src/threading/threading.hpp
index 26b2bace..157b936a 100644
--- a/src/threading/threading.hpp
+++ b/src/threading/threading.hpp
@@ -1,11 +1,11 @@
 #pragma once
 
-#if defined(WITH_TBB)
+#if defined(NMC_HAVE_TBB)
     #include "tbb.hpp"
-#elif defined(WITH_OMP)
+#elif defined(NMC_HAVE_OMP)
     #include "omp.hpp"
 #else
-    #define WITH_SERIAL
+    #define NMC_HAVE_SERIAL
     #include "serial.hpp"
 #endif
 
diff --git a/src/util/debug.hpp b/src/util/debug.hpp
index b2c39e49..c2945e29 100644
--- a/src/util/debug.hpp
+++ b/src/util/debug.hpp
@@ -62,13 +62,13 @@ void debug_emit_trace(const char* file, int line, const char* varlist, const Arg
 } // namespace mc
 } // namespace nest
 
-#ifdef WITH_TRACE
+#ifdef NMC_HAVE_TRACE
     #define TRACE(vars...) nest::mc::util::debug_emit_trace(__FILE__, __LINE__, #vars, ##vars)
 #else
     #define TRACE(...)
 #endif
 
-#ifdef WITH_ASSERTIONS
+#ifdef NMC_HAVE_ASSERTIONS
     #ifdef __GNUC__
         #define DEBUG_FUNCTION_NAME __PRETTY_FUNCTION__
     #else
@@ -81,4 +81,4 @@ void debug_emit_trace(const char* file, int line, const char* varlist, const Arg
 #else
     #define EXPECTS(condition) \
        (void)(false && (condition))
-#endif // def WITH_ASSERTIONS
+#endif // def NMC_HAVE_ASSERTIONS
diff --git a/src/util/range.hpp b/src/util/range.hpp
index 6c161fda..6df51e35 100644
--- a/src/util/range.hpp
+++ b/src/util/range.hpp
@@ -26,7 +26,7 @@
 #include <type_traits>
 #include <utility>
 
-#ifdef WITH_TBB
+#ifdef NMC_HAVE_TBB
 #include <tbb/tbb_stddef.h>
 #endif
 
@@ -109,7 +109,7 @@ struct range {
         return (*this)[n];
     }
 
-#ifdef WITH_TBB
+#ifdef NMC_HAVE_TBB
     template <
         typename V = iterator,
         typename = enable_if_t<is_forward_iterator<V>::value>
diff --git a/tests/global_communication/CMakeLists.txt b/tests/global_communication/CMakeLists.txt
index 723e5902..8e66b9af 100644
--- a/tests/global_communication/CMakeLists.txt
+++ b/tests/global_communication/CMakeLists.txt
@@ -18,7 +18,7 @@ foreach(target ${TARGETS})
     target_link_libraries(${target} LINK_PUBLIC nestmc gtest)
     target_link_libraries(${target} LINK_PUBLIC ${EXTERNAL_LIBRARIES})
 
-    if(WITH_MPI)
+    if(NMC_WITH_MPI)
         target_link_libraries(${target} LINK_PUBLIC ${MPI_C_LIBRARIES})
         set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS "${MPI_C_LINK_FLAGS}")
     endif()
diff --git a/tests/global_communication/test_mpi_gather_all.cpp b/tests/global_communication/test_mpi_gather_all.cpp
index f67df15a..07c5a6d1 100644
--- a/tests/global_communication/test_mpi_gather_all.cpp
+++ b/tests/global_communication/test_mpi_gather_all.cpp
@@ -1,4 +1,4 @@
-#ifdef WITH_MPI
+#ifdef NMC_HAVE_MPI
 
 #include "../gtest.h"
 
@@ -97,4 +97,4 @@ TEST(mpi, gather_all_with_partition) {
     EXPECT_EQ(expected_divisions, gathered.partition());
 }
 
-#endif // WITH_MPI
+#endif // NMC_HAVE_MPI
diff --git a/tests/modcc/CMakeLists.txt b/tests/modcc/CMakeLists.txt
index 40c35687..bb27815a 100644
--- a/tests/modcc/CMakeLists.txt
+++ b/tests/modcc/CMakeLists.txt
@@ -15,7 +15,7 @@ set(MODCC_TEST_SOURCES
     expr_expand.cpp
 )
 
-add_definitions("-DDATADIR=\"${CMAKE_SOURCE_DIR}/data\"")
+add_definitions("-DDATADIR=\"${PROJECT_SOURCE_DIR}/data\"")
 add_executable(test_modcc ${MODCC_TEST_SOURCES})
 
 target_link_libraries(test_modcc LINK_PUBLIC compiler gtest)
diff --git a/tests/performance/io/CMakeLists.txt b/tests/performance/io/CMakeLists.txt
index 4d4b3a5a..0d9b1b1e 100644
--- a/tests/performance/io/CMakeLists.txt
+++ b/tests/performance/io/CMakeLists.txt
@@ -10,7 +10,7 @@ add_executable(disk_io.exe ${DISK_IO_SOURCES} ${HEADERS})
 target_link_libraries(disk_io.exe LINK_PUBLIC nestmc)
 target_link_libraries(disk_io.exe LINK_PUBLIC ${EXTERNAL_LIBRARIES})
 
-if(WITH_MPI)
+if(NMC_WITH_MPI)
     target_link_libraries(disk_io.exe LINK_PUBLIC ${MPI_C_LIBRARIES})
     set_property(TARGET disk_io.exe APPEND_STRING PROPERTY LINK_FLAGS "${MPI_C_LINK_FLAGS}")
 endif()
diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt
index b211b296..9a72b1b9 100644
--- a/tests/unit/CMakeLists.txt
+++ b/tests/unit/CMakeLists.txt
@@ -1,4 +1,4 @@
-include(${CMAKE_SOURCE_DIR}/mechanisms/BuildModules.cmake)
+include(${PROJECT_SOURCE_DIR}/mechanisms/BuildModules.cmake)
 
 # Build prototype mechanisms for testing in test_mechanisms.
 set(proto_mechanisms pas hh expsyn exp2syn)
@@ -7,7 +7,7 @@ file(MAKE_DIRECTORY "${mech_proto_dir}")
 
 build_modules(
     ${proto_mechanisms}
-    SOURCE_DIR "${CMAKE_SOURCE_DIR}/mechanisms/mod"
+    SOURCE_DIR "${PROJECT_SOURCE_DIR}/mechanisms/mod"
     DEST_DIR "${mech_proto_dir}"
     MECH_SUFFIX _proto
     MODCC_FLAGS -t cpu
@@ -67,15 +67,19 @@ set(TEST_SOURCES
     test.cpp
 )
 
-add_definitions("-DDATADIR=\"${CMAKE_SOURCE_DIR}/data\"")
+add_definitions("-DDATADIR=\"${PROJECT_SOURCE_DIR}/data\"")
 
 set(TARGETS test.exe)
 
 add_executable(test.exe ${TEST_SOURCES} ${HEADERS})
-add_dependencies(test.exe build_test_mods)
+
+if (NMC_AUTO_RUN_MODCC_ON_CHANGES)
+  add_dependencies(test.exe build_test_mods)
+endif()
+
 target_include_directories(test.exe PRIVATE "${mech_proto_dir}/..")
 
-if(WITH_CUDA)
+if(NMC_WITH_CUDA)
     set(TARGETS ${TARGETS} test_cuda.exe)
     cuda_add_executable(test_cuda.exe ${TEST_CUDA_SOURCES} ${HEADERS})
     target_link_libraries(test_cuda.exe LINK_PUBLIC gpu)
@@ -85,7 +89,7 @@ foreach(target ${TARGETS})
     target_link_libraries(${target} LINK_PUBLIC gtest nestmc)
     target_link_libraries(${target} LINK_PUBLIC ${EXTERNAL_LIBRARIES})
 
-    if(WITH_MPI)
+    if(NMC_WITH_MPI)
         target_link_libraries(${target} LINK_PUBLIC ${MPI_C_LIBRARIES})
         set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS "${MPI_C_LINK_FLAGS}")
     endif()
diff --git a/tests/unit/test_range.cpp b/tests/unit/test_range.cpp
index d49430ae..fa2458fa 100644
--- a/tests/unit/test_range.cpp
+++ b/tests/unit/test_range.cpp
@@ -7,7 +7,7 @@
 #include <numeric>
 #include <type_traits>
 
-#ifdef WITH_TBB
+#ifdef NMC_HAVE_TBB
 #include <tbb/tbb_stddef.h>
 #endif
 
@@ -423,7 +423,7 @@ TEST(range, all_of_any_of) {
     EXPECT_TRUE(util::any_of(cstr("87654x"), pred));
 }
 
-#ifdef WITH_TBB
+#ifdef NMC_HAVE_TBB
 
 TEST(range, tbb_split) {
     constexpr std::size_t N = 20;
diff --git a/tests/validation/CMakeLists.txt b/tests/validation/CMakeLists.txt
index d9e16533..f7e9f849 100644
--- a/tests/validation/CMakeLists.txt
+++ b/tests/validation/CMakeLists.txt
@@ -27,14 +27,14 @@ set(VALIDATION_CUDA_SOURCES
     validate.cpp
 )
 
-if(VALIDATION_DATA_DIR)
-    add_definitions("-DDATADIR=\"${VALIDATION_DATA_DIR}\"")
+if(NMC_VALIDATION_DATA_DIR)
+    add_definitions("-DDATADIR=\"${NMC_VALIDATION_DATA_DIR}\"")
 endif()
 
 add_executable(validate.exe ${VALIDATION_SOURCES})
 set(TARGETS validate.exe)
 
-if(WITH_CUDA)
+if(NMC_WITH_CUDA)
     cuda_add_executable(validate_cuda.exe ${VALIDATION_CUDA_SOURCES})
     list(APPEND TARGETS validate_cuda.exe)
     target_link_libraries(validate_cuda.exe LINK_PUBLIC gpu)
@@ -46,7 +46,7 @@ foreach(target ${TARGETS})
 
     target_link_libraries(${target} LINK_PUBLIC ${EXTERNAL_LIBRARIES})
 
-    if(WITH_MPI)
+    if(NMC_WITH_MPI)
         target_link_libraries(${target} LINK_PUBLIC ${MPI_C_LIBRARIES})
         set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS "${MPI_C_LINK_FLAGS}")
     endif()
@@ -57,7 +57,7 @@ foreach(target ${TARGETS})
         RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
     )
 
-    if(BUILD_VALIDATION_DATA)
+    if(NMC_BUILD_VALIDATION_DATA)
         add_dependencies(${target} validation_data)
     endif()
 endforeach()
diff --git a/validation/CMakeLists.txt b/validation/CMakeLists.txt
index 99b4bec9..b65c4fcf 100644
--- a/validation/CMakeLists.txt
+++ b/validation/CMakeLists.txt
@@ -28,7 +28,7 @@ endfunction()
 include(CMakeParseArguments)
 function(add_validation_data)
     cmake_parse_arguments(ADD_VALIDATION_DATA "" "OUTPUT" "DEPENDS;COMMAND" ${ARGN})
-    set(out "${VALIDATION_DATA_DIR}/${ADD_VALIDATION_DATA_OUTPUT}")
+    set(out "${NMC_VALIDATION_DATA_DIR}/${ADD_VALIDATION_DATA_OUTPUT}")
     string(REGEX REPLACE "([^;]+)" "${CMAKE_CURRENT_SOURCE_DIR}/\\1" deps "${ADD_VALIDATION_DATA_DEPENDS}")
     add_custom_command(
         OUTPUT "${out}"
@@ -43,7 +43,7 @@ function(add_validation_data)
 endfunction()
 
 
-if(BUILD_NRN_VALIDATION_DATA)
+if(NMC_BUILD_NRN_VALIDATION_DATA)
     add_subdirectory(ref/neuron)
 endif()
 
diff --git a/validation/ref/numeric/CMakeLists.txt b/validation/ref/numeric/CMakeLists.txt
index ddb5001f..4a86db71 100644
--- a/validation/ref/numeric/CMakeLists.txt
+++ b/validation/ref/numeric/CMakeLists.txt
@@ -1,6 +1,6 @@
 # note: function add_validation_data defined in validation/CMakeLists.txt
 
-if(BUILD_JULIA_VALIDATION_DATA)
+if(NMC_BUILD_JULIA_VALIDATION_DATA)
     add_validation_data(
         OUTPUT numeric_soma.json
         DEPENDS numeric_soma.jl HHChannels.jl
-- 
GitLab