Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6168421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:41:04+00:00 2026-05-23T22:41:04+00:00

Introduction: I am trying to use CMake to obtain cross platform compilation scripts (for

  • 0

Introduction:

I am trying to use CMake to obtain cross platform compilation scripts (for VS 9.0 on a Windows32 and Makefiles for Unix).

I am experiencing something i can’t understand about add_subdirectory().

Let me show you my code :

Context:

My architecture for a module named “module1” is something like this :

  • CMakeLists.txt
  • include/
    • file1.h
    • file2.h
    • *.h
  • src/
    • file1.cpp
    • file2.cpp
    • *.cpp
  • test/
    • CMakeLists.txt
    • src/
      • testfile1.cpp
      • testfile2.cpp

The architecture of my whole application is composed of these modules which are in themselves projects that could work independantly.

My goals:

  1. I want to compile my module as a library

  2. I want to test the library with the code in the test/ folder

Here are the CMakeLists i wrote :

This one is the CMakeLists.txt in the root directory of my module.

#ENSURE MINIMUM VERSION OF CMAKE
cmake_minimum_required(VERSION 2.8)

#CONFIGURATION OF THE PROJECT   
    #NAME OF THE PROJECT    
     project(MyProject)

    #OUTPUT OF THE PROJECT  
    set(LIBRARY_OUTPUT_PATH lib/${CMAKE_BUILD_TYPE}) 

    #ADD THE HEADERS OF THE LIBRARY BEING CREATED   
    include_directories(include)

    #ADD 3rd PARTY OPENCV LIBRARIES     
    find_package(OpenCV REQUIRED)       

    #ADD 3rd PARTY XERCES LIBRARIES
    include_directories(${XERCES_INCLUDE_DIR})
    link_directories(${XERCES_LIB_DIR})     
    set(Xerces_LIBS xerces-c_3D.lib)


#CONFIGURATION OF THE LIBRARY   
file(GLOB_RECURSE MYPROJECT_MODULE_CXX src/*)   
file(GLOB_RECURSE MYPROJECT_MODULE_HDR include/*)       

#NAME OF THE PRESENT LIBRARY    
set(MYPROJECT_MODULE_LIB_NAME myModuleLib)
add_library(${MYPROJECT_MODULE_LIB_NAME}
        SHARED
        ${MYPROJECT_MODULE_CXX}
        ${MYPROJECT_MODULE_HDR}
        )   
target_link_libraries(${MYPROJECT_MODULE_LIB_NAME}
               ${OpenCV_LIBS}
               ${Xerces_LIBS}
               )

#CONTINUE IN THE SUB FOLDERS
add_subdirectory(test)

And then, in the test/ folder, here is the CMakeLists.txt

#ENSURE MINIMUM VERSION OF CMAKE
cmake_minimum_required(VERSION 2.8)

#CONFIGURATION OF THE PROJECT
    #NAME OF THE PROJECT
    project(MyProjectTest)

    #OUTPUT OF THE PROJECT
    set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})

    #ADD OUR TESTED LIBRARY
    include_directories(../include)
    link_directories(../build/lib/${CMAKE_BUILD_TYPE})


#CONFIGURATION OF THE EXE
    file(GLOB_RECURSE MYPROJECT_MODULE_TEST_CXX src/*)

    #NAME OF THE PRESENT EXECUTABLE
    set(MYPROJECT_MODULE_TEST_BIN_NAME myModuleTest)
    add_executable(${MYPROJECT_MODULE_TEST_BIN_NAME}
               ${MYPROJECT_MODULE_TEST_CXX}
               )
    target_link_libraries(${MYPROJECT_MODULE_TEST_BIN_NAME}
                  ${MYPROJECT_MODULE_LIB_NAME}
                  )

Question

The CMake outputs a correct MyProject.sln Visual Studio 9.0 solution, which compiles successfully in my library linked with OpenCV and Xerces (and other 3rd part libraries). However the test binary did not output any MyProjectTest.sln.

I thought, (and read in the CMake documentation) that add_subdirectory(dir) was used to do CMake in the following sub directory (i mean, the name could not be clearer :p !), so shouldn’t it continue CMake in the test/ directory and create my MyProjectTest.sln solution ?

I use the GUI CMake to run the root CMakeLists.txt in a build directory that i create in the root of my module. When I explore the build directory that’s where I can find my MyProjet.sln, a test/ folder, but no MyProjectTest.sln in it !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:41:05+00:00Added an answer on May 23, 2026 at 10:41 pm

    After three days trying everything, I finally found the answer… Sir DLRdave was right actually: the problem was not from the code itself but from something “out of the code”.

    Problem found:

    I created and edited all my files with Notepad++. Actually when opening the files with windows notepad (because i was curious) a strange rectangle symbol appeared and the file did not look like the one I usually see on Notepad++
    I found out that the symbol was a “\n\r” that Notepad++ did not show me (it must be filtered) but going on windows notepad, you could see that the whole file was “impure” and appeared on a single line instead of the layout i saw on Notepad++.

    As this “encoding” bug appeared only in the subdirectory CMakeLists, it could not be read but said no error when interpreting with CMake and that’s probably why I had no returned error from running CMake.

    Solution:

    I used the native2ascii.exe tool from Java to correct the encoding error.

    The why:

    Actually what it probably means is that the syntaxic parser of CMake has probably not been designed for filtering this type of char appearing with strange encoding, that’s why it gave me 3 days of intense debugging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

every introduction and sample that I can find seems to use GLUT or some
Introduction I am trying to use P/Invoke to register a struct of callbacks with
Introduction: I'm trying to get additional fields to log with log4j, and its working
I'm trying to learn redcode, because it looks fun to make a bot. Introduction
I'm trying to find a good, simple introduction to domain driven design, but that
I am trying to create a list view which as TextView that can display
I am trying to get an introduction to serving files to the iphone. I
I'm trying to implement a B-Tree according to the chapter B-Trees in Introduction to
I'm trying to follow some of the introduction to Grails tutorials and am at
Introduction I can't seem to get the the ChartObjects.CopyPicture method to work in Excel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.