Skip to content

Commit

Permalink
Merge C++ Std Test Source Files CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
iguessthislldo committed May 3, 2024
1 parent c69fdcf commit 6d4d51d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
7 changes: 0 additions & 7 deletions cmake/ace_cppstd.cpp

This file was deleted.

13 changes: 0 additions & 13 deletions cmake/cplusplus.cpp

This file was deleted.

23 changes: 16 additions & 7 deletions cmake/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,23 @@ function(_opendds_cxx_std_from_year out_var year)
endfunction()

function(_opendds_set_cxx_std)
set(cplusplus_values 201103 201402 201703 202002 202302)
set(test_cxx_std "${CMAKE_CURRENT_LIST_DIR}/test_cxx_std.cpp")
set(temp_dir "${CMAKE_CURRENT_BINARY_DIR}/opendds_test_cxx_std")
file(MAKE_DIRECTORY "${temp_dir}")

# Get the latest known default compiler C++ standard
set(default_cxx_std_year 1998)
set(cplusplus_values 201103 201402 201703 202002 202302)
foreach(cplusplus IN LISTS cplusplus_values)
set(args)
if(MSVC AND NOT MSVC_VERSION LESS 1914)
list(APPEND args CMAKE_FLAGS "-DCMAKE_CXX_FLAGS=/Zc:__cplusplus")
endif()
try_compile(compiled
"${CMAKE_CURRENT_BINARY_DIR}/opendds_test_cplusplus_${cplusplus}"
SOURCES "${CMAKE_CURRENT_LIST_DIR}/cplusplus.cpp"
"${temp_dir}/cplusplus_${cplusplus}"
SOURCES "${test_cxx_std}"
COMPILE_DEFINITIONS "-DOPENDDS_TEST_CPLUSPLUS=${cplusplus}L"
${args}
)
if(compiled)
_opendds_cplusplus_to_year(default_cxx_std_year ${cplusplus})
Expand Down Expand Up @@ -236,14 +245,13 @@ function(_opendds_set_cxx_std)
# What ACE 7+ requires depends on a check in ace/Global_Macros.h. We must
# compile against that header using each standard we know of until it
# compiles.
set(dir "${CMAKE_CURRENT_BINARY_DIR}/opendds_test_ace_cppstd")
set(includes "${ACE_INCLUDE_DIRS}")
if(NOT EXISTS "${ACE_INCLUDE_DIRS}/ace/config.h")
if(NOT ACE_IS_BEING_BUILT)
message(FATAL_ERROR "ACE doesn't have a config.h.")
endif()
# Won't compile without a config.h, so make a fake one.
set(include_dir "${dir}/include")
set(include_dir "${temp_dir}/include")
list(APPEND includes "${include_dir}")
set(ace_dir "${include_dir}/ace")
file(MAKE_DIRECTORY "${ace_dir}")
Expand All @@ -253,8 +261,9 @@ function(_opendds_set_cxx_std)
_opendds_cplusplus_to_year(try_year ${try_cplusplus})
_opendds_cxx_std_from_year(try_std ${try_year})
try_compile(compiled
"${dir}/${try_cplusplus}"
SOURCES "${CMAKE_CURRENT_LIST_DIR}/ace_cppstd.cpp"
"${temp_dir}/ace_cxx_std_${try_cplusplus}"
SOURCES "${test_cxx_std}"
COMPILE_DEFINITIONS "-DOPENDDS_TEST_ACE_CXX_STD"
CMAKE_FLAGS
"-DCMAKE_CXX_STANDARD=${try_std}"
"-DINCLUDE_DIRECTORIES=${includes}"
Expand Down
15 changes: 15 additions & 0 deletions cmake/test_cxx_std.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifdef OPENDDS_TEST_CPLUSPLUS
# if __cplusplus < OPENDDS_TEST_CPLUSPLUS
# error "Less then requested value"
# endif
#elif defined OPENDDS_TEST_ACE_CXX_STD
# define ACE_DOESNT_DEFINE_MAIN 1
# include <ace/Global_Macros.h>
#else
# error "No macro was defined!"
#endif

int main()
{
return 0;
}

0 comments on commit 6d4d51d

Please sign in to comment.