build: CMake refactoring
Includes:
- refactor build_lib and build_lib_example macros
- unify src and contrib macros
- replace macro with function not to leak definitions
- parse list of arguments
- different cmake-format file for modules to list one item per line
This commit is contained in:
@@ -1,23 +1,35 @@
|
||||
# Set module name
|
||||
set(name core)
|
||||
|
||||
# Set lib core link dependencies
|
||||
set(libraries_to_link)
|
||||
|
||||
set(gsl_test_sources)
|
||||
if(${GSL_FOUND})
|
||||
include_directories(${GSL_INCLUDE_DIRS})
|
||||
set(libraries_to_link ${libraries_to_link} ${GSL_LIBRARIES})
|
||||
set(gsl_test_sources test/rng-test-suite.cc
|
||||
test/random-variable-stream-test-suite.cc
|
||||
set(libraries_to_link
|
||||
${libraries_to_link}
|
||||
${GSL_LIBRARIES}
|
||||
)
|
||||
set(gsl_test_sources
|
||||
test/rng-test-suite.cc
|
||||
test/random-variable-stream-test-suite.cc
|
||||
)
|
||||
endif()
|
||||
|
||||
# Check for dependencies and add sources accordingly
|
||||
check_include_file_cxx("boost/units/quantity.hpp" HAVE_BOOST_UNITS_QUANTITY)
|
||||
check_include_file_cxx("boost/units/systems/si.hpp" HAVE_BOOST_UNITS_SI)
|
||||
if(${HAVE_BOOST_UNITS_QUANTITY} AND ${HAVE_BOOST_UNITS_SI})
|
||||
add_definitions(-DHAVE_BOOST -DHAVE_BOOST_UNITS)
|
||||
check_include_file_cxx(
|
||||
"boost/units/quantity.hpp"
|
||||
HAVE_BOOST_UNITS_QUANTITY
|
||||
)
|
||||
check_include_file_cxx(
|
||||
"boost/units/systems/si.hpp"
|
||||
HAVE_BOOST_UNITS_SI
|
||||
)
|
||||
if(${HAVE_BOOST_UNITS_QUANTITY}
|
||||
AND ${HAVE_BOOST_UNITS_SI}
|
||||
)
|
||||
add_definitions(
|
||||
-DHAVE_BOOST
|
||||
-DHAVE_BOOST_UNITS
|
||||
)
|
||||
message(STATUS "Boost Units have been found.")
|
||||
else()
|
||||
message(
|
||||
@@ -28,28 +40,59 @@ else()
|
||||
)
|
||||
endif()
|
||||
|
||||
set(rt_sources model/realtime-simulator-impl.cc
|
||||
model/wall-clock-synchronizer.cc
|
||||
set(rt_sources
|
||||
model/realtime-simulator-impl.cc
|
||||
model/wall-clock-synchronizer.cc
|
||||
)
|
||||
set(rt_headers
|
||||
model/realtime-simulator-impl.h
|
||||
model/wall-clock-synchronizer.h
|
||||
)
|
||||
set(rt_headers model/realtime-simulator-impl.h model/wall-clock-synchronizer.h)
|
||||
if(${ENABLE_REALTIME})
|
||||
set(libraries_to_link ${libraries_to_link} ${LIBRT})
|
||||
set(libraries_to_link
|
||||
${libraries_to_link}
|
||||
${LIBRT}
|
||||
)
|
||||
endif()
|
||||
|
||||
set(osclock_sources)
|
||||
set(osclock_sources model/unix-system-wall-clock-ms.cc)
|
||||
set(osclock_sources
|
||||
model/unix-system-wall-clock-ms.cc
|
||||
)
|
||||
|
||||
set(int64x64_sources)
|
||||
set(int64x64_headers)
|
||||
|
||||
if(${NS3_INT64X64} MATCHES "INT128")
|
||||
set(int64x64_sources model/int64x64-128.cc)
|
||||
set(int64x64_headers model/int64x64-128.h)
|
||||
elseif(${NS3_INT64X64} MATCHES "DOUBLE")
|
||||
set(int64x64_headers model/int64x64-double.h)
|
||||
elseif(${NS3_INT64X64} MATCHES "CAIRO")
|
||||
set(int64x64_sources model/int64x64-cairo.cc)
|
||||
set(int64x64_headers model/int64x64-cairo.h model/cairo-wideint-private.h)
|
||||
if(${NS3_INT64X64}
|
||||
MATCHES
|
||||
"INT128"
|
||||
)
|
||||
set(int64x64_sources
|
||||
model/int64x64-128.cc
|
||||
)
|
||||
set(int64x64_headers
|
||||
model/int64x64-128.h
|
||||
)
|
||||
elseif(
|
||||
${NS3_INT64X64}
|
||||
MATCHES
|
||||
"DOUBLE"
|
||||
)
|
||||
set(int64x64_headers
|
||||
model/int64x64-double.h
|
||||
)
|
||||
elseif(
|
||||
${NS3_INT64X64}
|
||||
MATCHES
|
||||
"CAIRO"
|
||||
)
|
||||
set(int64x64_sources
|
||||
model/int64x64-cairo.cc
|
||||
)
|
||||
set(int64x64_headers
|
||||
model/int64x64-cairo.h
|
||||
model/cairo-wideint-private.h
|
||||
)
|
||||
endif()
|
||||
|
||||
set(thread_sources)
|
||||
@@ -58,33 +101,57 @@ set(thread_test_sources)
|
||||
|
||||
if(${NS3_PTHREAD})
|
||||
if(${THREADS_FOUND})
|
||||
set(thread_sources model/unix-fd-reader.cc)
|
||||
set(thread_headers model/unix-fd-reader.h)
|
||||
set(thread_sources
|
||||
${thread_sources} model/system-thread.cc model/unix-system-mutex.cc
|
||||
model/unix-fd-reader.cc
|
||||
)
|
||||
set(thread_headers
|
||||
model/unix-fd-reader.h
|
||||
)
|
||||
set(thread_sources
|
||||
${thread_sources}
|
||||
model/system-thread.cc
|
||||
model/unix-system-mutex.cc
|
||||
model/unix-system-condition.cc
|
||||
)
|
||||
|
||||
set(thread_headers ${thread_headers} model/system-mutex.h
|
||||
model/system-thread.h model/system-condition.h
|
||||
set(thread_headers
|
||||
${thread_headers}
|
||||
model/system-mutex.h
|
||||
model/system-thread.h
|
||||
model/system-condition.h
|
||||
)
|
||||
set(libraries_to_link
|
||||
${libraries_to_link}
|
||||
pthread
|
||||
)
|
||||
set(thread_test_sources
|
||||
test/threaded-test-suite.cc
|
||||
)
|
||||
set(libraries_to_link ${libraries_to_link} pthread)
|
||||
set(thread_test_sources test/threaded-test-suite.cc)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(${ENABLE_EXAMPLES})
|
||||
set(example_as_test_sources model/example-as-test.cc)
|
||||
set(example_as_test_headers model/example-as-test.h)
|
||||
set(example_as_test_suite test/examples-as-tests-test-suite.cc)
|
||||
set(example_as_test_sources
|
||||
model/example-as-test.cc
|
||||
)
|
||||
set(example_as_test_headers
|
||||
model/example-as-test.h
|
||||
)
|
||||
set(example_as_test_suite
|
||||
test/examples-as-tests-test-suite.cc
|
||||
)
|
||||
endif()
|
||||
|
||||
# Embedded version support
|
||||
set(embedded_version_sources)
|
||||
set(embedded_version_headers)
|
||||
if(${NS3_ENABLE_BUILD_VERSION})
|
||||
set(embedded_version_sources model/version.cc)
|
||||
set(embedded_version_headers model/version.h)
|
||||
set(embedded_version_sources
|
||||
model/version.cc
|
||||
)
|
||||
set(embedded_version_headers
|
||||
model/version.h
|
||||
)
|
||||
endif()
|
||||
|
||||
# Define core lib sources
|
||||
@@ -298,6 +365,10 @@ set(test_sources
|
||||
)
|
||||
|
||||
# Build core lib
|
||||
build_lib("${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
"${test_sources}"
|
||||
build_lib(
|
||||
LIBNAME core
|
||||
SOURCE_FILES ${source_files}
|
||||
HEADER_FILES ${header_files}
|
||||
LIBRARIES_TO_LINK ${libraries_to_link}
|
||||
TEST_SOURCES ${test_sources}
|
||||
)
|
||||
|
||||
@@ -1,139 +1,58 @@
|
||||
set(name main-callback)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
set(base_examples
|
||||
command-line-example
|
||||
fatal-example
|
||||
hash-example
|
||||
length-example
|
||||
main-callback
|
||||
main-ptr
|
||||
sample-log-time-format
|
||||
sample-random-variable
|
||||
sample-random-variable-stream
|
||||
sample-show-progress
|
||||
sample-simulator
|
||||
system-path-examples
|
||||
test-string-value-formatting
|
||||
)
|
||||
|
||||
set(name sample-simulator)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
foreach(
|
||||
example
|
||||
${base_examples}
|
||||
)
|
||||
build_lib_example(
|
||||
NAME ${example}
|
||||
SOURCE_FILES ${example}.cc
|
||||
LIBRARIES_TO_LINK ${libcore}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
set(name main-ptr)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
)
|
||||
|
||||
set(name main-random-variable-stream)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore} ${libconfig-store} ${libstats})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
)
|
||||
|
||||
set(name sample-random-variable)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
)
|
||||
|
||||
set(name sample-random-variable-stream)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
)
|
||||
|
||||
set(name command-line-example)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
)
|
||||
|
||||
set(name fatal-example)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
)
|
||||
|
||||
set(name hash-example)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
)
|
||||
|
||||
set(name sample-log-time-format)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
)
|
||||
|
||||
set(name test-string-value-formatting)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
)
|
||||
|
||||
set(name sample-show-progress)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
NAME main-random-variable-stream
|
||||
SOURCE_FILES main-random-variable-stream.cc
|
||||
LIBRARIES_TO_LINK
|
||||
${libcore}
|
||||
${libconfig-store}
|
||||
${libstats}
|
||||
)
|
||||
|
||||
if(${NS3_ENABLE_BUILD_VERSION})
|
||||
set(name build-version-example)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
NAME build-version-example
|
||||
SOURCE_FILES build-version-example.cc
|
||||
LIBRARIES_TO_LINK ${libcore}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(${ENABLE_REALTIME})
|
||||
set(name main-test-sync)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libnetwork})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
NAME main-test-sync
|
||||
SOURCE_FILES main-test-sync.cc
|
||||
LIBRARIES_TO_LINK ${libnetwork}
|
||||
)
|
||||
endif()
|
||||
|
||||
set(name length-example)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
)
|
||||
|
||||
set(name empirical-random-variable-example)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore} ${libflow-monitor})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
)
|
||||
|
||||
set(name system-path-examples)
|
||||
set(source_files ${name}.cc)
|
||||
set(header_files)
|
||||
set(libraries_to_link ${libcore})
|
||||
build_lib_example(
|
||||
"${name}" "${source_files}" "${header_files}" "${libraries_to_link}"
|
||||
NAME empirical-random-variable-example
|
||||
SOURCE_FILES empirical-random-variable-example.cc
|
||||
LIBRARIES_TO_LINK ${libcore}
|
||||
${libflow-monitor}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user