Skip to content

Commit a5426ea

Browse files
authored
CMake: Assume working c++ compiler (#597)
1 parent e45da76 commit a5426ea

File tree

3 files changed

+24
-39
lines changed

3 files changed

+24
-39
lines changed

CMakeLists.txt

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ endif ()
7777
include (CheckIncludeFiles)
7878
include (CheckFunctionExists)
7979
include (CheckTypeSize)
80-
include (CheckCCompilerFlag)
81-
include (CheckCXXSymbolExists)
8280
include (CheckCSourceCompiles)
8381

8482
#==============================================================================
@@ -140,20 +138,6 @@ if (WITH_THREADLOCAL AND NOT DEFINED THREADLOCAL)
140138
endforeach()
141139
endif ()
142140

143-
144-
if (NLOPT_CXX OR NLOPT_PYTHON OR NLOPT_GUILE OR NLOPT_OCTAVE OR NLOPT_JAVA)
145-
check_cxx_symbol_exists (__cplusplus ciso646 SYSTEM_HAS_CXX)
146-
if (SYSTEM_HAS_CXX)
147-
set (CMAKE_CXX_STANDARD 11) # set the standard to C++11 but do not require it
148-
149-
if (NLOPT_CXX)
150-
set (CMAKE_CXX_STANDARD_REQUIRED ON) # if we build C++ API, we do need C++11
151-
endif ()
152-
else()
153-
message (FATAL_ERROR "The compiler doesn't support CXX.")
154-
endif ()
155-
endif ()
156-
157141
#==============================================================================
158142
# CREATE nlopt_config.h
159143
#==============================================================================
@@ -260,6 +244,9 @@ if (M_LIBRARY)
260244
endif ()
261245
set_target_properties (${nlopt_lib} PROPERTIES SOVERSION ${SO_MAJOR})
262246
set_target_properties (${nlopt_lib} PROPERTIES VERSION "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}")
247+
if (NLOPT_CXX)
248+
target_compile_features (${nlopt_lib} PUBLIC cxx_lambdas)
249+
endif ()
263250

264251
#==============================================================================
265252
# INCLUDE DIRECTORIES

src/swig/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ endif ()
2121
include_directories (${NLOPT_PRIVATE_INCLUDE_DIRS})
2222
set_source_files_properties (nlopt.i PROPERTIES CPLUSPLUS ON)
2323

24-
if (Python_NumPy_FOUND)
24+
if (Python_NumPy_FOUND AND NLOPT_CXX)
2525

2626
set (SWIG_MODULE_nlopt_python_EXTRA_DEPS nlopt-python.i numpy.i generate-cpp)
2727

@@ -46,7 +46,7 @@ if (Python_NumPy_FOUND)
4646
endif ()
4747

4848

49-
if (GUILE_FOUND)
49+
if (GUILE_FOUND AND NLOPT_CXX)
5050

5151
set (SWIG_MODULE_nlopt_guile_EXTRA_DEPS nlopt-guile.i generate-cpp)
5252
set (CMAKE_SWIG_FLAGS -scmstub)
@@ -74,7 +74,7 @@ if (GUILE_FOUND)
7474
endif ()
7575

7676

77-
if (JNI_FOUND AND Java_FOUND AND SWIG_FOUND)
77+
if (JNI_FOUND AND Java_FOUND AND SWIG_FOUND AND NLOPT_CXX)
7878

7979
include (UseJava)
8080

test/CMakeLists.txt

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
add_custom_target (tests)
22

33
macro(NLOPT_add_cpp_test test_name)
4-
add_executable (${test_name} ${test_name}.cxx)
5-
target_link_libraries (${test_name} ${nlopt_lib})
6-
add_dependencies (tests ${test_name})
7-
target_include_directories (${test_name} PRIVATE ${NLOPT_PRIVATE_INCLUDE_DIRS})
8-
foreach(arg IN ITEMS ${ARGN})
9-
add_test (NAME check_${test_name}_${arg} COMMAND ${test_name} ${arg})
10-
if (CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
11-
set_tests_properties (check_${test_name}_${arg}
12-
PROPERTIES ENVIRONMENT "PATH=${PROJECT_BINARY_DIR}\\${CMAKE_BUILD_TYPE};$ENV{PATH}") # to load dll
13-
endif ()
14-
endforeach()
4+
if (NLOPT_CXX)
5+
add_executable (${test_name} ${test_name}.cxx)
6+
target_link_libraries (${test_name} ${nlopt_lib})
7+
add_dependencies (tests ${test_name})
8+
target_include_directories (${test_name} PRIVATE ${NLOPT_PRIVATE_INCLUDE_DIRS})
9+
foreach(arg IN ITEMS ${ARGN})
10+
add_test (NAME check_${test_name}_${arg} COMMAND ${test_name} ${arg})
11+
if (CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
12+
set_tests_properties (check_${test_name}_${arg}
13+
PROPERTIES ENVIRONMENT "PATH=${PROJECT_BINARY_DIR}\\${CMAKE_BUILD_TYPE};$ENV{PATH}") # to load dll
14+
endif ()
15+
endforeach()
16+
endif ()
1517
endmacro()
1618

1719
NLOPT_add_cpp_test(t_tutorial 24 25 31 40)
1820
NLOPT_add_cpp_test(cpp_functor 0)
1921
NLOPT_add_cpp_test(t_fbound 0)
2022
NLOPT_add_cpp_test(t_except 1 0)
21-
2223
NLOPT_add_cpp_test(t_bounded 0 1 2 3 4 5 6 7 8 19 35 42 43)
23-
if (NOT NLOPT_CXX)
24-
set_tests_properties (check_t_bounded_8 check_t_bounded_43 PROPERTIES DISABLED TRUE)
25-
endif ()
2624

2725
# have to add timer.c and mt19937ar.c as symbols are declared extern
2826
set (testopt_sources testfuncs.c testfuncs.h testopt.c ${PROJECT_SOURCE_DIR}/src/util/timer.c ${PROJECT_SOURCE_DIR}/src/util/mt19937ar.c)
@@ -67,7 +65,7 @@ foreach (algo_index RANGE 28) # 42
6765
endforeach ()
6866
endforeach ()
6967

70-
if (Python_NumPy_FOUND AND (SWIG_FOUND OR (EXISTS ${PROJECT_SOURCE_DIR}/src/swig/nlopt-python.cpp)))
68+
if (TARGET nlopt_python)
7169
set (PYINSTALLCHECK_ENVIRONMENT "LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/src/swig"
7270
"PYTHONPATH=$<SHELL_PATH:${PROJECT_BINARY_DIR}/src/swig/python;${PROJECT_BINARY_DIR}/src/swig>"
7371
)
@@ -85,7 +83,7 @@ endif ()
8583
# The binding itself should also compile with more ancient Java versions that
8684
# have already reached their end of life, but it is not worth uglifying the test
8785
# code for them, because people will then cargo-cult the legacy boilerplate.
88-
if (JNI_FOUND AND Java_FOUND AND SWIG_FOUND AND NOT Java_VERSION VERSION_LESS 1.8)
86+
if (TARGET nlopt_java AND NOT Java_VERSION VERSION_LESS 1.8)
8987
include (UseJava)
9088
add_jar (t_java SOURCES t_java.java INCLUDE_JARS nlopt_jar ENTRY_POINT t_java)
9189
get_property (t_java_jar TARGET t_java PROPERTY JAR_FILE)
@@ -100,15 +98,15 @@ if (JNI_FOUND AND Java_FOUND AND SWIG_FOUND AND NOT Java_VERSION VERSION_LESS 1.
10098
endforeach()
10199
endif ()
102100

103-
if (OCTAVE_FOUND)
101+
if (TARGET nlopt_optimize)
104102
add_test (NAME test_octave COMMAND ${OCTAVE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/t_octave.m ${PROJECT_SOURCE_DIR}/src/octave ${PROJECT_BINARY_DIR}/src/octave)
105103
endif ()
106104

107-
if (MATLAB_FOUND)
105+
if (TARGET nlopt_optimize-mex)
108106
add_test (NAME test_matlab COMMAND ${Matlab_MAIN_PROGRAM} -nodesktop -nosplash -r "addpath('${PROJECT_SOURCE_DIR}/src/octave'); addpath('${PROJECT_BINARY_DIR}/src/octave'); try; run('${CMAKE_CURRENT_SOURCE_DIR}/t_matlab.m'); catch; exit(1); end; quit")
109107
endif ()
110108

111-
if (GUILE_FOUND AND (SWIG_FOUND OR (EXISTS ${PROJECT_SOURCE_DIR}/src/swig/nlopt-guile.cpp)))
109+
if (TARGET nlopt_guile)
112110
set (GUILECHECK_ENVIRONMENT "LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/src/swig"
113111
"GUILE_LOAD_PATH=$<SHELL_PATH:${PROJECT_BINARY_DIR}/src/swig/guile;${PROJECT_BINARY_DIR}/src/swig>"
114112
"GUILE_AUTO_COMPILE=0")

0 commit comments

Comments
 (0)