diff --git a/cmake/mex.cmake b/cmake/mex.cmake index c8b277ccd281..0c28af72d48b 100644 --- a/cmake/mex.cmake +++ b/cmake/mex.cmake @@ -129,6 +129,7 @@ function(mex_setup) get_mex_option(CFLAGS NAMES COMPFLAGS) get_mex_option(CXXFLAGS NAMES COMPFLAGS) + get_mex_option(DEFINES NAMES COMPDEFINES) get_mex_option(COPTIMFLAGS NAMES OPTIMFLAGS) get_mex_option(CXXOPTIMFLAGS NAMES OPTIMFLAGS) get_mex_option(CDEBUGFLAGS NAMES DEBUGFLAGS) @@ -197,7 +198,7 @@ function(mex_setup) endif() # figure out LDFLAGS for exes and shared libraries - set (MEXLIB_LDFLAGS ${MEX_LDFLAGS} ${MEX_LD_ARGUMENTS} ${MEX_CLIBS} ${MEX_LINKLIBS} ${MEX_LINKEXPORT}) + set (MEXLIB_LDFLAGS ${MEX_LDFLAGS} ${MEX_LD_ARGUMENTS} ${MEX_CXXLIBS} ${MEX_LINKLIBS} ${MEX_LINKEXPORT}) if (NOT WIN32) # AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)) set(MEXLIB_LDFLAGS ${MEXLIB_LDFLAGS} "-ldl") @@ -225,20 +226,20 @@ function(mex_setup) # todo: handle C separately from CXX? - set (MEX_COMPILE_FLAGS "${MEX_INCLUDE} ${MEX_CXXFLAGS} ${MEX_DEFINES} ${MEX_MATLABMEX} ${MEX_CXX_ARGUMENTS}") - string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type) - if (_build_type MATCHES DEBUG) - set(MEX_COMPILE_FLAGS "${MEX_CXXDEBUGFLAGS} ${MEX_COMPILE_FLAGS}") - if (MSVC) - string(REPLACE "/MD " "/MDd " MEX_COMPILE_FLAGS "${MEX_COMPILE_FLAGS}") - endif() - elseif (_build_type MATCHES RELEASE) - set(MEX_COMPILE_FLAGS "${MEX_CXXOPTIMFLAGS} ${MEX_COMPILE_FLAGS}") - endif() - - if (${MEX_COMPILE_FLAGS} MATCHES "-ansi") - string(REPLACE "-ansi" "" MEX_COMPILE_FLAGS "${MEX_COMPILE_FLAGS}") - message(WARNING "Your MEX compiler flags contained '-ansi', but we've removed that flag for compatibility with C++11") + set (MEX_COMPILE_FLAGS "${MEX_CXXFLAGS} ${MEX_DEFINES} ${MEX_CXX_ARGUMENTS}") + + # CMake will add the appropriate flags for the chosen build configuration + # instead of these flags + if(MSVC) + # Controlled by CMAKE_BUILD_TYPE + string(REPLACE "/MD " "" MEX_COMPILE_FLAGS "${MEX_COMPILE_FLAGS}") + # Controlled by CMAKE_VERBOSE_MAKEFILE + string(REPLACE "/nologo " "" MEX_COMPILE_FLAGS "${MEX_COMPILE_FLAGS}") + string(REPLACE "/nologo " "" MEXLIB_LDFLAGS "${MEXLIB_LDFLAGS}") + else() + # Controlled by CMAKE_C_STANDARD and CMAKE_CXX_STANDARD + string(REPLACE "-ansi " "" MEX_COMPILE_FLAGS "${MEX_COMPILE_FLAGS}") + string(REPLACE "-std=c++11 " "" MEX_COMPILE_FLAGS "${MEX_COMPILE_FLAGS}") endif() set(MEX_COMPILE_FLAGS "${MEX_COMPILE_FLAGS}" PARENT_SCOPE) @@ -255,7 +256,7 @@ function(mex_setup) endif() set (MEXLIB_LDFLAGS "${MEXLIB_LDFLAGS}" PARENT_SCOPE) - # todo: add CLIBS or CXXLIBS to LINK_FLAGS selectively based in if it's a c or cxx target (always added C above) + # todo: add CLIBS or CXXLIBS to LINK_FLAGS selectively based on if it's a c or cxx target (always added CXX above) if (MATLAB_ROOT AND MEX_EXT) set (MATLAB_FOUND true PARENT_SCOPE) @@ -269,7 +270,7 @@ function(mex_setup) compare_compilers(compilers_match "${CMAKE_CXX_COMPILER}" "${MEX_CXX}") if (NOT compilers_match) - message(WARNING "Your cmake CXX compiler is: \"${CMAKE_CXX_COMPILER}\" but your mex options end up pointing to: \"${MEX_CXX}\". You must use the same compilers. You can either:\n a) Configure the mex compiler by running 'mex -setup' in MATLAB, or \n b) Set the default compiler for cmake by setting the CC environment variable in your terminal.") + message(WARNING "Your cmake CXX compiler is: \"${CMAKE_CXX_COMPILER}\" but your mex options end up pointing to: \"${MEX_CXX}\". You must use the same compilers. You can either:\n a) Configure the mex compiler by running 'mex -setup' in MATLAB, or \n b) Set the default compiler for cmake by setting the CXX environment variable in your terminal.") endif() # NOTE: would like to check LD also, but it appears to be difficult with cmake (there is not explicit linker executable variable, only the make rule), and even my mex code assumes that LD==LDCXX for simplicity. @@ -313,12 +314,7 @@ function(add_mex) if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) target_link_libraries(${target} liblast) else() - set_target_properties(${target} PROPERTIES - LINK_FLAGS_DEBUG "${MEXLIB_LDDEBUGFLAGS} ${MEX_LDFLAGS}" - LINK_FLAGS_RELEASE "${MEXLIB_LDOPTIMFLAGS} ${MEX_LDFLAGS}" - LINK_FLAGS_MINSIZEREL "${MEXLIB_LDFLAGS} ${MEX_LDOPTIMFLAGS}" - LINK_FLAGS_RELWITHDEBINFO "${MEXLIB_LDFLAGS} ${MEX_LDDEBUGFLAGS} ${MEX_LDOPTIMFLAGS}" - ) + set_target_properties(${target} PROPERTIES LINK_FLAGS "${MEXLIB_LDFLAGS}") endif() elseif (isshared GREATER -1) add_library(${target} ${ARGV}) @@ -334,23 +330,15 @@ function(add_mex) string(REPLACE "/EXPORT:mexFunction" "" __ldflags "${__ldflags}") string(REGEX REPLACE "/implib:[^ ]+" "" __ldflags "${__ldflags}") - set_target_properties(${target} PROPERTIES - LINK_FLAGS_DEBUG "${__ldflags} ${MEX_LDDEBUGFLAGS}" - LINK_FLAGS_RELEASE "${__ldflags} ${MEX_LDOPTIMFLAGS}" - LINK_FLAGS_MINSIZEREL "${__ldflags} ${MEX_LDOPTIMFLAGS}" - LINK_FLAGS_RELWITHDEBINFO "${__ldflags} ${MEX_LDDEBUGFLAGS} ${MEX_LDOPTIMFLAGS}" - ) + set_target_properties(${target} PROPERTIES LINK_FLAGS "${__ldflags}") endif() else () add_library(${target} MODULE ${ARGV}) set_target_properties(${target} PROPERTIES - COMPILE_FLAGS "-DMATLAB_MEX_FILE ${MEX_COMPILE_FLAGS}" + COMPILE_FLAGS "${MEX_COMPILE_FLAGS}" PREFIX "" SUFFIX ".${MEX_EXT}" - LINK_FLAGS_DEBUG "${MEXLIB_LDFLAGS} ${MEX_LDDEBUGFLAGS}" - LINK_FLAGS_RELEASE "${MEXLIB_LDFLAGS} ${MEX_LDOPTIMFLAGS}" - LINK_FLAGS_MINSIZEREL "${MEXLIB_LDFLAGS} ${MEX_LDOPTIMFLAGS}" - LINK_FLAGS_RELWITHDEBINFO "${MEXLIB_LDFLAGS} ${MEX_LDDEBUGFLAGS} ${MEX_LDOPTIMFLAGS}" + LINK_FLAGS "${MEXLIB_LDFLAGS}" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_NAME ${mexfilename} @@ -367,12 +355,7 @@ function(add_mex) if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) # see comment by the definition of liblast above - set_target_properties(${target} PROPERTIES - LINK_FLAGS_DEBUG "${MEX_LDDEBUGFLAGS}" - LINK_FLAGS_RELEASE "${MEX_LDOPTIMFLAGS}" - LINK_FLAGS_MINSIZEREL "${MEX_LDOPTIMFLAGS}" - LINK_FLAGS_RELWITHDEBINFO "${MEX_LDDEBUGFLAGS} ${MEX_LDOPTIMFLAGS}" - ) + set_target_properties(${target} PROPERTIES LINK_FLAGS "${MEXLIB_LDFLAGS}") target_link_libraries(${target} liblast) endif() endif() diff --git a/cmake/pods.cmake b/cmake/pods.cmake index 117a0aeacd42..b513c907fc13 100644 --- a/cmake/pods.cmake +++ b/cmake/pods.cmake @@ -572,8 +572,7 @@ function(pods_use_pkg_config_packages target) # from http://stackoverflow.com/a/29871891 find_package(Threads REQUIRED) if (THREADS_HAVE_PTHREAD_ARG) - set_property(TARGET ${target} PROPERTY COMPILE_OPTIONS "-pthread") - set_property(TARGET ${target} PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread") + target_compile_options(${target} PUBLIC "-pthread") endif() if (CMAKE_THREAD_LIBS_INIT) target_link_libraries(${target} "${CMAKE_THREAD_LIBS_INIT}") diff --git a/drake/CMakeLists.txt b/drake/CMakeLists.txt index 221f94526795..2557fe31ddbf 100644 --- a/drake/CMakeLists.txt +++ b/drake/CMakeLists.txt @@ -97,9 +97,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" endif() # TODO(rdeits) Remove when https://github.com/jaeandersson/swig/pull/73 is # accessible from the version of swig_matlab we are using - set(CXX_FLAGS_NO_ERROR_MAYBE_UNINITIALIZED "-Wno-error=maybe-uninitialized") - set(CXX_FLAGS_NO_ERROR_SHADOW "-Wno-error=shadow -Wno-shadow") - set(CXX_FLAGS_NO_SIGN_COMPARE "-Wno-sign-compare") + set(CXX_FLAGS_NO_ERROR_MAYBE_UNINITIALIZED -Wno-error=maybe-uninitialized) + set(CXX_FLAGS_NO_ERROR_SHADOW -Wno-error=shadow -Wno-shadow) + set(CXX_FLAGS_NO_SIGN_COMPARE -Wno-sign-compare) elseif(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251") # disable warning C4251: e.g.'RigidBody::linkname' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'RigidBody' @@ -126,8 +126,8 @@ elseif(MSVC) add_definitions(-D_USE_MATH_DEFINES) # to get math constants on MSVC (see https://msdn.microsoft.com/en-us/library/4hwaceh6.aspx) - set(CXX_FLAGS_NO_ERROR_SHADOW "/wd4456 /wd4457") - set(CXX_FLAGS_NO_SIGN_COMPARE "/wd4018") + set(CXX_FLAGS_NO_ERROR_SHADOW /wd4456 /wd4457) + set(CXX_FLAGS_NO_SIGN_COMPARE /wd4018) endif() # set up matlab build diff --git a/drake/bindings/swig/CMakeLists.txt b/drake/bindings/swig/CMakeLists.txt index c93dceb6fb66..6e0144595645 100644 --- a/drake/bindings/swig/CMakeLists.txt +++ b/drake/bindings/swig/CMakeLists.txt @@ -8,13 +8,16 @@ set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} "-w315,-401") # Ignore SWIG errors about not being able to wrap operator << set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} "-w503") # The autodiff.i in swig has for-loop variable warnings. -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_NO_SIGN_COMPARE}") +set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} APPEND PROPERTY + COMPILE_OPTIONS ${CXX_FLAGS_NO_SIGN_COMPARE}) # SWIG output code makes expansive use of variable shadowing. -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_NO_ERROR_SHADOW}") +set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} APPEND PROPERTY + COMPILE_OPTIONS ${CXX_FLAGS_NO_ERROR_SHADOW}) # SWIG output code "may" use a variable uninitialized (not really, but due to # bad annotation of mexErrMsgIdAndTxt, the compiler can't know that); see also # https://github.com/jaeandersson/swig/pull/73 -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS_NO_ERROR_MAYBE_UNINITIALIZED}") +set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} APPEND PROPERTY + COMPILE_OPTIONS ${CXX_FLAGS_NO_ERROR_MAYBE_UNINITIALIZED}) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Suppresses warnings due to the existence of deprecated methods. These diff --git a/drake/common/test/CMakeLists.txt b/drake/common/test/CMakeLists.txt index 9e6a2164f810..5860d3ff5413 100644 --- a/drake/common/test/CMakeLists.txt +++ b/drake/common/test/CMakeLists.txt @@ -122,9 +122,9 @@ add_executable(drake_deprecated_test drake_deprecated_test.cc) target_link_libraries(drake_deprecated_test drakeCommon ${GTEST_BOTH_LIBRARIES}) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Remove spurious warnings from the default build output. - set_target_properties( + target_compile_options( drake_deprecated_test - PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") + PRIVATE -Wno-deprecated-declarations) endif() add_test(NAME drake_deprecated_test COMMAND drake_deprecated_test) @@ -143,9 +143,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" set_target_properties( drake_deprecated_test_nocompile PROPERTIES EXCLUDE_FROM_ALL TRUE EXCLUDE_FROM_DEFAULT_BUILD TRUE) - set_target_properties( + target_compile_options( drake_deprecated_test_nocompile - PROPERTIES COMPILE_FLAGS "-Werror=deprecated-declarations") + PRIVATE -Werror=deprecated-declarations) add_test(NAME drake_deprecated_test_nocompile COMMAND ${CMAKE_COMMAND} --build . --target diff --git a/drake/solvers/CMakeLists.txt b/drake/solvers/CMakeLists.txt index 455d7d177ed2..3513902ff518 100644 --- a/drake/solvers/CMakeLists.txt +++ b/drake/solvers/CMakeLists.txt @@ -95,6 +95,15 @@ if(gurobi_FOUND) pods_use_pkg_config_packages(drakeOptimization gurobi) endif() +if(snopt_c_FOUND AND MATLAB_FOUND) + add_mex(NonlinearProgramSnoptmex NonlinearProgramSnoptmex.cpp) + pods_use_pkg_config_packages(NonlinearProgramSnoptmex snopt_c) + + # These warnings are not worth fixing. + target_compile_options(NonlinearProgramSnoptmex PRIVATE + ${CXX_FLAGS_NO_ERROR_SHADOW}) +endif() + if(mosek_FOUND) pods_use_pkg_config_packages(drakeOptimization mosek) endif() diff --git a/drake/systems/plants/CMakeLists.txt b/drake/systems/plants/CMakeLists.txt index 98f09491f9f0..593530ff0ff9 100644 --- a/drake/systems/plants/CMakeLists.txt +++ b/drake/systems/plants/CMakeLists.txt @@ -56,10 +56,10 @@ add_subdirectory(joints) if(MATLAB_FOUND) add_mex(rbmMexFunctions SHARED rigidBodyTreeMexFunctions.cpp) + pods_install_libraries(rbmMexFunctions) target_link_libraries(rbmMexFunctions drakeRBM drakeMexUtil) # These warnings are not worth fixing. - set_target_properties( - rbmMexFunctions PROPERTIES COMPILE_FLAGS ${CXX_FLAGS_NO_SIGN_COMPARE}) + target_compile_options(rbmMexFunctions PRIVATE ${CXX_FLAGS_NO_SIGN_COMPARE}) macro(add_rbm_mex) # TODO: use this again once I can assume everyone has CMAKE version >= 2.8.8 @@ -68,8 +68,7 @@ if(MATLAB_FOUND) add_mex(${ARGV} ${ARGV}.cpp) target_link_libraries(${ARGV} rbmMexFunctions) # These warnings are not worth fixing. - set_target_properties( - ${ARGV} PROPERTIES COMPILE_FLAGS ${CXX_FLAGS_NO_SIGN_COMPARE}) + target_compile_options(${ARGV} PRIVATE ${CXX_FLAGS_NO_SIGN_COMPARE}) endmacro() add_rbm_mex(constructModelmex) @@ -122,8 +121,7 @@ if(MATLAB_FOUND) add_mex(${ARGV} ${ARGV}.cpp) target_link_libraries(${ARGV} drakeRBM drakeMexUtil drakeIKoptions) # These warnings are not worth fixing. - set_target_properties( - ${ARGV} PROPERTIES COMPILE_FLAGS ${CXX_FLAGS_NO_SIGN_COMPARE}) + target_compile_options(${ARGV} PRIVATE ${CXX_FLAGS_NO_SIGN_COMPARE}) endmacro() add_ikoptions_mex(IKoptionsmex) @@ -167,8 +165,7 @@ if(MATLAB_FOUND) add_mex(${ARGV} ${ARGV}.cpp) target_link_libraries(${ARGV} drakeIK drakeRBM drakeMexUtil drakeRigidBodyConstraint) # These warnings are not worth fixing. - set_target_properties( - ${ARGV} PROPERTIES COMPILE_FLAGS ${CXX_FLAGS_NO_SIGN_COMPARE}) + target_compile_options(${ARGV} PRIVATE ${CXX_FLAGS_NO_SIGN_COMPARE}) endmacro() if(snopt_c_FOUND) diff --git a/drake/systems/plants/constraint/CMakeLists.txt b/drake/systems/plants/constraint/CMakeLists.txt index 12546c3f4733..675d013636bb 100644 --- a/drake/systems/plants/constraint/CMakeLists.txt +++ b/drake/systems/plants/constraint/CMakeLists.txt @@ -2,8 +2,7 @@ macro(add_constraint_mex) add_mex(${ARGV} ${ARGV}.cpp) target_link_libraries(${ARGV} drakeRBM drakeMexUtil drakeRigidBodyConstraint drakeConstructRigidBodyConstraint) # These warnings are not worth fixing. - set_target_properties( - ${ARGV} PROPERTIES COMPILE_FLAGS ${CXX_FLAGS_NO_SIGN_COMPARE}) + target_compile_options(${ARGV} PRIVATE ${CXX_FLAGS_NO_SIGN_COMPARE}) endmacro() add_library_with_exports(LIB_NAME drakeRigidBodyConstraint SOURCE_FILES RigidBodyConstraint.cpp) @@ -18,6 +17,7 @@ pods_install_pkg_config_file(drake-rigid-body-constraint if(MATLAB_FOUND) add_mex(drakeConstructRigidBodyConstraint SHARED constructPtrRigidBodyConstraint.cpp) target_link_libraries(drakeConstructRigidBodyConstraint drakeRigidBodyConstraint drakeRBM drakeMexUtil drakeGeometryUtil) + pods_install_libraries(drakeConstructRigidBodyConstraint) add_constraint_mex(testSingleTimeKinCnstmex) add_constraint_mex(testMultipleTimeKinCnstmex) add_constraint_mex(testQuasiStaticConstraintmex) diff --git a/drake/systems/trajectories/CMakeLists.txt b/drake/systems/trajectories/CMakeLists.txt index 5aae006239a3..81c90326d804 100644 --- a/drake/systems/trajectories/CMakeLists.txt +++ b/drake/systems/trajectories/CMakeLists.txt @@ -30,9 +30,8 @@ if(BLAS_LIBRARY AND snopt_c_FOUND AND bullet_FOUND AND MATLAB_FOUND) target_link_libraries(ptToPolyBullet_mex drakeMexUtil) # These warnings are not worth fixing. - set_target_properties( - replanFunnels_mex shiftFunnel_snopt_mex - PROPERTIES COMPILE_FLAGS ${CXX_FLAGS_NO_ERROR_SHADOW}) + target_compile_options(replanFunnels_mex PRIVATE ${CXX_FLAGS_NO_ERROR_SHADOW}) + target_compile_options(shiftFunnel_snopt_mex PRIVATE ${CXX_FLAGS_NO_ERROR_SHADOW}) endif() add_subdirectory(test)