@@ -783,54 +783,12 @@ fn generate_cmake_config(lib: &Library, config: &CBindgenConfig) -> FormattingRe
783783 f. writeln ( "set(prefix \" ${CMAKE_CURRENT_LIST_DIR}/../\" )" ) ?;
784784 f. newline ( ) ?;
785785
786- // Write each platform variation
787786 let mut is_first_if = true ;
788787
789- // Add a config value if we have two linux versions
790- let has_static_choice =
791- if config. platforms . linux . is_some ( ) && config. platforms . linux_musl . is_some ( ) {
792- f. writeln ( & format ! (
793- "set({}_STATIC_MUSL OFF CACHE BOOL \" Use statically built musl lib on Linux for {}\" )" ,
794- lib. name. to_shouty_snake_case( ) ,
795- lib. name
796- ) ) ?;
797- f. newline ( ) ?;
798- true
799- } else {
800- false
801- } ;
802-
803- for p in config. platforms . iter ( ) {
804- let platform_check = match p. platform {
805- Platform :: Win64 => "WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8" . to_string ( ) ,
806- Platform :: Linux => {
807- if !has_static_choice {
808- "UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8" . to_string ( )
809- } else {
810- format ! (
811- "UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT $CACHE{{{}_STATIC_MUSL}}" ,
812- lib. name. to_shouty_snake_case( )
813- )
814- }
815- }
816- Platform :: LinuxMusl => {
817- if !has_static_choice {
818- "UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8" . to_string ( )
819- } else {
820- format ! (
821- "UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND $CACHE{{{}_STATIC_MUSL}}" ,
822- lib. name. to_shouty_snake_case( )
823- )
824- }
825- }
826- } ;
827-
828- if is_first_if {
829- f. writeln ( & format ! ( "if({})" , platform_check) ) ?;
830- is_first_if = false ;
831- } else {
832- f. writeln ( & format ! ( "elseif({})" , platform_check) ) ?;
833- }
788+ // Windows platform
789+ if let Some ( p) = & config. platforms . win64 {
790+ f. writeln ( "if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8)" ) ?;
791+ is_first_if = false ;
834792
835793 indented ( & mut f, |f| {
836794 f. writeln ( & format ! ( "add_library({} SHARED IMPORTED GLOBAL)" , lib. name) ) ?;
@@ -852,6 +810,56 @@ fn generate_cmake_config(lib: &Library, config: &CBindgenConfig) -> FormattingRe
852810 } ) ?;
853811 }
854812
813+ const LINUX_PLATFORM_CHECK : & str = "UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8" ;
814+
815+ // Linux dynamic lib
816+ if config. platforms . linux . is_some ( ) || config. platforms . linux_musl . is_some ( ) {
817+ if is_first_if {
818+ f. writeln ( & format ! ( "if({})" , LINUX_PLATFORM_CHECK ) ) ?;
819+ //is_first_if = false;
820+ } else {
821+ f. writeln ( & format ! ( "elseif({})" , LINUX_PLATFORM_CHECK ) ) ?;
822+ }
823+
824+ if let Some ( p) = & config. platforms . linux {
825+ indented ( & mut f, |f| {
826+ f. writeln ( & format ! ( "add_library({} SHARED IMPORTED GLOBAL)" , lib. name) ) ?;
827+ f. writeln ( & format ! ( "set_target_properties({} PROPERTIES" , lib. name) ) ?;
828+ indented ( f, |f| {
829+ f. writeln ( & format ! (
830+ "IMPORTED_LOCATION \" ${{prefix}}/lib/{}/{}\" " ,
831+ p. platform. to_string( ) ,
832+ p. bin_filename( & config. ffi_name)
833+ ) ) ?;
834+ f. writeln ( "INTERFACE_INCLUDE_DIRECTORIES \" ${prefix}/include\" " )
835+ } ) ?;
836+ f. writeln ( ")" )
837+ } ) ?;
838+ }
839+
840+ if let Some ( p) = & config. platforms . linux_musl {
841+ indented ( & mut f, |f| {
842+ f. writeln ( & format ! (
843+ "add_library({}_static STATIC IMPORTED GLOBAL)" ,
844+ lib. name
845+ ) ) ?;
846+ f. writeln ( & format ! (
847+ "set_target_properties({}_static PROPERTIES" ,
848+ lib. name
849+ ) ) ?;
850+ indented ( f, |f| {
851+ f. writeln ( & format ! (
852+ "IMPORTED_LOCATION \" ${{prefix}}/lib/{}/{}\" " ,
853+ p. platform. to_string( ) ,
854+ p. bin_filename( & config. ffi_name)
855+ ) ) ?;
856+ f. writeln ( "INTERFACE_INCLUDE_DIRECTORIES \" ${prefix}/include\" " )
857+ } ) ?;
858+ f. writeln ( ")" )
859+ } ) ?;
860+ }
861+ }
862+
855863 // Write error message if platform not found
856864 f. writeln ( "else()" ) ?;
857865 indented ( & mut f, |f| {
0 commit comments