[CMake] How to correctly default initialize CMAKE_BUILD_TYPE inside CMakeLists.txt

2019-01-14 Thread Kim Walisch
Hi,

By default I would like to set CMAKE_BUILD_TYPE=Release (inside
CMakeLists.txt) if the user has not defined CMAKE_BUILD_TYPE himself (e.g.
as command-line option: cmake . -DCMAKE_BUILD_TYPE=Debug). Is there a best
practice how to do this in CMake? I have been searching the web to see how
other people achieved this and I found that many people use code like this:

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: None Debug Release
RelWithDebInfo MinSizeRel."
FORCE)
endif()

I used this code myself in one of my projects but I recently discovered
that this code causes issues when compiling with clang-cl on Windows.

Greetings,
Kim
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


[CMake] target_compile_features() uses incorrect C++ version

2018-12-05 Thread Kim Walisch
Hi,

I have realized that my C++ primesieve project (
https://github.com/kimwalisch/primesieve) is
compiled using -std=gnu++11 with GCC 7.3 and CMake 3.10 (on Ubuntu 18.10
x64) even
though the default C++ version used by GCC 7.3 is C++14 as checked below:

$ g++ -dM -E -x c++  /dev/null | grep -F __cplusplus
#define __cplusplus 201402L

Note that I have not set CXX_STANDARD manually in my CMakeLists.txt so I
was expecting
that my project would be compiled either with -std=gnu++14 or without any
C++ version flag.
I spent some time investigating where the -std=gnu++11 flag comes from and
I found that it is
related to the use of target_compile_features():

target_compile_features(primesieve PRIVATE cxx_auto_type)

This code tells the compiler that my program uses features from C++11 and
that the compiler
should enable C++11 if the default C++ version of the compiler is e.g.
C++98. I would
however expect that if the default C++ version of the compiler is > C++11
CMake would not
add -std=gnu++11 to the compiler flags.

For me this is a CMake bug.

Thanks,
Kim Walisch
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] Warning when building static & shared library (DLL) on Windows

2018-09-30 Thread Kim Walisch
Thanks!

On Sun, Sep 30, 2018 at 12:41 PM J Decker  wrote:

>
>
> On Sun, Sep 30, 2018 at 3:12 AM Kim Walisch  wrote:
>
>> Hi,
>>
>> I have recently found out about CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS which
>> allows
>> to easily build a shared library i.e. DLL on Windows. It works great and
>> it is an awesome
>> feature however I have run into a warning on Windows (using cmake, ninja,
>> MSVC) because
>> my CMakeLists.txt builds both a static and shared library.
>>
>> Here is what my CMakeLists.txt does:
>>
>> if(WIN32)
>> set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
>> endif()
>>
>> add_library(mylib SHARED ${LIB_SRC})
>>
> make this 'mylib-sh'
>
>> ...
>> add_library(mylib STATIC ${LIB_SRC})
>>
> make this 'mylib-st'
>
>> ...
>>
>> This works without any issues on all Unix-like OSes. However on Windows
>> with MSVC I found
>> out that building the shared library creates both mylib.dll and
>> mylib.lib. And building the static
>> library also creates mylib.lib which causes ninja to issue the following
>> warning:
>>
>> ninja: warning: multiple rules generate mylib.lib. builds involving this
>> target will not be correct; continuing anyway [-w dupbuild=warn]
>>
>> So my question is how to best deal with this warning:
>>
>> 1) Should I ignore it?
>>
> you need the .lib to later link to the .dll so no...
>
>>
>> 2) Should I use add_library(... MODULE ...) instead of SHARED on Windows?
>> The ninja
>> maintainer's have suggested this when another user reported the issue
>> here:
>> https://github.com/ninja-build/ninja/issues/1128#issuecomment-207058115
>>
>> One issue I see with this approach is that apparently when building a
>> shared library using
>> add_library(... MODULE ...) one should avoid
>> using target_link_libraries(binary mylib)
>> as mentioned in this stackoverflow answer:
>> https://stackoverflow.com/a/4968940/363778
>> However the author of the stackoverflow answer also mentions that on
>> Windows you
>> could probably still use target_link_libraries(binary mylib)!?
>>
>> 3) Or is there another known workaround for this issue.
>>
> Could just use unique names.
> There's little use in practice in linking against both... if you really
> want to do both and have it be either
> just use add_library and let the user of the library deside if static or
> shared should be enabled.
>
>>
>> Thanks,
>> Kim
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
>> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> https://cmake.org/mailman/listinfo/cmake
>>
>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


[CMake] Warning when building static & shared library (DLL) on Windows

2018-09-30 Thread Kim Walisch
Hi,

I have recently found out about CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS which
allows
to easily build a shared library i.e. DLL on Windows. It works great and it
is an awesome
feature however I have run into a warning on Windows (using cmake, ninja,
MSVC) because
my CMakeLists.txt builds both a static and shared library.

Here is what my CMakeLists.txt does:

if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

add_library(mylib SHARED ${LIB_SRC})
...
add_library(mylib STATIC ${LIB_SRC})
...

This works without any issues on all Unix-like OSes. However on Windows
with MSVC I found
out that building the shared library creates both mylib.dll and mylib.lib.
And building the static
library also creates mylib.lib which causes ninja to issue the following
warning:

ninja: warning: multiple rules generate mylib.lib. builds involving this
target will not be correct; continuing anyway [-w dupbuild=warn]

So my question is how to best deal with this warning:

1) Should I ignore it?

2) Should I use add_library(... MODULE ...) instead of SHARED on Windows?
The ninja
maintainer's have suggested this when another user reported the issue here:
https://github.com/ninja-build/ninja/issues/1128#issuecomment-207058115

One issue I see with this approach is that apparently when building a
shared library using
add_library(... MODULE ...) one should avoid
using target_link_libraries(binary mylib)
as mentioned in this stackoverflow answer:
https://stackoverflow.com/a/4968940/363778
However the author of the stackoverflow answer also mentions that on
Windows you
could probably still use target_link_libraries(binary mylib)!?

3) Or is there another known workaround for this issue.

Thanks,
Kim
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] Linking programs with Clang & OpenMP fails

2018-05-04 Thread Kim Walisch
Hi,

I have figured out what the problem is:

LLVM/Clang with OpenMP requires linking against libatomic only when
using 128-bit integers. The following program fails to compile using
Clang-6.0 on Ubuntu 18 x86_64 using:

$ clang++ -fopenmp=libomp test.cpp

#include 

int main() {
__int128_t sum = 0;

#pragma omp parallel for reduction(+: sum)
for (int i = 0; i < 100; i++)
sum += i;

return 0;
}

But it compiles fine when adding -latomic:
clang++ -fopenmp=libomp test.cpp -latomic

For me, this is neither a CMake bug nor an LLVM/Clang bug but it is
still very confusing as GCC does not require linking against libatomic.

Regards,
Kim

On Fri, May 4, 2018 at 7:48 PM, Kim Walisch <kim.wali...@gmail.com> wrote:

> Hi,
>
> The latest Clang-6.0 compiler finally enables OpenMP by default on
> Linux (e.g. Ubuntu-18 x86_64).
>
> But OpenMP programs using Clang-6.0/CMake-3.10 fail to compile:
>
> [100%] Linking CXX executable primecount
> libprimecount.a(P2.cpp.o): In function `.omp_outlined..7':
> P2.cpp:(.text+0x2194): undefined reference to `__atomic_load'
> P2.cpp:(.text+0x21ef): undefined reference to `__atomic_compare_exchange'
> CMakeFiles/primecount.dir/build.make:148: recipe for target 'primecount'
> failed
> make[2]: *** [primecount] Error 1
>
> The problem is that:
>
> target_link_libraries(myprogram OpenMP::OpenMP_CXX)
>
> does not add libatomic to the linker options which LLVM/Clang's OpenMP
> library depends upon. When I manually add -latomic to the linker
> options my OpenMP programs compile & link fine using Clang-6.0/CMake-3.10.
>
> Regards,
> Kim
>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


[CMake] Linking programs with Clang & OpenMP fails

2018-05-04 Thread Kim Walisch
Hi,

The latest Clang-6.0 compiler finally enables OpenMP by default on
Linux (e.g. Ubuntu-18 x86_64).

But OpenMP programs using Clang-6.0/CMake-3.10 fail to compile:

[100%] Linking CXX executable primecount
libprimecount.a(P2.cpp.o): In function `.omp_outlined..7':
P2.cpp:(.text+0x2194): undefined reference to `__atomic_load'
P2.cpp:(.text+0x21ef): undefined reference to `__atomic_compare_exchange'
CMakeFiles/primecount.dir/build.make:148: recipe for target 'primecount'
failed
make[2]: *** [primecount] Error 1

The problem is that:

target_link_libraries(myprogram OpenMP::OpenMP_CXX)

does not add libatomic to the linker options which LLVM/Clang's OpenMP
library depends upon. When I manually add -latomic to the linker
options my OpenMP programs compile & link fine using Clang-6.0/CMake-3.10.

Regards,
Kim
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


[CMake] find_package(): fails because static library is not installed

2018-02-15 Thread Kim Walisch
Hi,

I have added support for find_package(primesieve) to my primesieve library
and I have exported 2 targets in my main CMakeLists.txt:

primesieve::libprimesieve (shared library)
primesieve::libprimesieve-static

It works fine if both the static and shared primesieve libraries have
previously
been installed. As a test I have now deleted the static libprimesieve from
my
PC and now find_package(primesieve) fails:

CMake Error at /usr/local/lib/cmake/primesieve/primesieveTargets.cmake:88
(message):
  The imported target "primesieve::libprimesieve-static" references the file
 "/usr/local/lib/libprimesieve.a"
  but this file does not exist.  Possible reasons include...

The error seems reasonable but if I leave my code as is this error will be
triggered if somebody installs the libprimesieve RPM package on Fedora or
Red Hat Linux. The libprimesieve package contains only the shared
libprimesieve. Fedora requires that static libraries are put into a separate
package. Hence the static primesieve library is in libprimesieve-static.

How can I solve this issue? If the shared libprimesieve is installed but the
static libprimesieve is not installed then I would like to only export:

primesieve::libprimesieve (shared library)

But if both the static and shared libprimesieve are installed I would like
to export:

primesieve::libprimesieve (shared library)
primesieve::libprimesieve-static

Do you know any library which has already implemented this?

Thanks,
Kim
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] Config.cmake.in: Conditionally serve static or shared library

2018-02-14 Thread Kim Walisch
Thanks for your comment, I seem to have misunderstood the usage of
BUILD_SHARED_LIBS. I will remove the hack to serve either a static or
shared libprimesieve from my cmake config file.

Kim

On Feb 14, 2018 11:42 PM, "Hendrik Sattler" <p...@hendrik-sattler.de> wrote:

>
>
> Am 14. Februar 2018 21:47:24 MEZ schrieb Kim Walisch <
> kim.wali...@gmail.com>:
> >Thanks, I got it working!
> >
> >Unfortunately I could not make the generator expression work inside
> >PrimesieveConfig.cmake.in, here is the error message:
> >
> >CMake Error:
> >  Error evaluating generator expression:
> >$
> >  Expression did not evaluate to a known generator expression
> >
> >Note that in my main CMakeLists.txt the generator expression worked
> >fine. But I figured out I don't actually need the generator expression,
> >the following code inside my PrimesieveConfig.cmake.in does the trick:
> >
> >if(BUILD_SHARED_LIBS)
>
> This is IMHO using the wrong variable! This variable tells that I want to
> build MY libs as static, not that I want to link 3rdParty libs statically!
> At least this is surprising behavior.
>
> OTOH and luckily, there are still the real targets to choose from.
>
> >This trick is also used by the c-ares library:
>
> Others also doing this wrong does not make it any better.
>
> HS
>
> --
> Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail
> gesendet.
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] Config.cmake.in: Conditionally serve static or shared library

2018-02-14 Thread Kim Walisch
Thanks, I got it working!

Unfortunately I could not make the generator expression work inside
PrimesieveConfig.cmake.in, here is the error message:

CMake Error:
  Error evaluating generator expression:
$
  Expression did not evaluate to a known generator expression

Note that in my main CMakeLists.txt the generator expression worked
fine. But I figured out I don't actually need the generator expression,
the following code inside my PrimesieveConfig.cmake.in does the trick:

if(BUILD_SHARED_LIBS)
add_library(Primesieve::Primesieve INTERFACE IMPORTED)
set_target_properties(Primesieve::Primesieve PROPERTIES
INTERFACE_LINK_LIBRARIES "Primesieve::libprimesieve")
else()
add_library(Primesieve::Primesieve INTERFACE IMPORTED)
set_target_properties(Primesieve::Primesieve PROPERTIES
INTERFACE_LINK_LIBRARIES "Primesieve::libprimesieve-static")
endif()

This trick is also used by the c-ares library:
https://github.com/gjasny/c-ares/blob/fec405a420597180244e6c66912f09ae84b31123/c-ares-config.cmake.in

The trick was already discussed on the cmake mailing list before:
https://cmake.org/pipermail/cmake-developers/2017-June/030115.html

It would be really nice though if CMake would support library aliases for
import targets, then I could achieve the same using much nicer code.

Kim

On Wed, Feb 14, 2018 at 7:08 PM, Kim Walisch <kim.wali...@gmail.com> wrote:

> CMake currently does not allow alias libraries for import targets:
>
> $ cmake ..
> CMake Error at /usr/local/lib/cmake/primesieve/PrimesieveConfig.cmake:7
> (add_library):
>   add_library cannot create ALIAS target "my_libprimesieve" because target
>   "Primesieve::libprimesieve-static" is IMPORTED.
> Call Stack (most recent call first):
>   CMakeLists.txt:6 (find_package)
>
> -- Configuring incomplete, errors occurred!
>
> Kim
>
>
> On Wed, Feb 14, 2018 at 5:34 PM, ThePhD <jm3...@columbia.edu> wrote:
>
>> I think you can use what's called an "Alias Library":
>> https://cmake.org/cmake/help/latest/command/add_li
>> brary.html#alias-libraries
>>
>> if (BUILD_SHARED_LIBS)
>>  add_library(my_libprimesieve ALIAS libprimesieve)
>> else
>>  add_library(my_libprimesieve ALIAS libprimesieve-static)
>> endif(BUILD_SHARED_LIBS)
>>
>> Then, set it properly to Primesieve::Primesieve and it should work.
>>
>>
>> On Wed, Feb 14, 2018 at 10:21 AM, Kim Walisch <kim.wali...@gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> My primesieve project builds as both a static and a shared library, hence
>>> there are 2 targets in my main CMakeLists.txt:
>>>
>>> 1) libprimesieve (shared library)
>>> 2) libprimesieve-static
>>>
>>> I am now trying to add support for find_package(Primesieve). Ideally I
>>> would like that users can link against libprimesieve as follows:
>>>
>>> find_package(Primesieve REQUIRED)
>>> target_link_libraries(user_library Primesieve::Primesieve)
>>>
>>> And I want Primesieve::Primesieve to be an alias for
>>> Primesieve::libprimesieve if BUILD_SHARED_LIBS=ON (in the user's
>>> CMakeLists.txt) and and alias for Primesieve::libprimesieve-static if
>>> BUILD_SHARED_LIBS=OFF (or if it is not set).
>>>
>>> Is this possible?
>>> Do you know any library that has already implemented this?
>>>
>>> Thanks,
>>> Kim
>>>
>>> --
>>>
>>> Powered by www.kitware.com
>>>
>>> Please keep messages on-topic and check the CMake FAQ at:
>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Kitware offers various services to support the CMake community. For more
>>> information on each offering, please visit:
>>>
>>> CMake Support: http://cmake.org/cmake/help/support.html
>>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> https://cmake.org/mailman/listinfo/cmake
>>>
>>>
>>
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
>> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
&g

Re: [CMake] Config.cmake.in: Conditionally serve static or shared library

2018-02-14 Thread Kim Walisch
CMake currently does not allow alias libraries for import targets:

$ cmake ..
CMake Error at /usr/local/lib/cmake/primesieve/PrimesieveConfig.cmake:7
(add_library):
  add_library cannot create ALIAS target "my_libprimesieve" because target
  "Primesieve::libprimesieve-static" is IMPORTED.
Call Stack (most recent call first):
  CMakeLists.txt:6 (find_package)

-- Configuring incomplete, errors occurred!

Kim


On Wed, Feb 14, 2018 at 5:34 PM, ThePhD <jm3...@columbia.edu> wrote:

> I think you can use what's called an "Alias Library": https://cmake.org/
> cmake/help/latest/command/add_library.html#alias-libraries
>
> if (BUILD_SHARED_LIBS)
>  add_library(my_libprimesieve ALIAS libprimesieve)
> else
>  add_library(my_libprimesieve ALIAS libprimesieve-static)
> endif(BUILD_SHARED_LIBS)
>
> Then, set it properly to Primesieve::Primesieve and it should work.
>
>
> On Wed, Feb 14, 2018 at 10:21 AM, Kim Walisch <kim.wali...@gmail.com>
> wrote:
>
>> Hi,
>>
>> My primesieve project builds as both a static and a shared library, hence
>> there are 2 targets in my main CMakeLists.txt:
>>
>> 1) libprimesieve (shared library)
>> 2) libprimesieve-static
>>
>> I am now trying to add support for find_package(Primesieve). Ideally I
>> would like that users can link against libprimesieve as follows:
>>
>> find_package(Primesieve REQUIRED)
>> target_link_libraries(user_library Primesieve::Primesieve)
>>
>> And I want Primesieve::Primesieve to be an alias for
>> Primesieve::libprimesieve if BUILD_SHARED_LIBS=ON (in the user's
>> CMakeLists.txt) and and alias for Primesieve::libprimesieve-static if
>> BUILD_SHARED_LIBS=OFF (or if it is not set).
>>
>> Is this possible?
>> Do you know any library that has already implemented this?
>>
>> Thanks,
>> Kim
>>
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
>> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> https://cmake.org/mailman/listinfo/cmake
>>
>>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>
>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


[CMake] Config.cmake.in: Conditionally serve static or shared library

2018-02-14 Thread Kim Walisch
Hi,

My primesieve project builds as both a static and a shared library, hence
there are 2 targets in my main CMakeLists.txt:

1) libprimesieve (shared library)
2) libprimesieve-static

I am now trying to add support for find_package(Primesieve). Ideally I
would like that users can link against libprimesieve as follows:

find_package(Primesieve REQUIRED)
target_link_libraries(user_library Primesieve::Primesieve)

And I want Primesieve::Primesieve to be an alias for
Primesieve::libprimesieve if BUILD_SHARED_LIBS=ON (in the user's
CMakeLists.txt) and and alias for Primesieve::libprimesieve-static if
BUILD_SHARED_LIBS=OFF (or if it is not set).

Is this possible?
Do you know any library that has already implemented this?

Thanks,
Kim
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


[CMake] cmake treat warnings as errors

2017-03-11 Thread Kim Walisch
Hi,

Obviously the return code of cmake is 1 if any error occurs. For
integration testing I would like the return code of cmake to be 1 as
well if any warning occurs (during configuration).

Is there an option for this?
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake


Re: [cmake-developers] CMake vs libtool versioning of shared libraries

2016-12-15 Thread Kim Walisch
Thanks for your answer.

Lets suppose I do not want to stick to my previous libtool versioning
but instead version my library according to cmake best practices. How
should I set VERSION and SOVERSION given my API version is 3.5 and my
old ABI version 4:7:0. By browsing a few CMakeLists.txt on GitHub of
other projects it seems to me that most of these projects set VERSION
to the project/API version (e.g. 3.5) and the SOVERSION to the
project/API major version (e.g 3).

-Kim

On Thu, Dec 15, 2016 at 7:07 PM, Brad King <brad.k...@kitware.com> wrote:
> On 12/15/2016 11:54 AM, Kim Walisch wrote:
>> I am currently in the process of switching the build system of my
>> primecount project from Autotools to CMake and the shared library
>> versioning in CMake is not yet clear to myself. My current project
>> version (API version) is 3.5 and the libtool version (ABI version) is
>> 4:7:0. So I have set the VERSION and SOVERSION to my libtool
>> version (in CMakeLists.txt):
>>
>> set_target_properties(libprimecount PROPERTIES SOVERSION 4)
>> set_target_properties(libprimecount PROPERTIES VERSION "4.7.0")
>>
>> Is this correct? Or should I set the VERSION to my current project
>> version (API version):
>>
>> set_target_properties(libprimecount PROPERTIES SOVERSION 4)
>> set_target_properties(libprimecount PROPERTIES VERSION "3.5")
>
> The CMake properties give direct control over the way the files
> are constructed:
>
> libfoo.so -> libfoo.so.$soversion
> libfoo.so.$soversion -> libfoo.so.$version
> libfoo.so.$version (actual file)
>
> Libtool instead defines version components [1] "current", "revision",
> and "age", and somehow maps them to the version and soversion above.
> I don't recall the mapping off the top of my head, but if you want to
> reproduce what you were doing before you should do that mapping to
> select the values for the CMake SOVERSION and VERSION properties.
>
> -Brad
>
> [1] 
> https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers


[cmake-developers] CMake vs libtool versioning of shared libraries

2016-12-15 Thread Kim Walisch
Hi,

I am currently in the process of switching the build system of my
primecount project from Autotools to CMake and the shared library
versioning in CMake is not yet clear to myself. My current project
version (API version) is 3.5 and the libtool version (ABI version) is
4:7:0. So I have set the VERSION and SOVERSION to my libtool
version (in CMakeLists.txt):

set_target_properties(libprimecount PROPERTIES SOVERSION 4)
set_target_properties(libprimecount PROPERTIES VERSION "4.7.0")

Is this correct? Or should I set the VERSION to my current project
version (API version):

set_target_properties(libprimecount PROPERTIES SOVERSION 4)
set_target_properties(libprimecount PROPERTIES VERSION "3.5")

Best regards,
Kim
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers