Re: [CMake] Add linker command file to object files
On 07/20/2011 02:19 PM, Florian Reinhard wrote: > Hi Michael, > > Thank you for that long and well explained resonse! > > I just gave your EXTERNAL_OBJECT approach with a patched cmake version a try. > > Unfortunately this is just almost a solution. That way the linker.cmd > appears in the list of files that are fed to the linker, but it > doesn't keep the same order as specified in ADD_EXECUTABLE. External > objects are being appended to the list of object files which doesn't > help in that place. I manually edited the resulting makefile and added > the .cmd file to the object file list in the right place and ran make. > That way the build was completed successfully. > > So i guess the only way to have the .cmd file appear in the list of > objects in the same place where it is in the list of source files is > to fiddle with the CMAKE__IGNORE_EXTENSIONS. Alternatively, if you get along with Makefiles, you might use one of the RULE_LAUNCH_LINK properties in connection with a shell script or the like. In this way, you will have last-minute access to the whole linker command line and can place the linker command file wherever you want. To establish a dependency of the affected targets on the linker command file, you might use the LINK_DEPENDS target property. IMO, that's a quite elegant solution for your concern; see [1] for an example how to intercept the linker command by a launch script. However, I'm still of the opinion that the EXTERNAL_OBJECT property is *not* handled correctly: It should definitely take precedence over the examination of the respective file's extension in order that the file gets included in the linker command regardless whether its extension is designated to be ignored. This is also what one would expect due to the documentation. CMake developers, what do you say? Regards, Michael [1] http://www.mail-archive.com/cmake@cmake.org/msg37131.html ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] test linker flags?
On 07/15/2011 03:15 AM, Clifford Yapp wrote: > Is there a way to test flags supplied to the linker > (CMAKE_SHARED_LINKER_FLAGS) in the same way we can test compiler flags > with CHECK_C_COMPILER_FLAG? I'd like to check if -Wl,--no-undefined > works or not before using it. > > Cheers, > CY You might set CMAKE_REQUIRED_FLAGS to the linker flags you want to test and subsequently invoke CHECK_C_COMPILER_FLAG() with an empty argument: CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) PROJECT(LINKERFLAGS C) SET(CMAKE_VERBOSE_MAKEFILE ON) INCLUDE(CheckCCompilerFlag) SET(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined") CHECK_C_COMPILER_FLAG("" RESULT1) IF(RESULT1) MESSAGE("Supported: -Wl,--no-undefined") ELSE() MESSAGE("Not supported: -Wl,--no-undefined") ENDIF() SET(CMAKE_REQUIRED_FLAGS "-Wl,--nonono-undefined") CHECK_C_COMPILER_FLAG("" RESULT2) IF(RESULT2) MESSAGE("Supported: -Wl,--nonono-undefined") ELSE() MESSAGE("Not supported: -Wl,--nonono-undefined") ENDIF() AFAICS, the reason CHECK_C_COMPILER_FLAG() doesn't work for flags passed to the linker is that its first argument is appended to the CMAKE_REQUIRED_DEFINITIONS variable before CHECK_C_SOURCE_COMPILES() is called which in turn passes the CMAKE_REQUIRED_DEFINITIONS to the COMPILE_DEFINITIONS argument of TRY_COMPILE(). So, the flag is just used for the compilation, and flags like "-Wl,..." are ignored, i.e. they pass always. However, the CMAKE_REQUIRED_FLAGS are appended to TRY_COMPILE()'s CMAKE_FLAGS as "-DCOMPILE_DEFINITIONS:STRING=..." and apparently make it to the linker command as can be seen in CMakeFiles/CMakeTmp/CMakeFiles/cmTryCompileExec.dir/link.txt. Perhaps, one should reconsider this behavior and provide an improved possibility to check flags being meaningful for the linker also/only. Regards, Michael ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] Using CMake to interface with non-CMake libraries
Hey Zoey, I don't know anything about SOLID, but the errormessage means, your program needs to be linked against a library. You could ask cmake to look for your SOLID library: find_library(SOLID_LIBRARY solid) if(NOT SOLID_LIBRARY) message(ERROR "please specify the library for SOLID") endif(NOT SOLID_LIBRARY) add extend the target_link_libraries call with ${SOLID_LIBRARY}: target_link_libraries(hybrid_PRM_demo ${QT3_LIBRARIES} ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ${SOLID_LIBRARY}) I hope that helps you a little bit. Andreas Am 24.07.2011 12:09, schrieb Zoey McCarthy: Hello everyone, I am new to using CMake and I am trying to compile a program that uses two libraries, one of which needs to be built using CMake, and the other, that utilizes its own build system(the Makefiles were generated using ./configure). The two libraries are CGAL and SOLID (for collision detection). CGAL provides a script, cgal_create_cmake_script , that produces the CMakeLists.txt file for an executable that includes the CGAL library. I can build my executable fine using cmake and make when I only try to include CGAL. When I try to include SOLID, I have issues with finding class definitions during linking, i.e. I get errors of the type: /home/zoeymccarthy/hybrid_PRM/CollisionChecker.h:146: undefined reference to `DT_GenResponseClass' SOLID is installed in /usr/local/include/SOLID/ and /usr/include/SOLID/. The header files for the library were installed there, but I have since tried copying the rest of the files associated with the library there since the compiler was able to locate the header files. This is the CMakeLists.txt that the CGAL script generated for my project: # Created by the script cgal_create_cmake_script # This is the CMake script for compiling a CGAL application. project( hybrid_PRM_demo ) CMAKE_MINIMUM_REQUIRED(VERSION 2.4.5) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) if ( COMMAND cmake_policy ) cmake_policy( SET CMP0003 NEW ) endif() find_package(CGAL QUIET COMPONENTS Core Qt3 ) if ( CGAL_FOUND ) include( ${CGAL_USE_FILE} ) find_package(Qt3-patched QUIET ) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so # that it can be used together with FindQt4: all its variables are prefixed # by "QT3_" instead of "QT_". if(CGAL_Qt3_FOUND AND QT3_FOUND) include( Qt3Macros-patched ) qt3_automoc( main.cpp ) # Make sure the compiler can find generated .moc files include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) include_directories( ${QT3_INCLUDE_DIR} ) add_executable (hybrid_PRM_demo main.cpp) add_to_cached_list( CGAL_EXECUTABLE_TARGETS hybrid_PRM_demo ) # Link the executable to CGAL and third-party libraries target_link_libraries(hybrid_PRM_demo ${QT3_LIBRARIES} ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ) else() message(STATUS "NOTICE: This demo requires Qt3 and the CGAL Qt3 library, and will not be compiled.") endif() else() message(STATUS "NOTICE: This demo requires the CGAL library, and will not be compiled.") endif() As you can see, there is no reference to SOLID. How should I modify it so that the resulting Makefile will know where to link to my SOLID object files, given that SOLID has no .cmake file associated with it, and the library was built without any CMakeLists.txt files? I've tried adding the following two lines: include_directories(/usr/include/SOLID/) link_directories(/usr/include/SOLID/) to the middle of my CMakeLists.txt (before if ( CGAL_FOUND) ), but it results in the same error. I'm sorry if this is a stupid question, but for the life of me I can't get it to work. Thank you for your help, Zoey ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
[CMake] Using CMake to interface with non-CMake libraries
Hello everyone, I am new to using CMake and I am trying to compile a program that uses two libraries, one of which needs to be built using CMake, and the other, that utilizes its own build system(the Makefiles were generated using ./configure). The two libraries are CGAL and SOLID (for collision detection). CGAL provides a script, cgal_create_cmake_script , that produces the CMakeLists.txt file for an executable that includes the CGAL library. I can build my executable fine using cmake and make when I only try to include CGAL. When I try to include SOLID, I have issues with finding class definitions during linking, i.e. I get errors of the type: /home/zoeymccarthy/hybrid_PRM/CollisionChecker.h:146: undefined reference to `DT_GenResponseClass' SOLID is installed in /usr/local/include/SOLID/ and /usr/include/SOLID/. The header files for the library were installed there, but I have since tried copying the rest of the files associated with the library there since the compiler was able to locate the header files. This is the CMakeLists.txt that the CGAL script generated for my project: # Created by the script cgal_create_cmake_script # This is the CMake script for compiling a CGAL application. project( hybrid_PRM_demo ) CMAKE_MINIMUM_REQUIRED(VERSION 2.4.5) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) if ( COMMAND cmake_policy ) cmake_policy( SET CMP0003 NEW ) endif() find_package(CGAL QUIET COMPONENTS Core Qt3 ) if ( CGAL_FOUND ) include( ${CGAL_USE_FILE} ) find_package(Qt3-patched QUIET ) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so # that it can be used together with FindQt4: all its variables are prefixed # by "QT3_" instead of "QT_". if(CGAL_Qt3_FOUND AND QT3_FOUND) include( Qt3Macros-patched ) qt3_automoc( main.cpp ) # Make sure the compiler can find generated .moc files include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) include_directories( ${QT3_INCLUDE_DIR} ) add_executable (hybrid_PRM_demo main.cpp) add_to_cached_list( CGAL_EXECUTABLE_TARGETS hybrid_PRM_demo ) # Link the executable to CGAL and third-party libraries target_link_libraries(hybrid_PRM_demo ${QT3_LIBRARIES} ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ) else() message(STATUS "NOTICE: This demo requires Qt3 and the CGAL Qt3 library, and will not be compiled.") endif() else() message(STATUS "NOTICE: This demo requires the CGAL library, and will not be compiled.") endif() As you can see, there is no reference to SOLID. How should I modify it so that the resulting Makefile will know where to link to my SOLID object files, given that SOLID has no .cmake file associated with it, and the library was built without any CMakeLists.txt files? I've tried adding the following two lines: include_directories(/usr/include/SOLID/) link_directories(/usr/include/SOLID/) to the middle of my CMakeLists.txt (before if ( CGAL_FOUND) ), but it results in the same error. I'm sorry if this is a stupid question, but for the life of me I can't get it to work. Thank you for your help, Zoey ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake