Menu

Adding a new project to solution

Help
Anonymous
2013-04-10
2013-04-18
  • Anonymous

    Anonymous - 2013-04-10

    Hi,
    I want to add a new project to the existing solution. I'm using cmake and visual studio 2008 under win xp.
    How can I do this?

    The new project "test" should be under ../modules/test, so I add a new project "test" in visual studio to the solution. After that I add the CMakeLists.txt files to navigate to the right folder. I also add "add_subdirectory(test)" to the CMakeList.txt in ../modules.

    Then I copied the CMakeList from an other module (for example networking) and changes the specific things like headers, sources, naming conventions,… .

    After this changes I rerun cmake and the new solution was generated, with my new project test.

    My problem: if I build the new project in visual studio only a test.dll is generated, no test.lib file. I can only change between generate .dll or generate .lib in the project settings, but not both at the same time like in the other projects.

    My next problem: I want to work with the functions that I added in the new project in standardgame (racesituation.cpp), how does this work?
    I tried to add my project to the SDLIB in internaldeps.cmake, and call add_sdlib_includedir(… test) and add_sdlib_library(… test) in CMakeList.txt in standardgame.

    The CMakeLists.txt in ../module/test:

    INCLUDE(../../../../cmake/macros.cmake)
    SET(TEST_HEADERS test.h)
    SET(TEST_SOURCES test.c)
    #disable developer warning
    if (COMMAND cmake_policy)
        cmake_policy(SET CMP0003 NEW)
    endif(COMMAND cmake_policy)
    # Note: Headers needed for having them available in IDEs.
    ADD_LIBRARY(test SHARED ${TEST_SOURCES} ${TEST_HEADERS})
    ADD_SDLIB_INCLUDEDIR(test)
    ADD_SDL_LIBRARY(test)
    IF(WIN32)
        TARGET_LINK_LIBRARIES(test Winmm ws2_32)
    ENDIF(WIN32)
    IF(MSVC)
        # Ignore some run-time libs to avoid link time warnings and sometimes even crashes.
        SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG 
            "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:libcmt.lib")
        SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE 
            "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmt.lib")
    ENDIF(MSVC)
    ADD_SDLIB_LIBRARY(test)
    SD_INSTALL_FILES(LIB modules/test TARGETS test)
    

    The CMakeLists.txt in standardgame:

    INCLUDE(../../../../cmake/macros.cmake)
    #PROJECT(standardgame)
    SET(_SOURCES standardgame.cpp
                 racecareer.cpp raceupdate.cpp racenetwork.cpp racecars.cpp
                 raceinit.cpp racemain.cpp
                 racetrack.cpp raceresults.cpp racesimusimu.cpp 
                 racestate.cpp racesituation.cpp racemessage.cpp
                 raceutil.cpp)
    SET(_HEADERS standardgame.h 
                 racecareer.h raceupdate.h racenetwork.h racecars.h
                 raceinit.h racetrack.h raceresults.h racesimusimu.h 
                 racestate.h racesituation.h racemessage.h
                 raceutil.h)
    SET(_OTHER_SOURCES )
    ADD_INTERFACE_INCLUDEDIR()
    ADD_SDLIB_INCLUDEDIR(math portability robottools tgf tgfdata networking test)
    ADD_PLIB_INCLUDEDIR()
    ADD_SDL_INCLUDEDIR()
    # Disable developer warning
    IF (COMMAND CMAKE_POLICY)
        CMAKE_POLICY(SET CMP0003 NEW)
    ENDIF(COMMAND CMAKE_POLICY)
    IF(WIN32)
        # DLL export stuff under Windows (to avoid .def file)
        ADD_DEFINITIONS(-DSTANDARDGAME_DLL)
    ENDIF(WIN32)
        
    IF(MSVC)
        # Ignore some run-time libs to avoid link time warnings and sometimes even crashes.
        SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:msvcrt.lib")
    ENDIF(MSVC)
    # Note: Other source files  and headers needed for having them available in IDEs.
    ADD_LIBRARY(standardgame SHARED ${_SOURCES} ${_HEADERS} ${_OTHER_SOURCES})
    # Might not work with GCC 4.5 or + (non-robot modules crash at 1st reload = after 1 dlclose) 
    #SET_TARGET_PROPERTIES(standardgame PROPERTIES VERSION ${VERSION} SOVERSION 0.0.0)
    IF(UNIX OR MINGW)
        SET_TARGET_PROPERTIES(standardgame PROPERTIES PREFIX "")
    ENDIF(UNIX OR MINGW)
    ADD_SDLIB_LIBRARY(standardgame portability tgf tgfdata robottools networking test)
    SD_INSTALL_FILES(LIB modules/racing TARGETS standardgame)
    

    The changes in internaldeps.cmake:

    ...//networking
    ELSEIF(SDLIB_LIB STREQUAL "test")
          IF(IN_SOURCETREE)
            SET(INCLUDE_CANDIDATE ${SOURCE_DIR}/src/modules/test)
          ELSE(IN_SOURCETREE)
            SET(INCLUDE_CANDIDATE ${SD_INCLUDEDIR_ABS})
          ENDIF(IN_SOURCETREE)
          FIND_PATH(SDLIB_TEST_INCLUDE_DIR test.h PATHS ${INCLUDE_CANDIDATE} /usr/include /usr/local/include NO_DEFAULT_PATH)
          FIND_PATH(SDLIB_TEST_INCLUDE_DIR test.h PATHS ${INCLUDE_CANDIDATE} /usr/include /usr/local/include)
          MARK_AS_ADVANCED(SDLIB_TEST_INCLUDE_DIR)
          SET(SDLIB_EXTRA_INCLUDEDIR SDLIB_TEST_INCLUDE_DIR)
    ...//raceengine
    

    Did anyone knows an answer to this problem? Or can give me an explanation how to add a new project to the solution?

    Thanks!!!
    Andy

     
  • Anonymous

    Anonymous - 2013-04-10

    I forgot some more details:

    If I build the project solution I got an linker error, because racesituation did not know the functions of test. If I comment out the functions everything is fine and it runs completely.
    So I think that there is an error in linking test to standardgame…

     
  • Jean-Philippe Meuret

    Hi,  Andy.
    A few hints ;
    * under src/modules, we put source code for Speed Dreams "dynamically loadable modules", that is DLLs that we load at run-time through LoadLibrary / dlopen system calls (search for and examine the GfModule class for more) ; as it seems "test" is only a standard library that you want the "standardgame" racing module to link with, you should rather put it under src/libs (just like "tgf", "tgfclient" … networking is a BAD example, don't follow it.
    * in "test" CMakeLists.txt, you should rather use "SD_ADD_LIBRARY" (not the CMake native ADD_LIBRARY) : see cmake/macros.cmake for more details,
    * if your "test" DLL doesn't features a .lib file, this means that it doesn't exports anything ; you have to explicitly tell the compiler which classes, functions or variables the DLL publishes, through the usual following construction (example extracted from the tgf library, from tgf.h, for exporting the GfShutdown function ; please adapt it to your "test" one) :

    // DLL exported symbols declarator for Windows.
    #ifdef WIN32
    # ifdef tgf_EXPORTS
    #  define TGF_API __declspec(dllexport)
    # else
    #  define TGF_API __declspec(dllimport)
    # endif
    #else
    # define TGF_API
    #endif
    TGF_API void GfShutdown(void);

    Note: For your "test" DLL, MSVC automatically defines the "test_EXPORT" C-preprocessor symbol, which makes the compiler use "__declspec(dllexport)" when compiling test.dll, and "__declspec(dllimport)" when compiling code that calls / includes test.dll

     
  • Andy

    Andy - 2013-04-17

    Hey Jean-Philippe,
    thank you for this professional answer.
    Now it work great.

    Regards,
    Andy

     
  • Jean-Philippe Meuret

    Thanks Andy, you're welcome :-)

     

Log in to post a comment.